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
2976 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2977 ((source._class && source._class.registered && source._class.registered.type != enumClass) || source.kind == classType)) // Added this here for a base enum to be acceptable for a derived enum (#139)
2979 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2987 // JUST ADDED THIS...
2988 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
2993 // Just added this for Straight conversion of ColorAlpha => Color
2994 if(source.kind == classType)
2997 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3000 for(convert = _class.conversions.first; convert; convert = convert.next)
3002 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3004 Conversion after = (conversions != null) ? conversions.last : null;
3006 if(!convert.dataType)
3007 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3008 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3009 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3010 MatchTypes(convert.dataType, dest, conversions, null, null,
3011 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3012 convert.dataType.kind == classType, false, true, warnConst))
3014 if(!conversions && !convert.Get)
3016 else if(conversions != null)
3018 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3019 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3020 (dest.kind != classType || dest._class.registered != _class.base))
3024 Conversion conv { convert = convert, isGet = true };
3025 // conversions.Add(conv);
3026 conversions.Insert(after, conv);
3039 if(dest.kind == classType)
3042 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3045 for(convert = _class.conversions.first; convert; convert = convert.next)
3047 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3049 Type constType = null;
3050 bool success = false;
3051 // Conversion after = (conversions != null) ? conversions.last : null;
3053 if(!convert.dataType)
3054 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3056 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3059 constType = { kind = pointerType, refCount = 1, type = ptrType };
3060 CopyTypeInto(ptrType, convert.dataType.type);
3061 ptrType.constant = true;
3064 // Just added this equality check to prevent recursion.... Make it safer?
3065 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3066 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3068 if(!conversions && !convert.Set)
3070 else if(conversions != null)
3072 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3073 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3074 (source.kind != classType || source._class.registered != _class.base))
3078 // *** Testing this! ***
3079 Conversion conv { convert = convert };
3080 conversions.Add(conv);
3081 //conversions.Insert(after, conv);
3087 FreeType(constType);
3093 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3095 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3096 (source.kind != classType || source._class.registered.type != structClass))
3100 // TESTING THIS... IS THIS OK??
3101 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3103 if(!dest._class.registered.dataType)
3104 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3105 // Only support this for classes...
3106 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3107 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3109 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3118 if(source.kind == classType)
3121 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3124 for(convert = _class.conversions.first; convert; convert = convert.next)
3126 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3128 Conversion after = (conversions != null) ? conversions.last : null;
3130 if(!convert.dataType)
3131 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3132 if(convert.dataType != source &&
3133 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3134 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3136 if(!conversions && !convert.Get)
3138 else if(conversions != null)
3140 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3141 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3142 (dest.kind != classType || dest._class.registered != _class.base))
3146 Conversion conv { convert = convert, isGet = true };
3148 // conversions.Add(conv);
3149 conversions.Insert(after, conv);
3158 // TESTING THIS... IS THIS OK??
3159 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3161 if(!source._class.registered.dataType)
3162 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3163 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3165 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))
3167 // For bool to be accepted by byte, short, etc.
3168 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3175 if(source.kind == classType || source.kind == subClassType)
3177 else if(dest.kind == source.kind &&
3178 (dest.kind != structType && dest.kind != unionType &&
3179 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3181 // RECENTLY ADDED THESE
3182 else if(dest.kind == doubleType && source.kind == floatType)
3184 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3186 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3188 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3190 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3192 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3194 else if(source.kind == enumType &&
3195 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3197 else if(dest.kind == enumType && !isConversionExploration &&
3198 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3200 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3201 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3203 Type paramSource, paramDest;
3205 if(dest.kind == methodType)
3206 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3207 if(source.kind == methodType)
3208 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3210 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3211 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3212 if(dest.kind == methodType)
3213 dest = dest.method.dataType;
3214 if(source.kind == methodType)
3215 source = source.method.dataType;
3217 paramSource = source.params.first;
3218 if(paramSource && paramSource.kind == voidType) paramSource = null;
3219 paramDest = dest.params.first;
3220 if(paramDest && paramDest.kind == voidType) paramDest = null;
3223 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3224 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3226 // Source thisClass must be derived from destination thisClass
3227 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3228 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3230 if(paramDest && paramDest.kind == classType)
3231 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3233 Compiler_Error($"method class should not take an object\n");
3236 paramDest = paramDest.next;
3238 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3240 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3244 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3246 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3252 // THIS WAS BACKWARDS:
3253 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3254 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3257 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3259 Compiler_Error($"overriding class expected to be derived from method class\n");
3263 paramSource = paramSource.next;
3269 // Source thisClass must be derived from destination thisClass
3270 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3272 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3278 // THIS WAS BACKWARDS TOO??
3279 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3280 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3283 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3285 //Compiler_Error($"overriding class expected to be derived from method class\n");
3293 // Source return type must be derived from destination return type
3294 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3296 Compiler_Warning($"incompatible return type for function\n");
3299 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3301 CheckConstCompatibility(dest.returnType, source.returnType, true);
3305 for(; paramDest; paramDest = paramDest.next)
3309 //Compiler_Warning($"not enough parameters\n");
3310 Compiler_Error($"not enough parameters\n");
3314 Type paramDestType = paramDest;
3315 Type paramSourceType = paramSource;
3316 Type type = paramDestType;
3318 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3319 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3320 paramSource.kind != templateType)
3323 ClassTemplateParameter curParam = null;
3325 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3328 if(sClass.templateClass) sClass = sClass.templateClass;
3329 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3331 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3333 for(sClass = sClass.base; sClass; sClass = sClass.base)
3335 if(sClass.templateClass) sClass = sClass.templateClass;
3336 id += sClass.templateParams.count;
3347 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3348 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3352 // paramDest must be derived from paramSource
3353 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3354 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3358 PrintType(paramDest, type, false, true);
3359 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3361 if(paramDestType != paramDest)
3362 FreeType(paramDestType);
3365 if(paramDestType != paramDest)
3366 FreeType(paramDestType);
3369 paramSource = paramSource.next;
3373 Compiler_Error($"too many parameters\n");
3378 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3382 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3383 (source.kind == arrayType || source.kind == pointerType))
3385 // Pointers to pointer is incompatible with non normal/nohead classes
3386 if(!(dest.type && dest.type.kind == pointerType && source.type.kind == classType && source.type._class &&
3387 source.type._class.registered && (source.type._class.registered.type != normalClass && source.type._class.registered.type != noHeadClass) && !source.type.byReference))
3389 ComputeTypeSize(source.type);
3390 ComputeTypeSize(dest.type);
3391 if(source.type.size == dest.type.size && MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3399 static void FreeConvert(Conversion convert)
3401 if(convert.resultType)
3402 FreeType(convert.resultType);
3405 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3406 char * string, OldList conversions)
3410 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3412 Class _class = link.data;
3413 if(_class.type == enumClass)
3415 OldList converts { };
3417 type.kind = classType;
3420 _class.symbol = FindClass(_class.fullName);
3421 type._class = _class.symbol;
3423 if(MatchTypes(type, dest, &converts, null, null, dest.kind != classType || !dest._class || strcmp(dest._class.string, "bool"),
3424 false, false, false, false))
3427 Class enumClass = eSystem_FindClass(privateModule, "enum");
3431 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3433 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3434 for(value = e.values.first; value; value = value.next)
3436 if(!strcmp(value.name, string))
3441 FreeType(sourceExp.expType);
3443 sourceExp.isConstant = true;
3444 sourceExp.expType = MkClassType(baseClass.fullName);
3445 if(inCompiler || inPreCompiler || inDebugger)
3448 FreeExpContents(sourceExp);
3450 sourceExp.type = constantExp;
3451 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "short") || !strcmp(baseClass.dataTypeString, "char"))
3452 sprintf(constant, FORMAT64D, value.data);
3454 sprintf(constant, FORMAT64HEXLL, value.data);
3455 sourceExp.constant = CopyString(constant);
3456 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3459 while(converts.first)
3461 Conversion convert = converts.first;
3462 converts.Remove(convert);
3463 conversions.Add(convert);
3472 converts.Free(FreeConvert);
3476 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3477 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3482 public bool ModuleVisibility(Module searchIn, Module searchFor)
3484 SubModule subModule;
3486 if(searchFor == searchIn)
3489 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3491 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3493 if(ModuleVisibility(subModule.module, searchFor))
3500 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3504 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3506 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3508 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3511 for(module = mainModule.application.allModules.first; module; module = module.next)
3513 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3519 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3522 Type realDest = dest;
3523 Type backupSourceExpType = null;
3524 Expression nbExp = GetNonBracketsExp(sourceExp);
3525 Expression computedExp = nbExp;
3528 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3529 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3531 computedExp = CopyExpression(nbExp); // Keep the original expression, but compute for checking enum ranges
3532 ComputeExpression(computedExp /*sourceExp*/);
3535 source = sourceExp.expType;
3537 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3539 if(computedExp != nbExp)
3541 FreeExpression(computedExp);
3542 computedExp = nbExp;
3548 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3550 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3552 Class sourceBase, destBase;
3553 for(sourceBase = source._class.registered;
3554 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3555 sourceBase = sourceBase.base);
3556 for(destBase = dest._class.registered;
3557 destBase && destBase.base && destBase.base.type != systemClass;
3558 destBase = destBase.base);
3559 //if(source._class.registered == dest._class.registered)
3560 if(sourceBase == destBase)
3562 if(computedExp != nbExp)
3564 FreeExpression(computedExp);
3565 computedExp = nbExp;
3577 int64 value = MAXINT;
3581 if(computedExp.type == constantExp)
3584 value = strtoll(computedExp.constant, null, 0);
3586 value = strtoull(computedExp.constant, null, 0);
3588 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3591 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3593 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3595 if(computedExp != nbExp)
3597 FreeExpression(computedExp);
3598 computedExp = nbExp;
3601 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3602 !strcmp(source._class.registered.fullName, "unichar" /*"ecere::com::unichar"*/))
3605 source = Type { kind = intType, isSigned = false, refCount = 1 };
3608 if(dest.kind == classType)
3610 Class _class = dest._class ? dest._class.registered : null;
3612 if(_class && _class.type == unitClass)
3614 if(source.kind != classType)
3617 Type tempDest, tempSource;
3619 for(; _class.base.type != systemClass; _class = _class.base);
3621 tempDest = tempType;
3623 tempType.kind = classType;
3625 _class.symbol = FindClass(_class.fullName);
3627 tempType._class = _class.symbol;
3628 tempType.truth = dest.truth;
3630 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3632 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3633 backupSourceExpType = sourceExp.expType;
3634 if(dest.passAsTemplate)
3636 // Don't carry passAsTemplate
3637 sourceExp.expType = { };
3638 CopyTypeInto(sourceExp.expType, dest);
3639 sourceExp.expType.passAsTemplate = false;
3643 sourceExp.expType = dest;
3646 //sourceExp.expType = MkClassType(_class.fullName);
3654 // Why wasn't there something like this?
3655 if(_class && _class.type == bitClass && source.kind != classType)
3657 if(!dest._class.registered.dataType)
3658 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3659 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3662 FreeType(sourceExp.expType);
3663 source = sourceExp.expType = MkClassType(dest._class.string);
3666 //source.kind = classType;
3667 //source._class = dest._class;
3671 // Adding two enumerations
3673 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3675 if(!source._class.registered.dataType)
3676 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3677 if(!dest._class.registered.dataType)
3678 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3680 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3683 source = sourceExp.expType = MkClassType(dest._class.string);
3686 //source.kind = classType;
3687 //source._class = dest._class;
3691 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3693 OldList * specs = MkList();
3697 ReadString(string, sourceExp.string);
3698 decl = SpecDeclFromString(string, specs, null);
3700 FreeExpContents(sourceExp);
3701 FreeType(sourceExp.expType);
3703 sourceExp.type = classExp;
3704 sourceExp._classExp.specifiers = specs;
3705 sourceExp._classExp.decl = decl;
3706 sourceExp.expType = dest;
3711 if(backupSourceExpType) FreeType(backupSourceExpType);
3715 else if(source.kind == classType)
3717 Class _class = source._class ? source._class.registered : null;
3719 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || _class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3722 if(dest.kind != classType)
3724 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3725 if(!source._class.registered.dataType)
3726 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3729 dest = MkClassType(source._class.string);
3730 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3731 // dest = MkClassType(source._class.string);
3735 if(dest.kind != classType)
3738 Type tempDest, tempSource;
3740 if(!source._class.registered.dataType)
3741 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3743 for(; _class.base.type != systemClass; _class = _class.base);
3745 tempSource = tempType;
3746 tempType.kind = classType;
3747 tempType._class = FindClass(_class.fullName);
3748 tempType.truth = source.truth;
3749 tempType.classObjectType = source.classObjectType;
3752 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3754 // PUT THIS BACK TESTING UNITS?
3755 if(conversions && conversions.last)
3757 ((Conversion)(conversions.last)).resultType = dest;
3761 FreeType(sourceExp.expType);
3762 sourceExp.expType = MkClassType(_class.fullName);
3763 sourceExp.expType.truth = source.truth;
3764 sourceExp.expType.classObjectType = source.classObjectType;
3766 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3768 if(!sourceExp.destType)
3770 FreeType(sourceExp.destType);
3771 sourceExp.destType = sourceExp.expType;
3772 if(sourceExp.expType)
3773 sourceExp.expType.refCount++;
3776 //source = _class.dataType;
3779 // TOCHECK: TESTING THIS NEW CODE
3780 if(!_class.dataType)
3781 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3783 dest = MkClassType(source._class.string);
3784 dest.truth = source.truth;
3785 dest.classObjectType = source.classObjectType;
3788 source = _class.dataType;
3798 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3808 if(source.kind == classType)
3810 Class _class = source._class.registered;
3811 if(_class.type == unitClass)
3813 if(!_class.dataType)
3814 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3815 source = _class.dataType;
3819 if(dest.kind == classType)
3821 Class _class = dest._class ? dest._class.registered : null;
3822 bool fittingValue = false;
3823 if(_class && _class.type == enumClass)
3825 Class enumClass = eSystem_FindClass(privateModule, "enum");
3826 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3827 if(c && value >= 0 && value <= c.largest)
3828 fittingValue = true;
3831 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3832 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3834 if(_class.type == normalClass || _class.type == noHeadClass)
3836 Expression newExp { };
3837 *newExp = *sourceExp;
3838 if(sourceExp.destType) sourceExp.destType.refCount++;
3839 if(sourceExp.expType) sourceExp.expType.refCount++;
3840 sourceExp.type = castExp;
3841 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3842 sourceExp.cast.exp = newExp;
3843 FreeType(sourceExp.expType);
3844 sourceExp.expType = null;
3845 ProcessExpressionType(sourceExp);
3847 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3850 FreeType(sourceExp.expType);
3851 sourceExp.expType = dest;
3855 if(inCompiler) FreeType(dest);
3857 if(backupSourceExpType) FreeType(backupSourceExpType);
3861 if(!_class.dataType)
3862 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3864 dest = _class.dataType;
3868 // Accept lower precision types for units, since we want to keep the unit type
3869 if(dest.kind == doubleType &&
3870 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3871 source.kind == charType || source.kind == _BoolType))
3873 specs = MkListOne(MkSpecifier(DOUBLE));
3875 else if(dest.kind == floatType &&
3876 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3877 source.kind == _BoolType || source.kind == doubleType))
3879 specs = MkListOne(MkSpecifier(FLOAT));
3881 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3882 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3885 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3886 ListAdd(specs, MkSpecifier(INT64));
3888 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3889 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3892 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3893 ListAdd(specs, MkSpecifier(INT));
3895 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3896 source.kind == floatType || source.kind == doubleType))
3899 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3900 ListAdd(specs, MkSpecifier(SHORT));
3902 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3903 source.kind == floatType || source.kind == doubleType))
3906 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3907 ListAdd(specs, MkSpecifier(CHAR));
3913 if(backupSourceExpType)
3915 // Failed to convert: revert previous exp type
3916 if(sourceExp.expType) FreeType(sourceExp.expType);
3917 sourceExp.expType = backupSourceExpType;
3922 else if(dest.kind == doubleType &&
3923 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3924 source.kind == _BoolType || source.kind == charType))
3926 specs = MkListOne(MkSpecifier(DOUBLE));
3928 else if(dest.kind == floatType &&
3929 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3931 specs = MkListOne(MkSpecifier(FLOAT));
3933 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3934 (value == 1 || value == 0))
3937 ListAdd(specs, MkSpecifier(BOOL));
3939 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3940 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3942 if(source.kind == intType)
3946 if(backupSourceExpType) FreeType(backupSourceExpType);
3952 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3953 ListAdd(specs, MkSpecifier(CHAR));
3956 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3957 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3959 if(source.kind == intType)
3963 if(backupSourceExpType) FreeType(backupSourceExpType);
3969 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3970 ListAdd(specs, MkSpecifier(SHORT));
3973 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3976 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3977 ListAdd(specs, MkSpecifier(INT));
3979 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3982 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3983 ListAdd(specs, MkSpecifier(INT64));
3985 else if(dest.kind == enumType &&
3986 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3988 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3994 if(backupSourceExpType)
3996 // Failed to convert: revert previous exp type
3997 if(sourceExp.expType) FreeType(sourceExp.expType);
3998 sourceExp.expType = backupSourceExpType;
4003 if(!flag && !sourceExp.opDestType)
4005 Expression newExp { };
4006 *newExp = *sourceExp;
4009 if(sourceExp.destType) sourceExp.destType.refCount++;
4010 if(sourceExp.expType) sourceExp.expType.refCount++;
4012 sourceExp.type = castExp;
4013 if(realDest.kind == classType)
4015 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4016 FreeList(specs, FreeSpecifier);
4019 sourceExp.cast.typeName = MkTypeName(specs, null);
4020 if(newExp.type == opExp)
4022 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4025 sourceExp.cast.exp = newExp;
4027 FreeType(sourceExp.expType);
4028 sourceExp.expType = null;
4029 ProcessExpressionType(sourceExp);
4032 FreeList(specs, FreeSpecifier);
4036 if(backupSourceExpType) FreeType(backupSourceExpType);
4042 if(computedExp != nbExp)
4044 FreeExpression(computedExp);
4045 computedExp = nbExp;
4048 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4049 if(sourceExp.type == identifierExp)
4051 Identifier id = sourceExp.identifier;
4052 if(dest.kind == classType)
4054 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4056 Class _class = dest._class.registered;
4057 Class enumClass = eSystem_FindClass(privateModule, "enum");
4060 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4063 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4064 for(value = e.values.first; value; value = value.next)
4066 if(!strcmp(value.name, id.string))
4071 FreeType(sourceExp.expType);
4073 sourceExp.isConstant = true;
4074 sourceExp.expType = MkClassType(_class.fullName);
4075 if(inCompiler || inPreCompiler || inDebugger)
4077 FreeExpContents(sourceExp);
4079 sourceExp.type = constantExp;
4080 if(_class.dataTypeString && (!strcmp(_class.dataTypeString, "int") || !strcmp(_class.dataTypeString, "int64") || !strcmp(_class.dataTypeString, "short") || !strcmp(_class.dataTypeString, "char"))) // _class cannot be null here!
4081 sourceExp.constant = PrintInt64(value.data);
4083 sourceExp.constant = PrintUInt64(value.data);
4084 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4094 // Loop through all enum classes
4095 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4106 #define TERTIARY(o, name, m, t, p) \
4107 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4109 exp.type = constantExp; \
4110 exp.string = p(op1.m ? op2.m : op3.m); \
4112 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4116 #define BINARY(o, name, m, t, p) \
4117 static bool name(Expression exp, Operand op1, Operand op2) \
4120 exp.type = constantExp; \
4121 exp.string = p((t)(op1.m o value2)); \
4123 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4127 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4128 static bool name(Expression exp, Operand op1, Operand op2) \
4131 exp.type = constantExp; \
4132 exp.string = p(value2 ? ((t)(op1.m o value2)) : 0); \
4134 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4138 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4139 static bool name(Expression exp, Operand op1, Operand op2) \
4142 exp.type = constantExp; \
4143 exp.string = p((t)(op1.m o value2)); \
4145 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4149 #define UNARY(o, name, m, t, p) \
4150 static bool name(Expression exp, Operand op1) \
4152 exp.type = constantExp; \
4153 exp.string = p((t)(o op1.m)); \
4155 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4159 #define OPERATOR_ALL(macro, o, name) \
4160 macro(o, Int##name, i, int, PrintInt) \
4161 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4162 macro(o, Int64##name, i64, int64, PrintInt64) \
4163 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4164 macro(o, Short##name, s, short, PrintShort) \
4165 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4166 macro(o, Char##name, c, char, PrintChar) \
4167 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4168 macro(o, Float##name, f, float, PrintFloat) \
4169 macro(o, Double##name, d, double, PrintDouble)
4171 #define OPERATOR_INTTYPES(macro, o, name) \
4172 macro(o, Int##name, i, int, PrintInt) \
4173 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4174 macro(o, Int64##name, i64, int64, PrintInt64) \
4175 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4176 macro(o, Short##name, s, short, PrintShort) \
4177 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4178 macro(o, Char##name, c, char, PrintChar) \
4179 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4181 #define OPERATOR_REALTYPES(macro, o, name) \
4182 macro(o, Float##name, f, float, PrintFloat) \
4183 macro(o, Double##name, d, double, PrintDouble)
4185 // binary arithmetic
4186 OPERATOR_ALL(BINARY, +, Add)
4187 OPERATOR_ALL(BINARY, -, Sub)
4188 OPERATOR_ALL(BINARY, *, Mul)
4189 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4190 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4191 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4194 OPERATOR_ALL(UNARY, -, Neg)
4196 // unary arithmetic increment and decrement
4197 OPERATOR_ALL(UNARY, ++, Inc)
4198 OPERATOR_ALL(UNARY, --, Dec)
4200 // binary arithmetic assignment
4201 OPERATOR_ALL(BINARY, =, Asign)
4202 OPERATOR_ALL(BINARY, +=, AddAsign)
4203 OPERATOR_ALL(BINARY, -=, SubAsign)
4204 OPERATOR_ALL(BINARY, *=, MulAsign)
4205 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4206 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4207 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4210 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4211 OPERATOR_INTTYPES(BINARY, |, BitOr)
4212 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4213 OPERATOR_INTTYPES(BINARY, <<, LShift)
4214 OPERATOR_INTTYPES(BINARY, >>, RShift)
4217 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4219 // binary bitwise assignment
4220 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4221 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4222 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4223 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4224 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4226 // unary logical negation
4227 OPERATOR_INTTYPES(UNARY, !, Not)
4229 // binary logical equality
4230 OPERATOR_ALL(BINARY, ==, Equ)
4231 OPERATOR_ALL(BINARY, !=, Nqu)
4234 OPERATOR_ALL(BINARY, &&, And)
4235 OPERATOR_ALL(BINARY, ||, Or)
4237 // binary logical relational
4238 OPERATOR_ALL(BINARY, >, Grt)
4239 OPERATOR_ALL(BINARY, <, Sma)
4240 OPERATOR_ALL(BINARY, >=, GrtEqu)
4241 OPERATOR_ALL(BINARY, <=, SmaEqu)
4243 // tertiary condition operator
4244 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4246 //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
4247 #define OPERATOR_TABLE_ALL(name, type) \
4248 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4250 type##Inc, type##Dec, \
4251 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4252 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4254 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4256 type##Equ, type##Nqu, \
4257 type##And, type##Or, \
4258 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4261 #define OPERATOR_TABLE_INTTYPES(name, type) \
4262 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4264 type##Inc, type##Dec, \
4265 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4266 null, null, null, null, null, \
4268 null, null, null, null, null, \
4270 type##Equ, type##Nqu, \
4271 type##And, type##Or, \
4272 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4275 OPERATOR_TABLE_ALL(int, Int)
4276 OPERATOR_TABLE_ALL(uint, UInt)
4277 OPERATOR_TABLE_ALL(int64, Int64)
4278 OPERATOR_TABLE_ALL(uint64, UInt64)
4279 OPERATOR_TABLE_ALL(short, Short)
4280 OPERATOR_TABLE_ALL(ushort, UShort)
4281 OPERATOR_TABLE_INTTYPES(float, Float)
4282 OPERATOR_TABLE_INTTYPES(double, Double)
4283 OPERATOR_TABLE_ALL(char, Char)
4284 OPERATOR_TABLE_ALL(uchar, UChar)
4286 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4287 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4288 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4289 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4290 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4291 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4292 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4293 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4295 public void ReadString(char * output, char * string)
4297 int len = strlen(string);
4299 bool quoted = false, escaped = false;
4300 for(c = 0; c<len; c++)
4302 char ch = string[c];
4307 case 'n': output[d] = '\n'; break;
4308 case 't': output[d] = '\t'; break;
4309 case 'a': output[d] = '\a'; break;
4310 case 'b': output[d] = '\b'; break;
4311 case 'f': output[d] = '\f'; break;
4312 case 'r': output[d] = '\r'; break;
4313 case 'v': output[d] = '\v'; break;
4314 case '\\': output[d] = '\\'; break;
4315 case '\"': output[d] = '\"'; break;
4316 case '\'': output[d] = '\''; break;
4317 default: output[d] = ch;
4338 // String Unescape Copy
4340 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4341 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4342 public int UnescapeString(char * d, char * s, int len)
4346 while(j < len && (ch = s[j]))
4351 switch((ch = s[++j]))
4353 case 'n': d[k] = '\n'; break;
4354 case 't': d[k] = '\t'; break;
4355 case 'a': d[k] = '\a'; break;
4356 case 'b': d[k] = '\b'; break;
4357 case 'f': d[k] = '\f'; break;
4358 case 'r': d[k] = '\r'; break;
4359 case 'v': d[k] = '\v'; break;
4360 case '\\': d[k] = '\\'; break;
4361 case '\"': d[k] = '\"'; break;
4362 case '\'': d[k] = '\''; break;
4363 default: d[k] = '\\'; d[k] = ch;
4375 public char * OffsetEscapedString(char * s, int len, int offset)
4379 while(j < len && k < offset && (ch = s[j]))
4384 return (k == offset) ? s + j : null;
4387 public Operand GetOperand(Expression exp)
4390 Type type = exp.expType;
4393 while(type.kind == classType && type._class &&
4394 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4396 if(!type._class.registered.dataType)
4397 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4398 type = type._class.registered.dataType;
4401 if(exp.type == stringExp && op.kind == pointerType)
4403 op.ui64 = (uint64)(uintptr)exp.string;
4404 op.kind = pointerType;
4407 else if(exp.isConstant && exp.type == constantExp)
4409 op.kind = type.kind;
4417 if(exp.constant[0] == '\'')
4419 op.c = exp.constant[1];
4422 else if(type.isSigned)
4424 op.c = (char)strtol(exp.constant, null, 0);
4429 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4435 if(exp.constant[0] == '\'')
4437 op.s = exp.constant[1];
4440 else if(type.isSigned)
4442 op.s = (short)strtol(exp.constant, null, 0);
4447 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4453 if(exp.constant[0] == '\'')
4455 op.i = exp.constant[1];
4458 else if(type.isSigned)
4460 op.i = (int)strtol(exp.constant, null, 0);
4465 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4473 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4478 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4481 op.kind = int64Type;
4486 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4491 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4494 op.kind = int64Type;
4499 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4504 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4507 op.kind = int64Type;
4510 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4511 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4512 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4513 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4515 op.f = (float)strtod(exp.constant, null);
4519 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4520 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4521 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4522 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4524 op.d = (double)strtod(exp.constant, null);
4527 //case classType: For when we have operator overloading...
4528 // Pointer additions
4529 //case functionType:
4533 op.ui64 = _strtoui64(exp.constant, null, 0);
4534 op.kind = pointerType;
4544 static int64 GetEnumValue(Class _class, void * ptr)
4547 switch(_class.typeSize)
4550 if(!strcmp(_class.dataTypeString, "uint64"))
4551 v = (int64)*(uint64 *)ptr;
4553 v = (int64)*(int64 *)ptr;
4556 if(!strcmp(_class.dataTypeString, "uint"))
4557 v = (int64)*(uint *)ptr;
4559 v = (int64)*(int *)ptr;
4562 if(!strcmp(_class.dataTypeString, "uint16"))
4563 v = (int64)*(uint16 *)ptr;
4565 v = (int64)*(short *)ptr;
4568 if(!strcmp(_class.dataTypeString, "byte"))
4569 v = (int64)*(byte *)ptr;
4571 v = (int64)*(char *)ptr;
4577 static __attribute__((unused)) void UnusedFunction()
4580 a.OnGetString(0,0,0);
4583 extern int __ecereVMethodID_class_OnGetString;
4586 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4588 DataMember dataMember;
4589 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4591 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4592 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4596 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4598 void * ptr = inst.data + dataMember.offset + offset;
4599 char * result = null;
4600 exp.loc = member.loc = inst.loc;
4601 ((Identifier)member.identifiers->first).loc = inst.loc;
4603 if(!dataMember.dataType)
4604 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4605 type = dataMember.dataType;
4606 if(type.kind == classType)
4608 Class _class = type._class.registered;
4609 if(_class.type == enumClass)
4611 Class enumClass = eSystem_FindClass(privateModule, "enum");
4614 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4616 for(item = e.values.first; item; item = item.next)
4618 if(item.data == GetEnumValue(_class, ptr))
4626 exp.identifier = MkIdentifier(result);
4627 exp.type = identifierExp;
4628 exp.destType = MkClassType(_class.fullName);
4629 ProcessExpressionType(exp);
4633 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4635 if(!_class.dataType)
4636 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4637 type = _class.dataType;
4646 FreeExpContents(exp);
4648 exp.constant = PrintFloat(*(float*)ptr);
4649 exp.type = constantExp;
4654 FreeExpContents(exp);
4656 exp.constant = PrintDouble(*(double*)ptr);
4657 exp.type = constantExp;
4662 FreeExpContents(exp);
4664 exp.constant = PrintInt(*(int*)ptr);
4665 exp.type = constantExp;
4670 FreeExpContents(exp);
4672 exp.constant = PrintInt64(*(int64*)ptr);
4673 exp.type = constantExp;
4678 FreeExpContents(exp);
4679 // TODO: This should probably use proper type
4680 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4681 exp.type = constantExp;
4686 FreeExpContents(exp);
4687 // TODO: This should probably use proper type
4688 exp.constant = PrintInt64((int64)*(intsize*)ptr);
4689 exp.type = constantExp;
4693 Compiler_Error($"Unhandled type populating instance\n");
4696 ListAdd(memberList, member);
4699 if(parentDataMember.type == unionMember)
4704 void PopulateInstance(Instantiation inst)
4706 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4707 Class _class = classSym.registered;
4708 DataMember dataMember;
4709 OldList * memberList = MkList();
4710 // Added this check and ->Add to prevent memory leaks on bad code
4712 inst.members = MkListOne(MkMembersInitList(memberList));
4714 inst.members->Add(MkMembersInitList(memberList));
4715 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4717 if(!dataMember.isProperty)
4719 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4720 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4724 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4726 void * ptr = inst.data + dataMember.offset;
4727 char * result = null;
4729 exp.loc = member.loc = inst.loc;
4730 ((Identifier)member.identifiers->first).loc = inst.loc;
4732 if(!dataMember.dataType)
4733 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4734 type = dataMember.dataType;
4735 if(type.kind == classType)
4737 Class _class = type._class.registered;
4738 if(_class.type == enumClass)
4740 Class enumClass = eSystem_FindClass(privateModule, "enum");
4743 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4745 for(item = e.values.first; item; item = item.next)
4747 if(item.data == GetEnumValue(_class, ptr))
4756 exp.identifier = MkIdentifier(result);
4757 exp.type = identifierExp;
4758 exp.destType = MkClassType(_class.fullName);
4759 ProcessExpressionType(exp);
4762 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4764 if(!_class.dataType)
4765 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4766 type = _class.dataType;
4775 exp.constant = PrintFloat(*(float*)ptr);
4776 exp.type = constantExp;
4781 exp.constant = PrintDouble(*(double*)ptr);
4782 exp.type = constantExp;
4787 exp.constant = PrintInt(*(int*)ptr);
4788 exp.type = constantExp;
4793 exp.constant = PrintInt64(*(int64*)ptr);
4794 exp.type = constantExp;
4799 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4800 exp.type = constantExp;
4804 Compiler_Error($"Unhandled type populating instance\n");
4807 ListAdd(memberList, member);
4813 void ComputeInstantiation(Expression exp)
4815 Instantiation inst = exp.instance;
4816 MembersInit members;
4817 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4818 Class _class = classSym ? classSym.registered : null;
4819 DataMember curMember = null;
4820 Class curClass = null;
4821 DataMember subMemberStack[256];
4822 int subMemberStackPos = 0;
4825 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4827 // Don't recompute the instantiation...
4828 // Non Simple classes will have become constants by now
4832 if(_class.type == normalClass || _class.type == noHeadClass)
4834 inst.data = (byte *)eInstance_New(_class);
4835 if(_class.type == normalClass)
4836 ((Instance)inst.data)._refCount++;
4839 inst.data = new0 byte[_class.structSize];
4844 for(members = inst.members->first; members; members = members.next)
4846 switch(members.type)
4848 case dataMembersInit:
4850 if(members.dataMembers)
4853 for(member = members.dataMembers->first; member; member = member.next)
4855 Identifier ident = member.identifiers ? member.identifiers->first : null;
4858 Property prop = null;
4859 DataMember dataMember = null;
4860 uint dataMemberOffset;
4864 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4867 if(curMember.isProperty)
4868 prop = (Property)curMember;
4871 dataMember = curMember;
4873 // CHANGED THIS HERE
4874 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4876 // 2013/17/29 -- It seems that this was missing here!
4877 if(_class.type == normalClass)
4878 dataMemberOffset += _class.base.structSize;
4879 // dataMemberOffset = dataMember.offset;
4886 prop = eClass_FindProperty(_class, ident.string, privateModule);
4890 if(prop.memberAccess == publicAccess)
4892 curMember = (DataMember)prop;
4893 curClass = prop._class;
4898 DataMember _subMemberStack[256];
4899 int _subMemberStackPos = 0;
4901 // FILL MEMBER STACK
4902 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4907 if(dataMember.memberAccess == publicAccess)
4909 curMember = dataMember;
4910 curClass = dataMember._class;
4911 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4912 subMemberStackPos = _subMemberStackPos;
4918 if(found && member.initializer && member.initializer.type == expInitializer)
4920 Expression value = member.initializer.exp;
4922 bool deepMember = false;
4925 type = prop.dataType;
4929 if(!dataMember.dataType)
4930 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4932 type = dataMember.dataType;
4935 if(ident && ident.next)
4939 // for(; ident && type; ident = ident.next)
4940 for(ident = ident.next; ident && type; ident = ident.next)
4942 if(type.kind == classType)
4944 prop = eClass_FindProperty(type._class.registered,
4945 ident.string, privateModule);
4947 type = prop.dataType;
4950 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4951 ident.string, &dataMemberOffset, privateModule, null, null);
4953 type = dataMember.dataType;
4956 else if(type.kind == structType || type.kind == unionType)
4959 for(memberType = type.members.first; memberType; memberType = memberType.next)
4961 if(!strcmp(memberType.name, ident.string))
4972 FreeType(value.destType);
4973 value.destType = type;
4974 if(type) type.refCount++;
4975 ComputeExpression(value);
4977 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4979 if(type.kind == classType)
4981 Class _class = type._class.registered;
4982 if(_class && (_class.type == bitClass || _class.type == unitClass || _class.type == enumClass))
4984 if(!_class.dataType)
4985 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4986 type = _class.dataType;
4992 void * ptr = inst.data + dataMemberOffset;
4994 if(value.type == constantExp)
5000 GetInt(value, (int*)ptr);
5005 GetInt64(value, (int64*)ptr);
5010 GetIntPtr(value, (intptr*)ptr);
5015 GetIntSize(value, (intsize*)ptr);
5020 GetFloat(value, (float*)ptr);
5025 GetDouble(value, (double *)ptr);
5030 else if(value.type == instanceExp)
5032 if(type.kind == classType)
5034 Class _class = type._class.registered;
5035 if(_class.type == structClass)
5037 ComputeTypeSize(type);
5038 if(value.instance.data)
5039 memcpy(ptr, value.instance.data, type.size);
5044 else if(prop && prop.Set != (void *)(intptr)1)
5046 if(value.type == instanceExp && value.instance.data)
5048 if(type.kind == classType)
5050 Class _class = type._class.registered;
5051 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5053 void (*Set)(void *, void *) = (void *)prop.Set;
5054 Set(inst.data, value.instance.data);
5055 PopulateInstance(inst);
5059 else if(value.type == constantExp)
5065 void (*Set)(void *, double) = (void *)prop.Set;
5066 Set(inst.data, strtod(value.constant, null) );
5071 void (*Set)(void *, float) = (void *)prop.Set;
5072 Set(inst.data, (float)(strtod(value.constant, null)));
5077 void (*Set)(void *, int) = (void *)prop.Set;
5078 Set(inst.data, (int)strtol(value.constant, null, 0));
5083 void (*Set)(void *, int64) = (void *)prop.Set;
5084 Set(inst.data, _strtoi64(value.constant, null, 0));
5089 void (*Set)(void *, intptr) = (void *)prop.Set;
5090 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5095 void (*Set)(void *, intsize) = (void *)prop.Set;
5096 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5101 else if(value.type == stringExp)
5104 ReadString(temp, value.string);
5105 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5109 else if(!deepMember && type && _class.type == unitClass)
5113 // Only support converting units to units for now...
5114 if(value.type == constantExp)
5116 if(type.kind == classType)
5118 Class _class = type._class.registered;
5119 if(_class.type == unitClass)
5121 if(!_class.dataType)
5122 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5123 type = _class.dataType;
5126 // TODO: Assuming same base type for units...
5132 float (*Set)(float) = (void *)prop.Set;
5133 GetFloat(member.initializer.exp, &fValue);
5134 exp.constant = PrintFloat(Set(fValue));
5135 exp.type = constantExp;
5141 double (*Set)(double) = (void *)prop.Set;
5142 GetDouble(member.initializer.exp, &dValue);
5143 exp.constant = PrintDouble(Set(dValue));
5144 exp.type = constantExp;
5151 else if(!deepMember && type && _class.type == bitClass)
5155 if(value.type == instanceExp && value.instance.data)
5157 unsigned int (*Set)(void *) = (void *)prop.Set;
5158 bits = Set(value.instance.data);
5160 else if(value.type == constantExp)
5166 BitMember bitMember = (BitMember) dataMember;
5169 bits = (bits & ~bitMember.mask);
5170 if(!bitMember.dataType)
5171 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5172 type = bitMember.dataType;
5173 if(type.kind == classType && type._class && type._class.registered)
5175 if(!type._class.registered.dataType)
5176 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5177 type = type._class.registered.dataType;
5182 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5183 case shortType: { uint16 v; type.isSigned ? GetShort(value, (short *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5185 case longType: { uint v; type.isSigned ? GetInt(value, (int *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5186 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (int64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5187 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (intptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5188 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (intsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5190 bits |= part << bitMember.pos;
5196 if(_class && _class.type == unitClass)
5198 ComputeExpression(member.initializer.exp);
5199 exp.constant = member.initializer.exp.constant;
5200 exp.type = constantExp;
5202 member.initializer.exp.constant = null;
5212 if(_class && _class.type == bitClass)
5214 exp.constant = PrintHexUInt(bits);
5215 exp.type = constantExp;
5217 if(exp.type != instanceExp)
5223 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5225 bool result = false;
5229 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5230 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5234 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5235 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5238 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5239 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5240 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5243 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5244 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5245 result = GetOpFloat(op, &op.f);
5248 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5249 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5250 result = GetOpDouble(op, &op.d);
5253 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5254 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5255 result = GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5258 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5259 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5260 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5263 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5264 result = isSigned ? GetOpInt64 /*GetOpIntPtr*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5267 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5268 result = isSigned ? GetOpInt64 /*GetOpIntSize*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntSize*/(op, &op.ui64);
5274 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5276 if(exp.op.op == SIZEOF)
5278 FreeExpContents(exp);
5279 exp.type = constantExp;
5280 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5291 // Provide default unary +
5292 Expression exp2 = exp.op.exp2;
5294 FreeExpContents(exp);
5295 FreeType(exp.expType);
5296 FreeType(exp.destType);
5302 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5304 // unary arithmetic increment and decrement
5305 //OPERATOR_ALL(UNARY, ++, Inc)
5306 //OPERATOR_ALL(UNARY, --, Dec)
5309 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5311 // unary logical negation
5313 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5319 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5321 if(Promote(op2, op1.kind, op1.type.isSigned))
5322 op2.kind = op1.kind, op2.ops = op1.ops;
5323 else if(Promote(op1, op2.kind, op2.type.isSigned))
5324 op1.kind = op2.kind, op1.ops = op2.ops;
5328 // binary arithmetic
5330 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5333 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5336 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5339 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5342 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5344 // binary arithmetic assignment
5345 //OPERATOR_ALL(BINARY, =, Asign)
5346 //OPERATOR_ALL(BINARY, +=, AddAsign)
5347 //OPERATOR_ALL(BINARY, -=, SubAsign)
5348 //OPERATOR_ALL(BINARY, *=, MulAsign)
5349 //OPERATOR_ALL(BINARY, /=, DivAsign)
5350 //OPERATOR_ALL(BINARY, %=, ModAsign)
5355 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5359 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5362 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5365 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5368 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5370 // binary bitwise assignment
5371 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5372 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5373 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5374 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5375 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5376 // binary logical equality
5378 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5381 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5385 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5388 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5390 // binary logical relational
5392 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5395 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5398 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5401 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5408 void ComputeExpression(Expression exp)
5411 char expString[10240];
5412 expString[0] = '\0';
5413 PrintExpression(exp, expString);
5420 Identifier id = exp.identifier;
5421 if(id && exp.isConstant && !inCompiler && !inPreCompiler && !inDebugger)
5423 Class c = (exp.expType && exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
5424 if(c && c.type == enumClass)
5426 Class enumClass = eSystem_FindClass(privateModule, "enum");
5430 EnumClassData e = ACCESS_CLASSDATA(c, enumClass);
5431 for(value = e.values.first; value; value = value.next)
5433 if(!strcmp(value.name, id.string))
5438 const String dts = c.dataTypeString;
5439 FreeExpContents(exp);
5440 exp.type = constantExp;
5441 exp.constant = (dts && (!strcmp(dts, "int") || !strcmp(dts, "int64") || !strcmp(dts, "short") || !strcmp(dts, "char"))) ? PrintInt64(value.data) : PrintUInt64(value.data);
5450 ComputeInstantiation(exp);
5459 Expression exp1, exp2 = null;
5463 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5466 Expression e = exp.op.exp2;
5468 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5470 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5472 if(e.type == extensionCompoundExp)
5473 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5478 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5480 if(e.type == stringExp && e.string)
5482 char * string = e.string;
5483 int len = strlen(string);
5484 char * tmp = new char[len-2+1];
5485 len = UnescapeString(tmp, string + 1, len - 2);
5487 FreeExpContents(exp);
5488 exp.type = constantExp;
5489 exp.constant = PrintUInt(len + 1);
5493 Type type = e.expType;
5495 FreeExpContents(exp);
5496 exp.type = constantExp;
5497 exp.constant = PrintUInt(ComputeTypeSize(type));
5503 ComputeExpression(exp.op.exp2);
5507 ComputeExpression(exp.op.exp1);
5510 op1 = GetOperand(exp1);
5511 if(op1.type) op1.type.refCount++;
5514 op2 = GetOperand(exp2);
5515 if(op2.type) op2.type.refCount++;
5521 op1 = GetOperand(exp1);
5522 if(op1.type) op1.type.refCount++;
5525 CallOperator(exp, exp1, exp2, op1, op2);
5532 if(exp.op.exp1 && exp.op.exp2)
5537 FreeExpContents(exp);
5538 op1.ops.BitAnd(exp, op1, op2);
5547 FreeExpContents(exp);
5548 op1.ops.Mul(exp, op1, op2);
5557 FreeExpContents(exp);
5558 op1.ops.Add(exp, op1, op2);
5563 // Provide default unary +
5564 Expression exp2 = exp.op.exp2;
5566 FreeExpContents(exp);
5567 FreeType(exp.expType);
5568 FreeType(exp.destType);
5579 FreeExpContents(exp);
5580 op1.ops.Sub(exp, op1, op2);
5587 FreeExpContents(exp);
5588 op1.ops.Neg(exp, op1);
5595 FreeExpContents(exp);
5596 op1.ops.BitNot(exp, op1);
5602 FreeExpContents(exp);
5603 op1.ops.Not(exp, op1);
5606 // Binary only operators
5610 FreeExpContents(exp);
5611 op1.ops.Div(exp, op1, op2);
5617 FreeExpContents(exp);
5618 op1.ops.Mod(exp, op1, op2);
5630 FreeExpContents(exp);
5631 op1.ops.Sma(exp, op1, op2);
5640 FreeExpContents(exp);
5641 op1.ops.Grt(exp, op1, op2);
5650 FreeExpContents(exp);
5651 op1.ops.SmaEqu(exp, op1, op2);
5660 FreeExpContents(exp);
5661 op1.ops.GrtEqu(exp, op1, op2);
5670 FreeExpContents(exp);
5671 op1.ops.Equ(exp, op1, op2);
5680 FreeExpContents(exp);
5681 op1.ops.Nqu(exp, op1, op2);
5688 FreeExpContents(exp);
5689 op1.ops.BitOr(exp, op1, op2);
5695 FreeExpContents(exp);
5696 op1.ops.BitXor(exp, op1, op2);
5704 FreeExpContents(exp);
5705 exp.type = constantExp;
5706 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5710 if(op1.type) FreeType(op1.type);
5711 if(op2.type) FreeType(op2.type);
5715 case extensionExpressionExp:
5718 for(e = exp.list->first; e; e = n)
5723 OldList * list = exp.list;
5724 Expression prev = exp.prev;
5725 Expression next = exp.next;
5726 ComputeExpression(e);
5727 //FreeExpContents(exp);
5728 FreeType(exp.expType);
5729 FreeType(exp.destType);
5748 exp.isConstant = true;
5750 ComputeExpression(exp.index.exp);
5751 if(!exp.index.exp.isConstant)
5752 exp.isConstant = false;
5754 for(e = exp.index.index->first; e; e = e.next)
5756 ComputeExpression(e);
5759 // Check if this type is int
5762 exp.isConstant = false;
5764 exp.expType = Dereference(exp.index.exp.expType);
5770 Expression memberExp = exp.member.exp;
5771 Identifier memberID = exp.member.member;
5774 ComputeExpression(exp.member.exp);
5775 type = exp.member.exp.expType;
5778 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);
5779 Property prop = null;
5780 DataMember member = null;
5781 Class convertTo = null;
5782 if(type.kind == subClassType && exp.member.exp.type == classExp)
5783 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5790 PrintTypeNoConst(type, string, false, true);
5791 classSym = FindClass(string);
5792 _class = classSym ? classSym.registered : null;
5795 if(exp.member.member)
5797 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5799 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5801 if(!prop && !member && _class && exp.member.member)
5803 Symbol classSym = FindClass(exp.member.member.string);
5805 _class = classSym ? classSym.registered : null;
5806 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5813 Type type = prop.dataType;
5814 // TODO: Assuming same base type for units...
5815 if(_class.type == unitClass)
5817 if(type.kind == classType)
5819 Class _class = type._class.registered;
5820 if(_class.type == unitClass)
5822 if(!_class.dataType)
5823 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5824 type = _class.dataType;
5832 float (*Get)(float) = (void *)prop.Get;
5833 GetFloat(exp.member.exp, &value);
5834 exp.constant = PrintFloat(Get ? Get(value) : value);
5835 exp.type = constantExp;
5841 double (*Get)(double);
5842 GetDouble(exp.member.exp, &value);
5845 Get = (void *)prop.Set;
5847 Get = (void *)prop.Get;
5848 exp.constant = PrintDouble(Get ? Get(value) : value);
5849 exp.type = constantExp;
5858 Expression value = exp.member.exp;
5861 ProcessPropertyType(prop);
5863 type = prop.dataType;
5866 // printf("Investigate this\n");
5868 else if(_class.type == structClass)
5874 Class propertyClass = type._class.registered;
5875 if(propertyClass.type == structClass && value.type == instanceExp)
5877 void (*Set)(void *, void *) = (void *)prop.Set;
5878 exp.instance = Instantiation { };
5879 exp.instance.data = new0 byte[_class.structSize];
5880 exp.instance._class = MkSpecifierName(_class.fullName);
5881 exp.instance.loc = exp.loc;
5882 exp.type = instanceExp;
5883 Set(exp.instance.data, value.instance.data);
5884 PopulateInstance(exp.instance);
5891 void (*Set)(void *, int) = (void *)prop.Set;
5893 exp.instance = Instantiation { };
5894 exp.instance.data = new0 byte[_class.structSize];
5895 exp.instance._class = MkSpecifierName(_class.fullName);
5896 exp.instance.loc = exp.loc;
5897 exp.type = instanceExp;
5899 GetInt(value, &intValue);
5901 Set(exp.instance.data, intValue);
5902 PopulateInstance(exp.instance);
5908 void (*Set)(void *, int64) = (void *)prop.Set;
5910 exp.instance = Instantiation { };
5911 exp.instance.data = new0 byte[_class.structSize];
5912 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5913 exp.instance.loc = exp.loc;
5914 exp.type = instanceExp;
5916 GetInt64(value, &intValue);
5918 Set(exp.instance.data, intValue);
5919 PopulateInstance(exp.instance);
5926 void (*Set)(void *, intptr) = (void *)prop.Set;
5928 exp.instance = Instantiation { };
5929 exp.instance.data = new0 byte[_class.structSize];
5930 exp.instance._class = MkSpecifierName(_class.fullName);
5931 exp.instance.loc = exp.loc;
5932 exp.type = instanceExp;
5934 GetIntPtr(value, &intValue);
5936 Set(exp.instance.data, intValue);
5937 PopulateInstance(exp.instance);
5944 void (*Set)(void *, intsize) = (void *)prop.Set;
5946 exp.instance = Instantiation { };
5947 exp.instance.data = new0 byte[_class.structSize];
5948 exp.instance._class = MkSpecifierName(_class.fullName);
5949 exp.instance.loc = exp.loc;
5950 exp.type = instanceExp;
5952 GetIntSize(value, &intValue);
5954 Set(exp.instance.data, intValue);
5955 PopulateInstance(exp.instance);
5961 void (*Set)(void *, float) = (void *)prop.Set;
5963 exp.instance = Instantiation { };
5964 exp.instance.data = new0 byte[_class.structSize];
5965 exp.instance._class = MkSpecifierName(_class.fullName);
5966 exp.instance.loc = exp.loc;
5967 exp.type = instanceExp;
5969 GetFloat(value, &floatValue);
5971 Set(exp.instance.data, floatValue);
5972 PopulateInstance(exp.instance);
5978 void (*Set)(void *, double) = (void *)prop.Set;
5980 exp.instance = Instantiation { };
5981 exp.instance.data = new0 byte[_class.structSize];
5982 exp.instance._class = MkSpecifierName(_class.fullName);
5983 exp.instance.loc = exp.loc;
5984 exp.type = instanceExp;
5986 GetDouble(value, &doubleValue);
5988 Set(exp.instance.data, doubleValue);
5989 PopulateInstance(exp.instance);
5994 else if(_class.type == bitClass)
6000 Class propertyClass = type._class.registered;
6001 if(propertyClass.type == structClass && value.instance.data)
6003 unsigned int (*Set)(void *) = (void *)prop.Set;
6004 unsigned int bits = Set(value.instance.data);
6005 exp.constant = PrintHexUInt(bits);
6006 exp.type = constantExp;
6009 else if(_class.type == bitClass)
6012 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6015 GetUInt(exp.member.exp, &value);
6017 exp.constant = PrintHexUInt(bits);
6018 exp.type = constantExp;
6026 if(_class.type == bitClass)
6029 GetUInt(exp.member.exp, &value);
6035 Class _class = type._class.registered;
6036 if(_class.type == structClass)
6038 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6040 exp.instance = Instantiation { };
6041 exp.instance.data = new0 byte[_class.structSize];
6042 exp.instance._class = MkSpecifierName(_class.fullName);
6043 exp.instance.loc = exp.loc;
6044 //exp.instance.fullSet = true;
6045 exp.type = instanceExp;
6046 Get(value, exp.instance.data);
6047 PopulateInstance(exp.instance);
6049 else if(_class.type == bitClass)
6051 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6052 uint64 bits = Get(value);
6053 exp.constant = PrintHexUInt64(bits);
6054 exp.type = constantExp;
6060 else if(_class.type == structClass)
6062 byte * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6067 Class _class = type._class.registered;
6068 if(_class.type == structClass && value)
6070 void (*Get)(void *, void *) = (void *)prop.Get;
6072 exp.instance = Instantiation { };
6073 exp.instance.data = new0 byte[_class.structSize];
6074 exp.instance._class = MkSpecifierName(_class.fullName);
6075 exp.instance.loc = exp.loc;
6076 //exp.instance.fullSet = true;
6077 exp.type = instanceExp;
6078 Get(value, exp.instance.data);
6079 PopulateInstance(exp.instance);
6087 char * value = exp.member.exp.instance.data;
6092 Class _class = type._class.registered;
6093 if(_class.type == normalClass)
6095 void *(*Get)(void *) = (void *)prop.Get;
6097 exp.instance = Instantiation { };
6098 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6099 exp.type = instanceExp;
6100 exp.instance.data = Get(value, exp.instance.data);
6112 exp.isConstant = false;
6120 if(exp.type != ExpressionType::memberExp)
6122 FreeExpression(memberExp);
6123 FreeIdentifier(memberID);
6129 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6130 FreeExpContents(exp);
6131 exp.constant = PrintUInt(ComputeTypeSize(type));
6132 exp.type = constantExp;
6138 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6139 if(classSym && classSym.registered)
6141 if(classSym.registered.fixed)
6143 FreeSpecifier(exp._class);
6144 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6145 exp.type = constantExp;
6149 char className[1024];
6150 strcpy(className, "__ecereClass_");
6151 FullClassNameCat(className, classSym.string, true);
6153 DeclareClass(curExternal, classSym, className);
6155 FreeExpContents(exp);
6156 exp.type = pointerExp;
6157 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6158 exp.member.member = MkIdentifier("structSize");
6168 if(exp.type == castExp)
6171 ComputeExpression(exp.cast.exp);
6174 if(e && exp.expType)
6177 type = exp.destType;
6180 if(type.kind == classType)
6182 Class _class = type._class.registered;
6183 if(_class && (_class.type == unitClass || _class.type == bitClass))
6185 if(!_class.dataType)
6186 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6187 type = _class.dataType;
6198 if(GetChar(e, &value))
6200 FreeExpContents(exp);
6201 exp.constant = PrintChar(value);
6202 exp.type = constantExp;
6207 unsigned char value = 0;
6208 if(GetUChar(e, &value))
6210 FreeExpContents(exp);
6211 exp.constant = PrintUChar(value);
6212 exp.type = constantExp;
6220 if(GetShort(e, &value))
6222 FreeExpContents(exp);
6223 exp.constant = PrintShort(value);
6224 exp.type = constantExp;
6229 unsigned short value = 0;
6230 if(GetUShort(e, &value))
6232 FreeExpContents(exp);
6233 exp.constant = PrintUShort(value);
6234 exp.type = constantExp;
6242 if(GetInt(e, &value))
6244 FreeExpContents(exp);
6245 exp.constant = PrintInt(value);
6246 exp.type = constantExp;
6251 unsigned int value = 0;
6252 if(GetUInt(e, &value))
6254 FreeExpContents(exp);
6255 exp.constant = PrintUInt(value);
6256 exp.type = constantExp;
6264 if(GetInt64(e, &value))
6266 FreeExpContents(exp);
6267 exp.constant = PrintInt64(value);
6268 exp.type = constantExp;
6274 if(GetUInt64(e, &value))
6276 FreeExpContents(exp);
6277 exp.constant = PrintUInt64(value);
6278 exp.type = constantExp;
6286 if(GetIntPtr(e, &value))
6288 FreeExpContents(exp);
6289 exp.constant = PrintInt64((int64)value);
6290 exp.type = constantExp;
6296 if(GetUIntPtr(e, &value))
6298 FreeExpContents(exp);
6299 exp.constant = PrintUInt64((uint64)value);
6300 exp.type = constantExp;
6308 if(GetIntSize(e, &value))
6310 FreeExpContents(exp);
6311 exp.constant = PrintInt64((int64)value);
6312 exp.type = constantExp;
6318 if(GetUIntSize(e, &value))
6320 FreeExpContents(exp);
6321 exp.constant = PrintUInt64((uint64)value);
6322 exp.type = constantExp;
6329 if(GetFloat(e, &value))
6331 FreeExpContents(exp);
6332 exp.constant = PrintFloat(value);
6333 exp.type = constantExp;
6340 if(GetDouble(e, &value))
6342 FreeExpContents(exp);
6343 exp.constant = PrintDouble(value);
6344 exp.type = constantExp;
6359 // Caring only about last expression for now...
6360 ComputeExpression(exp.cond.exp->last);
6361 if(exp.cond.elseExp)
6362 ComputeExpression(exp.cond.elseExp);
6364 ComputeExpression(exp.cond.cond);
6366 op1 = GetOperand(exp.cond.cond);
6367 if(op1.type) op1.type.refCount++;
6368 op2 = GetOperand(exp.cond.exp->last);
6369 if(op2.type) op2.type.refCount++;
6370 op3 = GetOperand(exp.cond.elseExp);
6371 if(op3.type) op3.type.refCount++;
6373 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6374 if(op1.type) FreeType(op1.type);
6375 if(op2.type) FreeType(op2.type);
6376 if(op3.type) FreeType(op3.type);
6382 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6387 OldList converts { };
6390 if(destType.kind == voidType)
6393 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6397 // for(convert = converts.last; convert; convert = convert.prev)
6398 for(convert = converts.first; convert; convert = convert.next)
6400 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6403 Expression newExp { };
6404 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6406 // TODO: Check this...
6410 newExp.destType = null;
6415 exp.type = memberExp;
6416 exp.addedThis = true;
6417 exp.member.exp = newExp;
6418 FreeType(exp.member.exp.expType);
6420 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6421 exp.member.exp.expType.classObjectType = objectType;
6422 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6423 exp.member.memberType = propertyMember;
6424 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6425 // TESTING THIS... for (int)degrees
6426 exp.needCast = true;
6427 if(exp.expType) exp.expType.refCount++;
6428 ApplyAnyObjectLogic(exp.member.exp);
6433 /*if(exp.isConstant)
6435 // Color { ColorRGB = [exp] };
6436 exp.type = instanceExp;
6437 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6438 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6439 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6443 // If not constant, don't turn it yet into an instantiation
6444 // (Go through the deep members system first)
6445 exp.type = memberExp;
6446 exp.addedThis = true;
6447 exp.member.exp = newExp;
6449 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6450 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6451 newExp.expType._class.registered.type == noHeadClass)
6453 newExp.byReference = true;
6456 FreeType(exp.member.exp.expType);
6457 /*exp.member.exp.expType = convert.convert.dataType;
6458 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6459 exp.member.exp.expType = null;
6460 if(convert.convert.dataType)
6462 exp.member.exp.expType = { };
6463 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6464 exp.member.exp.expType.refCount = 1;
6465 exp.member.exp.expType.classObjectType = objectType;
6466 ApplyAnyObjectLogic(exp.member.exp);
6469 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6470 exp.member.memberType = reverseConversionMember;
6471 exp.expType = convert.resultType ? convert.resultType :
6472 MkClassType(convert.convert._class.fullName);
6473 exp.needCast = true;
6474 if(convert.resultType) convert.resultType.refCount++;
6480 FreeType(exp.expType);
6483 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6484 if(exp.destType.casted)
6485 exp.needCast = true;
6486 if(exp.expType) exp.expType.refCount++;
6490 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6491 if(exp.destType.casted)
6492 exp.needCast = true;
6493 if(convert.resultType)
6494 convert.resultType.refCount++;
6498 if(exp.isConstant && inCompiler)
6499 ComputeExpression(exp);
6501 converts.Free(FreeConvert);
6504 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6506 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6508 if(!result && exp.expType && exp.destType)
6510 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6511 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6512 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6513 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6517 // if(result) CheckTemplateTypes(exp);
6521 void CheckTemplateTypes(Expression exp)
6524 bool et = exp.expType ? exp.expType.passAsTemplate : false;
6525 bool dt = exp.destType ? exp.destType.passAsTemplate : false;
6527 Expression nbExp = GetNonBracketsExp(exp);
6528 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6529 (nbExp == exp || nbExp.type != castExp))
6531 Expression newExp { };
6533 TypeKind kind = exp.expType.kind;
6535 if(exp.destType) exp.destType.refCount++;
6536 if(exp.expType) exp.expType.refCount++;
6540 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6542 Class c = exp.expType._class.registered;
6543 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6546 c.dataType = ProcessTypeString(c.dataTypeString, false);
6547 kind = c.dataType.kind;
6554 if(exp.destType.classObjectType)
6556 // We need to pass the address, just pass it along (Undo what was done above)
6557 if(exp.destType) exp.destType.refCount--;
6558 if(exp.expType) exp.expType.refCount--;
6563 // If we're looking for value:
6564 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6566 OldList * unionDefs = MkList();
6567 OldList * statements = MkList();
6568 context = PushContext();
6569 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6570 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6571 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6572 exp.type = extensionCompoundExp;
6573 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6574 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6575 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6576 exp.compound.compound.context = context;
6577 PopContext(context);
6582 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6583 if((exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass) || exp.expType.isPointerType)
6584 exp.cast.exp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), MkExpBrackets(MkListOne(newExp)));
6586 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6587 exp.needCast = true;
6591 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6593 Expression newExp { };
6595 TypeKind kind = exp.expType.kind;
6597 if(exp.destType) exp.destType.refCount++;
6598 if(exp.expType) exp.expType.refCount++;
6602 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6604 Class c = exp.expType._class.registered;
6605 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6608 c.dataType = ProcessTypeString(c.dataTypeString, false);
6609 kind = c.dataType.kind;
6616 if(exp.destType.classObjectType)
6618 // We need to pass the address, just pass it along (Undo what was done above)
6619 if(exp.destType) exp.destType.refCount--;
6620 if(exp.expType) exp.expType.refCount--;
6625 // If we're looking for value:
6626 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6628 OldList * unionDefs = MkList();
6629 OldList * statements = MkList();
6630 context = PushContext();
6631 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6632 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6633 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6634 exp.type = extensionCompoundExp;
6635 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6636 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6637 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6638 exp.compound.compound.context = context;
6639 PopContext(context);
6644 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6646 exp.type = bracketsExp;
6648 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6649 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6650 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6651 ProcessExpressionType(exp.list->first);
6656 exp.type = bracketsExp;
6657 if(exp.expType.isPointerType)
6659 exp.needTemplateCast = 2;
6660 newExp.needCast = true;
6661 newExp.needTemplateCast = 2;
6662 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6665 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6666 exp.needTemplateCast = 2;
6667 newExp.needCast = true;
6668 newExp.needTemplateCast = 2;
6669 ProcessExpressionType(exp.list->first);
6675 if(exp.expType.kind == templateType)
6677 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6680 FreeType(exp.destType);
6681 FreeType(exp.expType);
6686 /*if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6688 // When was this required? Removed to address using templated values to pass to printf()
6692 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6693 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6697 char typeString[1024];
6699 OldList * specs = MkList();
6700 typeString[0] = '\0';
6701 PrintType(exp.expType, typeString, false, false);
6702 decl = SpecDeclFromString(typeString, specs, null);
6705 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6706 exp.cast.typeName = MkTypeName(specs, decl);
6707 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6708 exp.cast.exp.needCast = true;
6709 exp.needTemplateCast = 2;
6710 newExp.needTemplateCast = 2;
6717 // TODO: The Symbol tree should be reorganized by namespaces
6719 // - Tree of all symbols within (stored without namespace)
6720 // - Tree of sub-namespaces
6722 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6724 int nsLen = strlen(nameSpace);
6726 // Start at the name space prefix
6727 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6729 char * s = symbol.string;
6730 if(!strncmp(s, nameSpace, nsLen))
6732 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6735 for(c = strlen(s)-1; c >= 0; c--)
6740 if(!strcmp(namePart, name))
6742 // TODO: Error on ambiguity
6752 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6755 char nameSpace[1024];
6756 const char * namePart;
6757 bool gotColon = false;
6759 nameSpace[0] = '\0';
6760 for(c = strlen(name)-1; c >= 0; c--)
6767 namePart = name+c+1;
6768 while(c >= 0 && name[c] == ':') c--;
6771 // Try an exact match first
6772 Symbol symbol = (Symbol)tree.FindString(name);
6776 // Namespace specified
6777 memcpy(nameSpace, name, c + 1);
6780 return ScanWithNameSpace(tree, nameSpace, namePart);
6784 // Looking for a global symbol, e.g. ::Sleep()
6785 Symbol symbol = (Symbol)tree.FindString(namePart);
6790 // Name only (no namespace specified)
6791 Symbol symbol = (Symbol)tree.FindString(namePart);
6794 return ScanWithNameSpace(tree, "", namePart);
6799 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6802 //Time startTime = GetTime();
6804 // Optimize this later? Do this before/less?
6806 Symbol symbol = null;
6808 // First, check if the identifier is declared inside the function
6809 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6811 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6813 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6819 strcpy(curName, thisNameSpace);
6820 strcat(curName, "::");
6821 strcat(curName, name);
6822 // Try to resolve in current namespace first
6823 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6826 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6829 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6831 if(symbol || ctx == endContext) break;
6833 if(inCompiler && symbol && ctx == globalContext && symbol.pointerExternal && curExternal && symbol.pointerExternal != curExternal)
6834 curExternal.CreateUniqueEdge(symbol.pointerExternal, symbol.pointerExternal.type == functionExternal);
6836 //findSymbolTotalTime += GetTime() - startTime;
6841 static void GetTypeSpecs(Type type, OldList * specs)
6843 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6848 if(type._class.registered)
6850 if(!type._class.registered.dataType)
6851 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6852 GetTypeSpecs(type._class.registered.dataType, specs);
6856 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6857 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6858 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6859 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6860 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6861 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6862 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6863 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6866 ListAdd(specs, MkSpecifier(INT)); break;
6870 static void PrintArraySize(Type arrayType, char * string)
6875 if(arrayType.enumClass)
6876 strcat(size, arrayType.enumClass.string);
6877 else if(arrayType.arraySizeExp)
6878 PrintExpression(arrayType.arraySizeExp, size);
6880 strcat(string, size);
6883 // WARNING : This function expects a null terminated string since it recursively concatenate...
6884 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6888 if(printConst && type.constant)
6889 strcat(string, "const ");
6894 Symbol c = type._class;
6895 bool isObjectBaseClass = !c || !c.string || !strcmp(c.string, "class");
6896 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6897 // look into merging with thisclass ?
6898 if(type.classObjectType == typedObject && isObjectBaseClass)
6899 strcat(string, "typed_object");
6900 else if(type.classObjectType == anyObject && isObjectBaseClass)
6901 strcat(string, "any_object");
6905 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6907 if(type.byReference)
6908 strcat(string, " &");
6911 case voidType: strcat(string, "void"); break;
6912 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6913 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6914 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6915 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6916 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6917 case _BoolType: strcat(string, "_Bool"); break;
6918 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6919 case floatType: strcat(string, "float"); break;
6920 case doubleType: strcat(string, "double"); break;
6924 strcat(string, "struct ");
6925 strcat(string, type.enumName);
6927 else if(type.typeName)
6928 strcat(string, type.typeName);
6932 strcat(string, "struct { ");
6933 for(member = type.members.first; member; member = member.next)
6935 PrintType(member, string, true, fullName);
6936 strcat(string,"; ");
6944 strcat(string, "union ");
6945 strcat(string, type.enumName);
6947 else if(type.typeName)
6948 strcat(string, type.typeName);
6951 strcat(string, "union ");
6952 strcat(string,"(unnamed)");
6958 strcat(string, "enum ");
6959 strcat(string, type.enumName);
6961 else if(type.typeName)
6962 strcat(string, type.typeName);
6964 strcat(string, "int"); // "enum");
6967 strcat(string, "...");
6970 strcat(string, "subclass(");
6971 strcat(string, type._class ? type._class.string : "int");
6972 strcat(string, ")");
6975 strcat(string, type.templateParameter.identifier.string);
6978 strcat(string, "thisclass");
6981 strcat(string, "__builtin_va_list");
6987 static void PrintName(Type type, char * string, bool fullName)
6989 if(type.name && type.name[0])
6992 strcat(string, type.name);
6995 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6996 if(name) name += 2; else name = type.name;
6997 strcat(string, name);
7002 static void PrintAttribs(Type type, char * string)
7006 if(type.dllExport) strcat(string, "dllexport ");
7007 if(type.attrStdcall) strcat(string, "stdcall ");
7011 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7013 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7015 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7016 PrintAttribs(type, string);
7017 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7018 strcat(string, " const");
7019 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7020 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7021 strcat(string, " (");
7022 if(type.kind == pointerType)
7024 if(type.type.kind == functionType || type.type.kind == methodType)
7025 PrintAttribs(type.type, string);
7027 if(type.kind == pointerType)
7029 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7030 strcat(string, "*");
7032 strcat(string, " *");
7034 if(printConst && type.constant && type.kind == pointerType)
7035 strcat(string, " const");
7038 PrintTypeSpecs(type, string, fullName, printConst);
7041 static void PostPrintType(Type type, char * string, bool fullName)
7043 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7044 strcat(string, ")");
7045 if(type.kind == arrayType)
7046 PrintArraySize(type, string);
7047 else if(type.kind == functionType)
7050 strcat(string, "(");
7051 for(param = type.params.first; param; param = param.next)
7053 PrintType(param, string, true, fullName);
7054 if(param.next) strcat(string, ", ");
7056 strcat(string, ")");
7058 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7059 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7063 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7065 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7067 PrePrintType(type, string, fullName, null, printConst);
7069 if(type.thisClass || (printName && type.name && type.name[0]))
7070 strcat(string, " ");
7071 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7073 Symbol _class = type.thisClass;
7074 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7076 if(type.classObjectType == classPointer)
7077 strcat(string, "class");
7079 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7081 else if(_class && _class.string)
7083 String s = _class.string;
7088 char * name = RSearchString(s, "::", strlen(s), true, false);
7089 if(name) name += 2; else name = s;
7090 strcat(string, name);
7093 strcat(string, "::");
7096 if(printName && type.name)
7097 PrintName(type, string, fullName);
7098 PostPrintType(type, string, fullName);
7099 if(type.bitFieldCount)
7102 sprintf(count, ":%d", type.bitFieldCount);
7103 strcat(string, count);
7107 void PrintType(Type type, char * string, bool printName, bool fullName)
7109 _PrintType(type, string, printName, fullName, true);
7112 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7114 _PrintType(type, string, printName, fullName, false);
7117 static Type FindMember(Type type, char * string)
7120 for(memberType = type.members.first; memberType; memberType = memberType.next)
7122 if(!memberType.name)
7124 Type subType = FindMember(memberType, string);
7128 else if(!strcmp(memberType.name, string))
7134 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7137 for(memberType = type.members.first; memberType; memberType = memberType.next)
7139 if(!memberType.name)
7141 Type subType = FindMember(memberType, string);
7144 *offset += memberType.offset;
7148 else if(!strcmp(memberType.name, string))
7150 *offset += memberType.offset;
7157 public bool GetParseError() { return parseError; }
7159 Expression ParseExpressionString(char * expression)
7163 fileInput = TempFile { };
7164 fileInput.Write(expression, 1, strlen(expression));
7165 fileInput.Seek(0, start);
7168 parsedExpression = null;
7170 expression_yyparse();
7173 return parsedExpression;
7176 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7178 Identifier id = exp.identifier;
7179 Method method = null;
7180 Property prop = null;
7181 DataMember member = null;
7182 ClassProperty classProp = null;
7184 if(_class && _class.type == enumClass)
7186 NamedLink64 value = null;
7187 Class enumClass = eSystem_FindClass(privateModule, "enum");
7191 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7193 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7194 for(value = e.values.first; value; value = value.next)
7196 if(!strcmp(value.name, id.string))
7201 exp.isConstant = true;
7202 if(inCompiler || inPreCompiler || inDebugger)
7205 FreeExpContents(exp);
7207 exp.type = constantExp;
7208 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "char") || !strcmp(baseClass.dataTypeString, "short"))
7209 sprintf(constant, FORMAT64D, value.data);
7211 sprintf(constant, FORMAT64HEX, value.data);
7212 exp.constant = CopyString(constant);
7214 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7215 exp.expType = MkClassType(baseClass.fullName);
7223 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7225 ProcessMethodType(method);
7232 // TOCHECK: Put it back to what it was...
7233 // methodClass = _class;
7234 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7239 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7242 ProcessPropertyType(prop);
7243 exp.expType = prop.dataType;
7244 if(prop.dataType) prop.dataType.refCount++;
7247 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7249 if(!member.dataType)
7250 member.dataType = ProcessTypeString(member.dataTypeString, false);
7251 exp.expType = member.dataType;
7252 if(member.dataType) member.dataType.refCount++;
7255 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7257 if(!classProp.dataType)
7258 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7260 if(classProp.constant)
7262 FreeExpContents(exp);
7264 exp.isConstant = true;
7265 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7267 //char constant[256];
7268 exp.type = stringExp;
7269 exp.constant = QMkString((char *)(uintptr)classProp.Get(_class));
7274 exp.type = constantExp;
7275 sprintf(constant, "%d", (int)classProp.Get(_class));
7276 exp.constant = CopyString(constant);
7284 exp.expType = classProp.dataType;
7285 if(classProp.dataType) classProp.dataType.refCount++;
7291 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7293 BinaryTree * tree = &nameSpace.functions;
7294 GlobalData data = (GlobalData)tree->FindString(name);
7298 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7300 data = ScanGlobalData(child, name);
7308 static GlobalData FindGlobalData(char * name)
7311 NameSpace * nameSpace;
7312 nameSpace = globalData;
7313 for(c = 0; name[c]; c++)
7315 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7317 NameSpace * newSpace;
7318 char * spaceName = new char[c - start + 1];
7319 strncpy(spaceName, name + start, c - start);
7320 spaceName[c-start] = '\0';
7321 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7325 nameSpace = newSpace;
7326 if(name[c] == ':') c++;
7332 return ScanGlobalData(nameSpace, name + start);
7337 static int definedExpStackPos;
7338 static void * definedExpStack[512];
7340 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7341 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7343 Expression prev = checkedExp.prev, next = checkedExp.next;
7345 FreeExpContents(checkedExp);
7346 FreeType(checkedExp.expType);
7347 FreeType(checkedExp.destType);
7349 *checkedExp = *newExp;
7353 checkedExp.prev = prev;
7354 checkedExp.next = next;
7357 void ApplyAnyObjectLogic(Expression e)
7359 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7361 char debugExpString[4096];
7362 debugExpString[0] = '\0';
7363 PrintExpression(e, debugExpString);
7366 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7368 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7369 //ellipsisDestType = destType;
7372 Type type = e.expType;
7373 Class _class = null;
7374 //Type destType = e.destType;
7376 if(type.kind == classType && type._class && type._class.registered)
7378 _class = type._class.registered;
7380 else if(type.kind == subClassType)
7382 _class = FindClass("ecere::com::Class").registered;
7386 char string[1024] = "";
7389 PrintTypeNoConst(type, string, false, true);
7390 classSym = FindClass(string);
7391 if(classSym) _class = classSym.registered;
7394 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...
7395 (!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))) ||
7396 destType.byReference)))
7398 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7400 Expression checkedExp = e, newExp;
7402 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7404 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7406 if(checkedExp.type == extensionCompoundExp)
7408 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7411 checkedExp = checkedExp.list->last;
7413 else if(checkedExp.type == castExp)
7414 checkedExp = checkedExp.cast.exp;
7417 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7419 newExp = checkedExp.op.exp2;
7420 checkedExp.op.exp2 = null;
7421 FreeExpContents(checkedExp);
7423 if(e.expType && e.expType.passAsTemplate)
7426 ComputeTypeSize(e.expType);
7427 sprintf(size, "%d", e.expType.size); // Potential 32/64 Bootstrap issue
7428 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7429 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7430 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7433 ReplaceExpContents(checkedExp, newExp);
7434 e.byReference = true;
7436 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7438 Expression checkedExp; //, newExp;
7441 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7443 e.type == identifierExp ||
7444 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7445 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7446 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7449 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7451 Context context = PushContext();
7453 OldList * specs = MkList();
7454 char typeString[1024];
7455 Expression newExp { };
7457 typeString[0] = '\0';
7460 //if(e.destType) e.destType.refCount++;
7461 // if(exp.expType) exp.expType.refCount++;
7464 newExp.expType = null;
7466 PrintTypeNoConst(e.expType, typeString, false, true);
7467 decl = SpecDeclFromString(typeString, specs, null);
7468 newExp.destType = ProcessType(specs, decl);
7470 curContext = context;
7472 // We need a current compound for this
7476 OldList * stmts = MkList();
7477 e.type = extensionCompoundExp;
7478 sprintf(name, "__internalValue%03X", internalValueCounter++);
7479 if(!curCompound.compound.declarations)
7480 curCompound.compound.declarations = MkList();
7481 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7482 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7483 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7484 e.compound = MkCompoundStmt(null, stmts);
7487 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7490 e.compound = MkCompoundStmt(
7491 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7492 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7494 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7498 Type type = e.destType;
7500 CopyTypeInto(e.destType, type);
7501 e.destType.refCount = 1;
7502 e.destType.classObjectType = none;
7506 e.compound.compound.context = context;
7507 PopContext(context);
7508 curContext = context.parent;
7512 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7514 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7516 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7518 if(checkedExp.type == extensionCompoundExp)
7520 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7523 checkedExp = checkedExp.list->last;
7525 else if(checkedExp.type == castExp)
7526 checkedExp = checkedExp.cast.exp;
7529 Expression operand { };
7530 operand = *checkedExp;
7532 checkedExp.destType = ProcessTypeString("void *", false);
7533 checkedExp.expType = checkedExp.destType;
7534 checkedExp.destType.refCount++;
7536 checkedExp.type = opExp;
7537 checkedExp.op.op = '&';
7538 checkedExp.op.exp1 = null;
7539 checkedExp.op.exp2 = operand;
7541 //newExp = MkExpOp(null, '&', checkedExp);
7543 //ReplaceExpContents(checkedExp, newExp);
7550 // If expression type is a simple class, make it an address
7551 // FixReference(e, true);
7554 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7555 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7556 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7558 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"))
7560 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7564 Expression thisExp { };
7567 thisExp.prev = null;
7568 thisExp.next = null;
7571 e.type = bracketsExp;
7572 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7573 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7574 ((Expression)e.list->first).byReference = true;
7576 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7578 e.expType = thisExp.expType;
7579 e.expType.refCount++;
7584 CopyTypeInto(e.expType, thisExp.expType);
7585 e.expType.byReference = false;
7586 e.expType.refCount = 1;
7588 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7589 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7591 e.expType.classObjectType = none;
7596 // TOFIX: Try this for a nice IDE crash!
7598 // The other way around
7601 if(destType && e.expType &&
7602 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7603 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7604 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7606 if(destType.kind == ellipsisType)
7608 Compiler_Error($"Unspecified type\n");
7610 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7612 bool byReference = e.expType.byReference;
7613 Expression thisExp { };
7615 OldList * specs = MkList();
7616 char typeString[1024]; // Watch buffer overruns
7618 ClassObjectType backupClassObjectType;
7619 bool backupByReference;
7621 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7626 backupClassObjectType = type.classObjectType;
7627 backupByReference = type.byReference;
7629 type.classObjectType = none;
7630 type.byReference = false;
7632 typeString[0] = '\0';
7633 PrintType(type, typeString, false, true);
7634 decl = SpecDeclFromString(typeString, specs, null);
7636 type.classObjectType = backupClassObjectType;
7637 type.byReference = backupByReference;
7640 thisExp.prev = null;
7641 thisExp.next = null;
7644 if( ( type.kind == classType && type._class && type._class.registered &&
7645 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7646 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7647 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7648 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7650 bool passAsTemplate = thisExp.destType.passAsTemplate;
7653 destType.refCount++;
7658 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7661 CopyTypeInto(t, thisExp.destType);
7662 t.passAsTemplate = false;
7663 FreeType(thisExp.destType);
7664 thisExp.destType = t;
7667 CopyTypeInto(t, destType);
7668 t.passAsTemplate = passAsTemplate;
7671 destType.refCount = 0;
7674 CopyTypeInto(e.expType, type);
7675 if(type.passAsTemplate)
7677 e.expType.classObjectType = none;
7678 e.expType.passAsTemplate = false;
7680 e.expType.byReference = false;
7681 e.expType.refCount = 1;
7686 e.cast.typeName = MkTypeName(specs, decl);
7687 e.cast.exp = thisExp;
7688 e.byReference = true;
7694 FreeType(e.destType);
7696 e.destType = destType;
7697 destType.refCount++;
7702 void ApplyLocation(Expression exp, Location loc)
7708 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7709 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7715 for(e = exp.list->first; e; e = e.next)
7716 ApplyLocation(e, loc);
7723 for(e = exp.index.index->first; e; e = e.next)
7724 ApplyLocation(e, loc);
7727 ApplyLocation(exp.index.exp, loc);
7730 if(exp.call.arguments)
7733 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7734 ApplyLocation(arg, loc);
7737 ApplyLocation(exp.call.exp, loc);
7742 ApplyLocation(exp.member.exp, loc);
7746 ApplyLocation(exp.cast.exp, loc);
7752 for(e = exp.cond.exp->first; e; e = e.next)
7753 ApplyLocation(e, loc);
7756 ApplyLocation(exp.cond.cond, loc);
7757 if(exp.cond.elseExp)
7758 ApplyLocation(exp.cond.elseExp, loc);
7762 ApplyLocation(exp.vaArg.exp, loc);
7769 void ProcessExpressionType(Expression exp)
7771 bool unresolved = false;
7772 Location oldyylloc = yylloc;
7773 bool notByReference = false;
7775 char debugExpString[4096];
7776 debugExpString[0] = '\0';
7777 PrintExpression(exp, debugExpString);
7779 if(!exp || exp.expType)
7782 //eSystem_Logf("%s\n", expString);
7784 // Testing this here
7790 Identifier id = exp.identifier;
7791 if(!id || !topContext) return;
7793 // DOING THIS LATER NOW...
7794 if(id._class && id._class.name)
7796 id.classSym = id._class.symbol; // FindClass(id._class.name);
7797 /* TODO: Name Space Fix ups
7799 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7803 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7805 exp.expType = ProcessTypeString("Module", true);
7809 if(!strcmp(id.string, "__runtimePlatform"))
7811 exp.expType = ProcessTypeString("ecere::com::Platform", true);
7814 else if(strstr(id.string, "__ecereClass") == id.string)
7816 exp.expType = ProcessTypeString("ecere::com::Class", true);
7819 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7821 // Added this here as well
7822 ReplaceClassMembers(exp, thisClass);
7823 if(exp.type != identifierExp)
7825 ProcessExpressionType(exp);
7829 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7834 Symbol symbol = null;
7835 bool findInGlobal = false;
7836 if(!topContext.parent && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == enumClass)
7837 findInGlobal = true; // In global context, look at enum values first
7839 symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7841 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7842 if(!symbol/* && exp.destType*/)
7844 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7850 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7851 if(exp.type != identifierExp)
7853 ProcessExpressionType(exp);
7857 // Static methods called from inside the _class
7858 else if(currentClass && !id._class)
7860 if(ResolveIdWithClass(exp, currentClass, true))
7863 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7867 symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7869 // If we manage to resolve this symbol
7872 Type type = symbol.type;
7873 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7875 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7877 Context context = SetupTemplatesContext(_class);
7878 type = ReplaceThisClassType(_class);
7879 FinishTemplatesContext(context);
7880 if(type) type.refCount = 0; // We'll be incrementing it right below...
7883 FreeSpecifier(id._class);
7886 id.string = CopyString(symbol.string);
7893 // Commented this out, it was making non-constant enum parameters seen as constant
7894 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7895 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7896 // Add missing cases here... enum Classes...
7897 exp.isConstant = true;
7899 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7900 if(symbol.isParam || !strcmp(id.string, "this"))
7902 if(_class && _class.type == structClass && !type.declaredWithStruct)
7903 exp.byReference = true;
7905 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7906 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7907 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7908 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7910 Identifier id = exp.identifier;
7911 exp.type = bracketsExp;
7912 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7916 if(symbol.isIterator)
7918 if(symbol.isIterator == 3)
7920 exp.type = bracketsExp;
7921 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7922 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7924 ProcessExpressionType(exp);
7926 else if(symbol.isIterator != 4)
7928 exp.type = memberExp;
7929 exp.member.exp = MkExpIdentifier(exp.identifier);
7930 exp.member.exp.expType = exp.expType;
7931 /*if(symbol.isIterator == 6)
7932 exp.member.member = MkIdentifier("key");
7934 exp.member.member = MkIdentifier("data");
7936 ProcessExpressionType(exp);
7943 DefinedExpression definedExp = null;
7944 if(thisNameSpace && !(id._class && !id._class.name))
7947 strcpy(name, thisNameSpace);
7949 strcat(name, id.string);
7950 definedExp = eSystem_FindDefine(privateModule, name);
7953 definedExp = eSystem_FindDefine(privateModule, id.string);
7957 for(c = 0; c<definedExpStackPos; c++)
7958 if(definedExpStack[c] == definedExp)
7960 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7962 Location backupYylloc = yylloc;
7963 File backInput = fileInput;
7964 definedExpStack[definedExpStackPos++] = definedExp;
7966 fileInput = TempFile { };
7967 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7968 fileInput.Seek(0, start);
7971 parsedExpression = null;
7973 expression_yyparse();
7976 fileInput = backInput;
7978 yylloc = backupYylloc;
7980 if(parsedExpression)
7983 exp.type = bracketsExp;
7984 exp.list = MkListOne(parsedExpression);
7985 ApplyLocation(parsedExpression, yylloc);
7986 ProcessExpressionType(exp);
7987 definedExpStackPos--;
7990 definedExpStackPos--;
7996 Compiler_Error($"Recursion in defined expression %s\n", id.string);
8002 GlobalData data = null;
8003 if(thisNameSpace && !(id._class && !id._class.name))
8006 strcpy(name, thisNameSpace);
8008 strcat(name, id.string);
8009 data = FindGlobalData(name);
8012 data = FindGlobalData(id.string);
8015 DeclareGlobalData(curExternal, data);
8016 exp.expType = data.dataType;
8017 if(data.dataType) data.dataType.refCount++;
8020 id.string = CopyString(data.fullName);
8021 FreeSpecifier(id._class);
8028 GlobalFunction function = null;
8029 if(thisNameSpace && !(id._class && !id._class.name))
8032 strcpy(name, thisNameSpace);
8034 strcat(name, id.string);
8035 function = eSystem_FindFunction(privateModule, name);
8038 function = eSystem_FindFunction(privateModule, id.string);
8043 id.string = CopyString(function.name);
8046 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8047 strcpy(name, "__ecereFunction_");
8048 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8049 if(DeclareFunction(curExternal, function, name))
8052 id.string = CopyString(name);
8054 exp.expType = function.dataType;
8055 if(function.dataType) function.dataType.refCount++;
8057 FreeSpecifier(id._class);
8074 if(!exp.instance._class)
8076 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8078 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8082 //classSym = FindClass(exp.instance._class.fullName);
8083 //_class = classSym ? classSym.registered : null;
8085 ProcessInstantiationType(exp.instance);
8087 exp.isConstant = exp.instance.isConstant;
8090 if(_class.type == unitClass && _class.base.type != systemClass)
8093 Type destType = exp.destType;
8095 exp.destType = MkClassType(_class.base.fullName);
8096 exp.expType = MkClassType(_class.fullName);
8097 CheckExpressionType(exp, exp.destType, true);
8099 exp.destType = destType;
8101 exp.expType = MkClassType(_class.fullName);
8104 if(exp.instance._class)
8106 exp.expType = MkClassType(exp.instance._class.name);
8107 /*if(exp.expType._class && exp.expType._class.registered &&
8108 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8109 exp.expType.byReference = true;*/
8117 char * constant = exp.constant;
8125 if(constant[0] == '\'')
8127 if((int)((byte *)constant)[1] > 127)
8130 unichar ch = UTF8GetChar(constant + 1, &nb);
8131 if(nb < 2) ch = constant[1];
8133 exp.constant = PrintUInt(ch);
8134 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8135 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8136 type._class = FindClass("unichar");
8138 type.isSigned = false;
8142 type.kind = charType;
8143 type.isSigned = true;
8148 char * dot = strchr(constant, '.');
8149 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8153 exponent = strchr(constant, 'p');
8154 if(!exponent) exponent = strchr(constant, 'P');
8158 exponent = strchr(constant, 'e');
8159 if(!exponent) exponent = strchr(constant, 'E');
8164 if(strchr(constant, 'f') || strchr(constant, 'F'))
8165 type.kind = floatType;
8167 type.kind = doubleType;
8168 type.isSigned = true;
8172 bool isSigned = constant[0] == '-';
8174 int64 i64 = strtoll(constant, &endP, 0);
8175 uint64 ui64 = strtoull(constant, &endP, 0);
8176 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll") || !strcmp(endP, "LLU") || !strcmp(endP, "llu") || !strcmp(endP, "ull") || !strcmp(endP, "ULL"));
8177 bool forceUnsigned = endP && (!strcmp(endP, "U") || !strcmp(endP, "u") || !strcmp(endP, "LLU") || !strcmp(endP, "llu") || !strcmp(endP, "ull") || !strcmp(endP, "ULL"));
8190 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8194 else if(constant[0] != '0' || !constant[1])
8199 type.kind = is64Bit ? int64Type : intType;
8200 type.isSigned = isSigned;
8203 exp.isConstant = true;
8204 if(exp.destType && exp.destType.kind == doubleType)
8205 type.kind = doubleType;
8206 else if(exp.destType && exp.destType.kind == floatType)
8207 type.kind = floatType;
8208 else if(exp.destType && exp.destType.kind == int64Type)
8209 type.kind = int64Type;
8215 exp.isConstant = true; // Why wasn't this constant?
8223 kind = exp.wideString ? shortType : charType;
8225 isSigned = exp.wideString ? false : true;
8232 ProcessExpressionType(exp._new.size);
8237 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8239 DeclareType(curExternal, exp.expType.type, true, false);
8243 ProcessExpressionType(exp._renew.size);
8244 ProcessExpressionType(exp._renew.exp);
8249 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8251 DeclareType(curExternal, exp.expType.type, true, false);
8255 bool assign = false, boolResult = false, boolOps = false;
8256 Type type1 = null, type2 = null;
8257 bool useDestType = false, useSideType = false;
8258 Location oldyylloc = yylloc;
8259 bool useSideUnit = false;
8260 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8262 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8271 // Assignment Operators
8285 // boolean Operators
8287 // Expect boolean operators
8289 //boolResult = true;
8293 // Expect boolean operands
8304 // Gives boolean result
8317 // useSideType = true;
8318 // useDestType = true;
8336 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8342 /*// Implement speed etc.
8348 if(exp.op.op == '&')
8350 // Added this here earlier for Iterator address as key
8351 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8353 Identifier id = exp.op.exp2.identifier;
8354 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8355 if(symbol && symbol.isIterator == 2)
8357 exp.type = memberExp;
8358 exp.member.exp = exp.op.exp2;
8359 exp.member.member = MkIdentifier("key");
8361 exp.op.exp2.expType = symbol.type;
8362 symbol.type.refCount++;
8363 ProcessExpressionType(exp);
8367 // exp.op.exp2.usage.usageRef = true;
8371 //dummy.kind = TypeDummy;
8374 // Added this check here to use the dest type only for units derived from the base unit
8375 // So that untyped units will use the side unit as opposed to the untyped destination unit
8376 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8377 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8378 useDestType = false;
8380 if(destClass && useDestType &&
8381 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8383 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8385 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8386 exp.op.exp1.destType = exp.destType;
8387 exp.op.exp1.opDestType = true;
8389 exp.destType.refCount++;
8393 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8394 exp.op.exp1.destType = dummy;
8398 // TESTING THIS HERE...
8399 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8400 ProcessExpressionType(exp.op.exp1);
8401 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8403 exp.op.exp1.opDestType = false;
8405 // Fix for unit and ++ / --
8406 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8407 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8409 exp.op.exp2 = MkExpConstant("1");
8410 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8414 if(exp.op.exp1.destType == dummy)
8417 exp.op.exp1.destType = null;
8422 if(!assign && exp.op.exp1.expType && (exp.op.exp1.expType.kind == charType || exp.op.exp1.expType.kind == shortType))
8424 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 };
8425 FreeType(exp.op.exp1.expType);
8426 exp.op.exp1.expType = type;
8430 type1 = exp.op.exp1.expType;
8435 char expString[10240];
8436 expString[0] = '\0';
8437 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8441 exp.op.exp2.destType = exp.op.exp1.expType;
8442 if(exp.op.exp1.expType)
8443 exp.op.exp1.expType.refCount++;
8447 exp.op.exp2.destType = exp.destType;
8448 if(!exp.op.exp1 || (exp.op.op != '&' && exp.op.op != '^'))
8449 exp.op.exp2.opDestType = true;
8451 exp.destType.refCount++;
8454 if(type1) type1.refCount++;
8455 exp.expType = type1;
8460 PrintExpression(exp.op.exp2, expString);
8462 if(type1 && type1.kind == pointerType)
8464 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 ||
8465 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8466 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8467 else if(exp.op.op == '=')
8469 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8470 exp.op.exp2.destType = type1;
8477 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8478 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/* ||
8479 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8482 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8483 exp.op.exp2.destType = type1;
8488 if(type1) type1.refCount++;
8489 exp.expType = type1;
8491 else if(destClass &&
8492 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8493 (destClass.type == enumClass && useDestType)))
8495 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8496 exp.op.exp2.destType = exp.destType;
8497 if(exp.op.op != '&' && exp.op.op != '^')
8498 exp.op.exp2.opDestType = true;
8500 exp.destType.refCount++;
8504 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8505 exp.op.exp2.destType = dummy;
8509 // TESTING THIS HERE... (DANGEROUS)
8510 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8511 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8513 FreeType(exp.op.exp2.destType);
8514 exp.op.exp2.destType = type1;
8517 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8518 // Cannot lose the cast on a sizeof
8519 if(exp.op.op == SIZEOF)
8521 Expression e = exp.op.exp2;
8522 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8524 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8526 if(e.type == extensionCompoundExp)
8527 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8532 if(e.type == castExp && e.cast.exp)
8533 e.cast.exp.needCast = true;
8535 ProcessExpressionType(exp.op.exp2);
8536 exp.op.exp2.opDestType = false;
8537 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8539 if(!assign && (exp.op.exp1 || exp.op.op == '~'))
8541 if(exp.op.exp2.expType && (exp.op.exp2.expType.kind == charType || exp.op.exp2.expType.kind == shortType))
8543 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 };
8544 FreeType(exp.op.exp2.expType);
8545 exp.op.exp2.expType = type;
8549 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8551 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)
8553 if(exp.op.op != '=' && type1.type.kind == voidType)
8554 Compiler_Error($"void *: unknown size\n");
8556 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||
8557 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8558 (exp.op.exp2.expType._class.registered.type == normalClass ||
8559 exp.op.exp2.expType._class.registered.type == structClass ||
8560 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8562 if(exp.op.op == ADD_ASSIGN)
8563 Compiler_Error($"cannot add two pointers\n");
8565 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8566 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8568 if(exp.op.op == ADD_ASSIGN)
8569 Compiler_Error($"cannot add two pointers\n");
8573 char type1String[1024];
8574 char type2String[1024];
8575 type1String[0] = '\0';
8576 type2String[0] = '\0';
8578 PrintType(exp.op.exp2.expType, type1String, false, true);
8579 PrintType(type1, type2String, false, true);
8580 ChangeCh(expString, '\n', ' ');
8581 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8585 if(exp.op.exp2.destType == dummy)
8588 exp.op.exp2.destType = null;
8591 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8595 CopyTypeInto(type2, exp.op.exp2.expType);
8596 type2.isSigned = true;
8598 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8600 type2 = { kind = intType };
8602 type2.isSigned = true;
8606 type2 = exp.op.exp2.expType;
8607 if(type2) type2.refCount++;
8611 dummy.kind = voidType;
8613 if(exp.op.op == SIZEOF)
8620 exp.isConstant = true;
8622 // Get type of dereferenced pointer
8623 else if(exp.op.op == '*' && !exp.op.exp1)
8625 exp.expType = Dereference(type2);
8626 if(type2 && type2.kind == classType)
8627 notByReference = true;
8629 else if(exp.op.op == '&' && !exp.op.exp1)
8630 exp.expType = Reference(type2);
8631 else if(exp.op.op == LEFT_OP || exp.op.op == RIGHT_OP)
8633 if(exp.op.exp1.expType)
8635 exp.expType = exp.op.exp1.expType;
8636 exp.expType.refCount++;
8645 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8646 exp.op.exp1.destType = MkClassType("bool");
8647 exp.op.exp1.destType.truth = true;
8648 if(!exp.op.exp1.expType)
8649 ProcessExpressionType(exp.op.exp1);
8651 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8652 FreeType(exp.op.exp1.expType);
8653 exp.op.exp1.expType = MkClassType("bool");
8654 exp.op.exp1.expType.truth = true;
8658 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8659 exp.op.exp2.destType = MkClassType("bool");
8660 exp.op.exp2.destType.truth = true;
8661 if(!exp.op.exp2.expType)
8662 ProcessExpressionType(exp.op.exp2);
8664 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8665 FreeType(exp.op.exp2.expType);
8666 exp.op.exp2.expType = MkClassType("bool");
8667 exp.op.exp2.expType.truth = true;
8670 else if(exp.op.exp1 && exp.op.exp2 &&
8673 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8674 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8675 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8676 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8678 if(type1 && type2 &&
8679 // If either both are class or both are not class
8680 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8682 // Added this check for enum subtraction to result in an int type:
8683 if(exp.op.op == '-' &&
8684 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8685 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8688 if(!type1._class.registered.dataType)
8689 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8690 if(!type2._class.registered.dataType)
8691 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8693 intType = ProcessTypeString(
8694 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8696 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8697 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8698 exp.op.exp1.destType = intType;
8699 exp.op.exp2.destType = intType;
8704 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8705 exp.op.exp2.destType = type1;
8707 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8708 exp.op.exp1.destType = type2;
8712 // Warning here for adding Radians + Degrees with no destination type
8713 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8714 type1._class.registered && type1._class.registered.type == unitClass &&
8715 type2._class.registered && type2._class.registered.type == unitClass &&
8716 type1._class.registered != type2._class.registered)
8717 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8718 type1._class.string, type2._class.string, type1._class.string);
8720 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8722 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8725 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8727 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8728 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8731 ProcessExpressionType(exp.op.exp1);
8733 if(type2.kind != pointerType)
8735 ProcessExpressionType(classExp);
8737 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8739 if(!exp.op.exp2.expType)
8743 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8747 ProcessExpressionType(exp.op.exp2);
8752 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)))
8754 if(type1.kind != classType && type1.type.kind == voidType)
8755 Compiler_Error($"void *: unknown size\n");
8756 exp.expType = type1;
8757 if(type1) type1.refCount++;
8759 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)))
8761 if(type2.kind != classType && type2.type.kind == voidType)
8762 Compiler_Error($"void *: unknown size\n");
8763 exp.expType = type2;
8764 if(type2) type2.refCount++;
8766 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8767 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8769 Compiler_Warning($"different levels of indirection\n");
8773 bool success = false;
8774 if(type1.kind == pointerType && type2.kind == pointerType)
8776 if(exp.op.op == '+')
8777 Compiler_Error($"cannot add two pointers\n");
8778 else if(exp.op.op == '-')
8780 // Pointer Subtraction gives integer
8781 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8790 if(type1.type.kind == templateType)
8792 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8795 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8797 ProcessExpressionType(classExp);
8799 exp.type = bracketsExp;
8800 exp.list = MkListOne(MkExpOp(
8801 MkExpBrackets(MkListOne(MkExpOp(
8802 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8804 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8805 MkExpMember(classExp, MkIdentifier("typeSize"))));
8807 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8816 if(!success && exp.op.exp1.type == constantExp)
8818 // If first expression is constant, try to match that first
8819 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8821 if(exp.expType) FreeType(exp.expType);
8822 exp.expType = exp.op.exp1.destType;
8823 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8826 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8828 if(exp.expType) FreeType(exp.expType);
8829 exp.expType = exp.op.exp2.destType;
8830 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8836 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8838 if(exp.expType) FreeType(exp.expType);
8839 exp.expType = exp.op.exp2.destType;
8840 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8843 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8845 if(exp.expType) FreeType(exp.expType);
8846 exp.expType = exp.op.exp1.destType;
8847 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8853 char expString1[10240];
8854 char expString2[10240];
8857 expString1[0] = '\0';
8858 expString2[0] = '\0';
8863 PrintExpression(exp.op.exp1, expString1);
8864 ChangeCh(expString1, '\n', ' ');
8865 PrintExpression(exp.op.exp2, expString2);
8866 ChangeCh(expString2, '\n', ' ');
8867 PrintType(exp.op.exp1.expType, type1, false, true);
8868 PrintType(exp.op.exp2.expType, type2, false, true);
8871 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8875 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8876 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8878 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8879 // Convert e.g. / 4 into / 4.0
8880 exp.op.exp1.destType = type2._class.registered.dataType;
8881 if(type2._class.registered.dataType)
8882 type2._class.registered.dataType.refCount++;
8883 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8884 exp.expType = type2;
8885 if(type2) type2.refCount++;
8887 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8889 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8890 // Convert e.g. / 4 into / 4.0
8891 exp.op.exp2.destType = type1._class.registered.dataType;
8892 if(type1._class.registered.dataType)
8893 type1._class.registered.dataType.refCount++;
8894 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8895 exp.expType = type1;
8896 if(type1) type1.refCount++;
8902 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8904 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8906 if(!type1._class.registered.dataType)
8907 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8908 exp.op.exp2.destType = type1._class.registered.dataType;
8909 exp.op.exp2.destType.refCount++;
8911 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8914 type2 = exp.op.exp2.destType;
8915 if(type2) type2.refCount++;
8917 exp.expType = type2;
8921 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8923 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8925 if(!type2._class.registered.dataType)
8926 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8927 exp.op.exp1.destType = type2._class.registered.dataType;
8928 exp.op.exp1.destType.refCount++;
8930 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8931 type1 = exp.op.exp1.destType;
8932 exp.expType = type1;
8936 // TESTING THIS NEW CODE
8937 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8939 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8940 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8941 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8943 // Convert the enum to an int instead for these operators
8944 if(op1IsEnum && exp.op.exp2.expType)
8946 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8948 if(exp.expType) FreeType(exp.expType);
8949 exp.expType = exp.op.exp2.expType;
8950 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8954 else if(op2IsEnum && exp.op.exp1.expType)
8956 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8958 if(exp.expType) FreeType(exp.expType);
8959 exp.expType = exp.op.exp1.expType;
8960 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8967 if(op1IsEnum && exp.op.exp2.expType)
8969 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8971 if(exp.expType) FreeType(exp.expType);
8972 exp.expType = exp.op.exp1.expType;
8973 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8977 else if(op2IsEnum && exp.op.exp1.expType)
8979 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8981 if(exp.expType) FreeType(exp.expType);
8982 exp.expType = exp.op.exp2.expType;
8983 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8992 // 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
8993 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8994 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8996 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8997 exp.op.exp1.destType = type2;
9000 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9002 if(exp.expType) FreeType(exp.expType);
9003 exp.expType = exp.op.exp1.destType;
9004 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9009 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9010 exp.op.exp2.destType = type1;
9014 // Maybe this was meant to be an enum...
9015 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9017 Type oldType = exp.op.exp2.expType;
9018 exp.op.exp2.expType = null;
9019 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
9022 exp.op.exp2.expType = oldType;
9027 // TESTING THIS HERE... LATEST ADDITION
9028 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9030 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9031 exp.op.exp2.destType = type2._class.registered.dataType;
9032 if(type2._class.registered.dataType)
9033 type2._class.registered.dataType.refCount++;
9034 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
9036 //exp.expType = type2._class.registered.dataType; //type2;
9037 //if(type2) type2.refCount++;
9040 // TESTING THIS HERE... LATEST ADDITION
9041 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9043 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9044 exp.op.exp1.destType = type1._class.registered.dataType;
9045 if(type1._class.registered.dataType)
9046 type1._class.registered.dataType.refCount++;
9047 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
9048 exp.expType = type1._class.registered.dataType; //type1;
9049 if(type1) type1.refCount++;
9053 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
9055 if(exp.expType) FreeType(exp.expType);
9056 exp.expType = exp.op.exp2.destType;
9057 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
9059 else if(type1 && type2)
9061 char expString1[10240];
9062 char expString2[10240];
9063 char type1String[1024];
9064 char type2String[1024];
9065 expString1[0] = '\0';
9066 expString2[0] = '\0';
9067 type1String[0] = '\0';
9068 type2String[0] = '\0';
9071 PrintExpression(exp.op.exp1, expString1);
9072 ChangeCh(expString1, '\n', ' ');
9073 PrintExpression(exp.op.exp2, expString2);
9074 ChangeCh(expString2, '\n', ' ');
9075 PrintType(exp.op.exp1.expType, type1String, false, true);
9076 PrintType(exp.op.exp2.expType, type2String, false, true);
9079 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9081 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9083 exp.expType = exp.op.exp1.expType;
9084 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9086 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9088 exp.expType = exp.op.exp2.expType;
9089 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9097 // Maybe this was meant to be an enum...
9098 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9100 Type oldType = exp.op.exp1.expType;
9101 exp.op.exp1.expType = null;
9102 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9105 exp.op.exp1.expType = oldType;
9108 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9109 exp.op.exp1.destType = type2;
9112 // TESTING THIS HERE... LATEST ADDITION
9113 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9115 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9116 exp.op.exp1.destType = type1._class.registered.dataType;
9117 if(type1._class.registered.dataType)
9118 type1._class.registered.dataType.refCount++;
9121 // TESTING THIS HERE... LATEST ADDITION
9122 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9124 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9125 exp.op.exp2.destType = type2._class.registered.dataType;
9126 if(type2._class.registered.dataType)
9127 type2._class.registered.dataType.refCount++;
9131 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9133 if(exp.expType) FreeType(exp.expType);
9134 exp.expType = exp.op.exp1.destType;
9135 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9139 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9141 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9143 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9144 // Convert e.g. / 4 into / 4.0
9145 exp.op.exp1.destType = type2._class.registered.dataType;
9146 if(type2._class.registered.dataType)
9147 type2._class.registered.dataType.refCount++;
9148 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9150 if(exp.op.op == '!')
9152 exp.expType = MkClassType("bool");
9153 exp.expType.truth = true;
9157 exp.expType = type2;
9158 if(type2) type2.refCount++;
9161 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9163 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9165 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9166 // Convert e.g. / 4 into / 4.0
9167 exp.op.exp2.destType = type1._class.registered.dataType;
9168 if(type1._class.registered.dataType)
9169 type1._class.registered.dataType.refCount++;
9170 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9172 exp.expType = type1;
9173 if(type1) type1.refCount++;
9178 if(exp.op.exp1 && !exp.op.exp1.expType)
9180 char expString[10000];
9181 expString[0] = '\0';
9184 PrintExpression(exp.op.exp1, expString);
9185 ChangeCh(expString, '\n', ' ');
9188 Compiler_Error($"couldn't determine type of %s\n", expString);
9190 if(exp.op.exp2 && !exp.op.exp2.expType)
9192 char expString[10240];
9193 expString[0] = '\0';
9196 PrintExpression(exp.op.exp2, expString);
9197 ChangeCh(expString, '\n', ' ');
9200 Compiler_Error($"couldn't determine type of %s\n", expString);
9205 FreeType(exp.expType);
9206 exp.expType = MkClassType("bool");
9207 exp.expType.truth = true;
9210 if(exp.op.op != SIZEOF)
9211 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9212 (!exp.op.exp2 || exp.op.exp2.isConstant);
9214 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9216 DeclareType(curExternal, exp.op.exp2.expType, true, false);
9219 if(exp.op.op == DELETE && exp.op.exp2 && exp.op.exp2.expType && exp.op.exp2.expType.specConst)
9220 Compiler_Warning($"deleting const qualified object\n");
9230 case extensionExpressionExp:
9233 exp.isConstant = true;
9234 for(e = exp.list->first; e; e = e.next)
9236 //bool inced = false;
9239 FreeType(e.destType);
9240 e.opDestType = exp.opDestType;
9241 e.destType = exp.destType;
9242 if(e.destType) { exp.destType.refCount++; /*e.destType.count++; inced = true;*/ }
9244 ProcessExpressionType(e);
9246 exp.destType.count--;*/
9247 if(!exp.expType && !e.next)
9249 exp.expType = e.expType;
9250 if(e.expType) e.expType.refCount++;
9253 exp.isConstant = false;
9256 // In case a cast became a member...
9257 e = exp.list->first;
9258 if(!e.next && e.type == memberExp)
9260 // Preserve prev, next
9261 Expression next = exp.next, prev = exp.prev;
9264 FreeType(exp.expType);
9265 FreeType(exp.destType);
9275 ProcessExpressionType(exp);
9282 exp.isConstant = true;
9284 ProcessExpressionType(exp.index.exp);
9285 if(!exp.index.exp.isConstant)
9286 exp.isConstant = false;
9288 if(exp.index.exp.expType)
9290 Type source = exp.index.exp.expType;
9291 if(source.kind == classType && source._class && source._class.registered)
9293 Class _class = source._class.registered;
9294 Class c = _class.templateClass ? _class.templateClass : _class;
9295 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9297 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9299 if(exp.index.index && exp.index.index->last)
9301 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9303 if(type.kind == classType) type.constant = true;
9304 else if(type.kind == pointerType)
9307 while(t.kind == pointerType) t = t.type;
9311 ((Expression)exp.index.index->last).destType = type;
9317 for(e = exp.index.index->first; e; e = e.next)
9319 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9321 if(e.destType) FreeType(e.destType);
9322 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9324 ProcessExpressionType(e);
9327 // Check if this type is int
9330 exp.isConstant = false;
9334 exp.expType = Dereference(exp.index.exp.expType);
9336 DeclareType(curExternal, exp.expType, true, false);
9343 Type methodType = null;
9349 PrintExpression(exp.call.exp, name);
9350 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9352 //exp.call.exp.expType = null;
9353 PrintExpression(exp.call.exp, name);
9356 if(exp.call.exp.type == identifierExp)
9358 Expression idExp = exp.call.exp;
9359 Identifier id = idExp.identifier;
9360 if(!strcmp(id.string, "__builtin_frame_address"))
9362 exp.expType = ProcessTypeString("void *", true);
9363 if(exp.call.arguments && exp.call.arguments->first)
9364 ProcessExpressionType(exp.call.arguments->first);
9367 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9369 exp.expType = ProcessTypeString("int", true);
9370 if(exp.call.arguments && exp.call.arguments->first)
9371 ProcessExpressionType(exp.call.arguments->first);
9374 else if(!strcmp(id.string, "Max") ||
9375 !strcmp(id.string, "Min") ||
9376 !strcmp(id.string, "Sgn") ||
9377 !strcmp(id.string, "Abs"))
9379 Expression a = null;
9380 Expression b = null;
9381 Expression tempExp1 = null, tempExp2 = null;
9382 if((!strcmp(id.string, "Max") ||
9383 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9385 a = exp.call.arguments->first;
9386 b = exp.call.arguments->last;
9390 else if(exp.call.arguments->count == 1)
9392 a = exp.call.arguments->first;
9398 exp.call.arguments->Clear();
9399 idExp.identifier = null;
9401 FreeExpContents(exp);
9403 ProcessExpressionType(a);
9405 ProcessExpressionType(b);
9407 exp.type = bracketsExp;
9408 exp.list = MkList();
9410 if(a.expType && (!b || b.expType))
9412 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9414 // Use the simpleStruct name/ids for now...
9417 OldList * specs = MkList();
9418 OldList * decls = MkList();
9420 char temp1[1024], temp2[1024];
9422 GetTypeSpecs(a.expType, specs);
9424 if(a && !a.isConstant && a.type != identifierExp)
9426 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9427 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9428 tempExp1 = QMkExpId(temp1);
9429 tempExp1.expType = a.expType;
9431 a.expType.refCount++;
9432 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9434 if(b && !b.isConstant && b.type != identifierExp)
9436 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9437 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9438 tempExp2 = QMkExpId(temp2);
9439 tempExp2.expType = b.expType;
9441 b.expType.refCount++;
9442 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9445 decl = MkDeclaration(specs, decls);
9446 if(!curCompound.compound.declarations)
9447 curCompound.compound.declarations = MkList();
9448 curCompound.compound.declarations->Insert(null, decl);
9453 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9455 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9457 MkExpCondition(MkExpBrackets(MkListOne(
9458 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9459 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9460 exp.expType = a.expType;
9462 a.expType.refCount++;
9464 else if(!strcmp(id.string, "Abs"))
9467 MkExpCondition(MkExpBrackets(MkListOne(
9468 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9469 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9470 exp.expType = a.expType;
9472 a.expType.refCount++;
9474 else if(!strcmp(id.string, "Sgn"))
9476 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9478 MkExpCondition(MkExpBrackets(MkListOne(
9479 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9480 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9481 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9482 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9483 exp.expType = ProcessTypeString("int", false);
9486 FreeExpression(tempExp1);
9487 if(tempExp2) FreeExpression(tempExp2);
9501 if(!exp.call.exp.destType)
9503 exp.call.exp.destType = dummy;
9506 ProcessExpressionType(exp.call.exp);
9507 if(exp.call.exp.destType == dummy)
9510 exp.call.exp.destType = null;
9515 // Check argument types against parameter types
9516 functionType = exp.call.exp.expType;
9518 if(functionType && functionType.kind == TypeKind::methodType)
9520 methodType = functionType;
9521 functionType = methodType.method.dataType;
9523 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9524 // TOCHECK: Instead of doing this here could this be done per param?
9525 if(exp.call.exp.expType.usedClass)
9527 char typeString[1024];
9528 typeString[0] = '\0';
9530 Symbol back = functionType.thisClass;
9531 // Do not output class specifier here (thisclass was added to this)
9532 functionType.thisClass = null;
9533 PrintType(functionType, typeString, true, true);
9534 functionType.thisClass = back;
9536 if(strstr(typeString, "thisclass"))
9538 OldList * specs = MkList();
9541 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9543 decl = SpecDeclFromString(typeString, specs, null);
9545 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9546 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9547 exp.call.exp.expType.usedClass))
9548 thisClassParams = false;
9550 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9552 Class backupThisClass = thisClass;
9553 thisClass = exp.call.exp.expType.usedClass;
9554 ProcessDeclarator(decl, true);
9555 thisClass = backupThisClass;
9558 thisClassParams = true;
9560 functionType = ProcessType(specs, decl);
9561 functionType.refCount = 0;
9562 FinishTemplatesContext(context);
9564 // Mark parameters that were 'thisclass'
9567 for(p = functionType.params.first, op = methodType.method.dataType.params.first; p && op; p = p.next, op = op.next)
9569 //p.wasThisClass = op.kind == thisClassType;
9570 if(op.kind == thisClassType)
9571 p.thisClassFrom = methodType.method._class;
9574 if(methodType.method.dataType.returnType.kind == thisClassType)
9576 // functionType.returnType.wasThisClass = true;
9577 functionType.returnType.thisClassFrom = methodType.method._class;
9581 FreeList(specs, FreeSpecifier);
9582 FreeDeclarator(decl);
9586 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9588 Type type = functionType.type;
9589 if(!functionType.refCount)
9591 functionType.type = null;
9592 FreeType(functionType);
9594 //methodType = functionType;
9595 functionType = type;
9597 if(functionType && functionType.kind != TypeKind::functionType)
9599 Compiler_Error($"called object %s is not a function\n", name);
9601 else if(functionType)
9603 bool emptyParams = false, noParams = false;
9604 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9605 Type type = functionType.params.first;
9606 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9608 Location oldyylloc = yylloc;
9610 if(!type) emptyParams = true;
9613 if(functionType.extraParam && e && functionType.thisClass)
9615 e.destType = MkClassType(functionType.thisClass.string);
9619 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9620 // Fixed #141 by adding '&& !functionType.extraParam'
9621 if(!functionType.staticMethod && !functionType.extraParam)
9623 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9624 memberExp.member.exp.expType._class)
9626 type = MkClassType(memberExp.member.exp.expType._class.string);
9631 type = functionType.params.first;
9636 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9638 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9639 type.byReference = functionType.byReference;
9640 type.typedByReference = functionType.typedByReference;
9643 // Allow manually passing a class for typed object
9644 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9648 type = functionType.params.first;
9656 if(type && type.kind == voidType)
9659 if(!type.refCount) FreeType(type);
9663 for( ; e; e = e.next)
9665 if(!type && !emptyParams)
9668 if(methodType && methodType.methodClass)
9669 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9670 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9671 noParams ? 0 : functionType.params.count);
9673 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9674 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9675 noParams ? 0 : functionType.params.count);
9679 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9681 Type templatedType = null;
9682 Class _class = methodType.usedClass;
9683 ClassTemplateParameter curParam = null;
9685 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9688 for(sClass = _class; sClass; sClass = sClass.base)
9690 if(sClass.templateClass) sClass = sClass.templateClass;
9692 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9694 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9697 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9699 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9700 id += nextClass.templateParams.count;
9709 if(curParam && _class.templateArgs[id].dataTypeString)
9711 bool constant = type.constant;
9712 ClassTemplateArgument arg = _class.templateArgs[id];
9714 Context context = SetupTemplatesContext(_class);
9717 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9718 templatedType = ProcessTypeString(arg.dataTypeString, false);
9719 FinishTemplatesContext(context);
9722 if(templatedType.kind == classType && constant) templatedType.constant = true;
9723 else if(templatedType.kind == pointerType)
9725 Type t = templatedType.type;
9726 while(t.kind == pointerType) t = t.type;
9727 if(constant) t.constant = constant;
9730 e.destType = templatedType;
9733 templatedType.passAsTemplate = true;
9734 // templatedType.refCount++;
9740 if(type) type.refCount++;
9745 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9747 e.destType = type.prev;
9748 e.destType.refCount++;
9753 if(type) type.refCount++;
9756 // Don't reach the end for the ellipsis
9757 if(type && type.kind != ellipsisType)
9759 Type next = type.next;
9760 if(!type.refCount) FreeType(type);
9765 if(type && type.kind != ellipsisType)
9767 if(methodType && methodType.methodClass)
9768 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9769 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9770 functionType.params.count + extra);
9772 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9773 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9774 functionType.params.count + extra);
9777 if(type && !type.refCount) FreeType(type);
9784 kind = TypeKind::functionType;
9787 if(exp.call.exp.type == identifierExp)
9789 char * string = exp.call.exp.identifier.string;
9793 Location oldyylloc = yylloc;
9795 yylloc = exp.call.exp.identifier.loc;
9796 if(strstr(string, "__builtin_") == string)
9800 functionType.returnType = exp.destType;
9801 exp.destType.refCount++;
9805 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9806 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9807 globalContext.symbols.Add((BTNode)symbol);
9808 if(strstr(symbol.string, "::"))
9809 globalContext.hasNameSpace = true;
9814 else if(exp.call.exp.type == memberExp)
9816 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9817 exp.call.exp.member.member.string);*/
9820 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9822 if(!functionType.returnType)
9824 functionType.returnType = Type
9831 if(functionType && functionType.kind == TypeKind::functionType)
9833 exp.expType = functionType.returnType;
9835 if(functionType.returnType)
9836 functionType.returnType.refCount++;
9838 if(!functionType.refCount)
9839 FreeType(functionType);
9842 if(exp.call.arguments)
9844 for(e = exp.call.arguments->first; e; e = e.next)
9845 ProcessExpressionType(e);
9852 Location oldyylloc = yylloc;
9854 Expression checkExp = exp.member.exp;
9857 if(checkExp.type == castExp)
9858 checkExp = checkExp.cast.exp;
9859 else if(checkExp.type == bracketsExp)
9860 checkExp = checkExp.list ? checkExp.list->first : null;
9865 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9866 exp.thisPtr = thisPtr;
9868 // DOING THIS LATER NOW...
9869 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9871 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9872 /* TODO: Name Space Fix ups
9873 if(!exp.member.member.classSym)
9874 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9878 ProcessExpressionType(exp.member.exp);
9879 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9880 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9882 exp.isConstant = false;
9885 exp.isConstant = exp.member.exp.isConstant;
9886 type = exp.member.exp.expType;
9890 if(type && (type.kind == templateType))
9892 Class _class = thisClass ? thisClass : currentClass;
9893 ClassTemplateParameter param = null;
9896 for(param = _class.templateParams.first; param; param = param.next)
9898 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9902 if(param && param.defaultArg.member)
9904 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9907 Expression expMember = exp.member.exp;
9909 OldList * specs = MkList();
9910 char thisClassTypeString[1024];
9912 FreeIdentifier(exp.member.member);
9914 ProcessExpressionType(argExp);
9917 char * colon = strstr(param.defaultArg.memberString, "::");
9920 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9921 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9924 strcpy(thisClassTypeString, _class.fullName);
9927 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9929 exp.expType = ProcessType(specs, decl);
9930 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9932 Class expClass = exp.expType._class.registered;
9933 Class cClass = null;
9937 char templateString[1024];
9938 ClassTemplateParameter param;
9939 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9940 for(cClass = expClass; cClass; cClass = cClass.base)
9943 for(param = cClass.templateParams.first; param; param = param.next)
9947 ClassTemplateArgument arg;
9948 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9949 arg = expClass.templateArgs[id];
9951 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9953 ClassTemplateParameter cParam;
9954 //int p = numParams - sClass.templateParams.count;
9957 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9959 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9961 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9963 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9965 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9966 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9978 strcat(argument, arg.name.string);
9979 strcat(argument, " = ");
9985 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9986 char expString[1024];
9987 OldList * specs = MkList();
9988 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9990 char * string = PrintHexUInt64(arg.expression.ui64);
9991 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9994 ProcessExpressionType(exp);
9995 ComputeExpression(exp);
9996 expString[0] = '\0';
9997 PrintExpression(exp, expString);
9998 strcat(argument, expString);
10000 FreeExpression(exp);
10005 strcat(argument, arg.member.name);
10008 case TemplateParameterType::type:
10010 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10012 if(!strcmp(arg.dataTypeString, "thisclass"))
10013 strcat(argument, thisClassTypeString);
10015 strcat(argument, arg.dataTypeString);
10022 if(paramCount) strcat(templateString, ", ");
10023 if(lastParam != p - 1)
10025 strcat(templateString, param.name);
10026 strcat(templateString, " = ");
10028 strcat(templateString, argument);
10037 int len = strlen(templateString);
10038 if(templateString[len-1] == '>') templateString[len++] = ' ';
10039 templateString[len++] = '>';
10040 templateString[len++] = '\0';
10043 Context context = SetupTemplatesContext(_class);
10044 FreeType(exp.expType);
10045 exp.expType = ProcessTypeString(templateString, false);
10046 FinishTemplatesContext(context);
10050 if(!expMember.expType.isPointerType)
10051 expMember = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), expMember);
10052 // *([expType] *)(((byte *)(uintptr)[exp.member.exp]) + [argExp].member.offset)
10053 exp.type = bracketsExp;
10054 exp.list = MkListOne(MkExpOp(null, '*',
10057 exp.op.exp1 = null;
10059 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
10060 MkExpBrackets(MkListOne(
10061 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
10064 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
10066 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
10071 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
10072 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
10074 type = ProcessTemplateParameterType(type.templateParameter);
10077 // TODO: *** This seems to be where we should add method support for all basic types ***
10078 if(type && (type.kind == templateType));
10079 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
10080 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
10081 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
10082 (type.kind == pointerType && type.type.kind == charType)))
10084 Identifier id = exp.member.member;
10085 TypeKind typeKind = type.kind;
10086 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10087 if(typeKind == subClassType && exp.member.exp.type == classExp)
10089 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10090 typeKind = classType;
10095 if(typeKind == intType || typeKind == enumType)
10096 _class = eSystem_FindClass(privateModule, "int");
10099 if(type.kind == classType && type._class && type._class.registered)
10101 _class = type._class.registered;
10103 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10105 _class = FindClass("char *").registered;
10107 else if(type.kind == pointerType)
10109 _class = eSystem_FindClass(privateModule, "uintptr");
10110 FreeType(exp.expType);
10111 exp.expType = ProcessTypeString("uintptr", false);
10112 exp.byReference = true;
10116 char string[1024] = "";
10118 PrintTypeNoConst(type, string, false, true);
10119 classSym = FindClass(string);
10120 if(classSym) _class = classSym.registered;
10128 (exp.member.exp.type == identifierExp &&
10129 !strcmp(exp.member.exp.identifier.string, "this"));*/
10130 Property prop = null;
10131 Method method = null;
10132 DataMember member = null;
10133 Property revConvert = null;
10134 ClassProperty classProp = null;
10136 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10137 exp.member.memberType = propertyMember;
10139 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10140 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10142 if(typeKind != subClassType)
10144 // Prioritize data members over properties for "this"
10145 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10147 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10148 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10150 prop = eClass_FindProperty(_class, id.string, privateModule);
10154 if(!member && !prop)
10155 prop = eClass_FindProperty(_class, id.string, privateModule);
10156 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10157 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10158 exp.member.thisPtr = true;
10160 // Prioritize properties over data members otherwise
10163 bool useMemberForNonConst = false;
10164 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10167 prop = eClass_FindProperty(_class, id.string, null);
10169 useMemberForNonConst = prop && exp.destType &&
10170 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10171 !strncmp(prop.dataTypeString, "const ", 6);
10173 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10174 member = eClass_FindDataMember(_class, id.string, null, null, null);
10177 if((!prop || useMemberForNonConst) && !member)
10179 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10182 prop = eClass_FindProperty(_class, id.string, privateModule);
10184 useMemberForNonConst |= prop && exp.destType &&
10185 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10186 !strncmp(prop.dataTypeString, "const ", 6);
10188 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10189 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10195 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10202 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10203 method = eClass_FindMethod(_class, id.string, privateModule);
10204 if(!prop && !member && !method)
10206 if(typeKind == subClassType)
10208 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10211 exp.member.memberType = classPropertyMember;
10212 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10216 // Assume this is a class_data member
10217 char structName[1024];
10218 Identifier id = exp.member.member;
10219 Expression classExp = exp.member.exp;
10222 FreeType(classExp.expType);
10223 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10225 strcpy(structName, "__ecereClassData_");
10226 FullClassNameCat(structName, type._class.string, false);
10227 exp.type = pointerExp;
10228 exp.member.member = id;
10230 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10231 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10232 MkExpBrackets(MkListOne(MkExpOp(
10233 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10234 MkExpMember(classExp, MkIdentifier("data"))), '+',
10235 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10240 ProcessExpressionType(exp);
10246 // Check for reverse conversion
10247 // (Convert in an instantiation later, so that we can use
10248 // deep properties system)
10249 Symbol classSym = FindClass(id.string);
10252 Class convertClass = classSym.registered;
10254 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10259 //if(!exp.member.exp.destType)
10260 if(exp.member.exp.destType)
10261 FreeType(exp.member.exp.destType);
10263 if(method && !method._class.symbol)
10264 method._class.symbol = FindClass(method._class.fullName);
10265 if(prop && !prop._class.symbol)
10266 prop._class.symbol = FindClass(prop._class.fullName);
10268 exp.member.exp.destType = Type
10272 _class = prop ? prop._class.symbol : method ? method._class.symbol : _class.symbol;
10273 // wasThisClass = type ? type.wasThisClass : false;
10274 thisClassFrom = type ? type.thisClassFrom : null;
10280 exp.member.memberType = propertyMember;
10282 ProcessPropertyType(prop);
10283 exp.expType = prop.dataType;
10284 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10287 CopyTypeInto(type, exp.expType);
10289 type.constant = true;
10290 exp.expType = type;
10292 else if(prop.dataType)
10293 prop.dataType.refCount++;
10297 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10299 FreeExpContents(exp);
10300 exp.type = identifierExp;
10301 exp.identifier = MkIdentifier("class");
10302 ProcessExpressionType(exp);
10306 exp.member.memberType = dataMember;
10307 DeclareStruct(curExternal, _class.fullName, false, true);
10308 if(member._class != _class)
10309 DeclareStruct(curExternal, member._class.fullName, false, true);
10311 if(!member.dataType)
10313 Context context = SetupTemplatesContext(_class);
10314 member.dataType = ProcessTypeString(member.dataTypeString, false);
10315 FinishTemplatesContext(context);
10317 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)
10318 member.dataType.bitMemberSize = ((BitMember)member).size;
10319 exp.expType = member.dataType;
10320 if(member.dataType) member.dataType.refCount++;
10322 else if(revConvert)
10324 exp.member.memberType = reverseConversionMember;
10325 exp.expType = MkClassType(revConvert._class.fullName);
10333 exp.type = identifierExp;
10334 exp.identifier = exp.member.member;
10337 exp.member.memberType = methodMember;
10339 if(!method.dataType)
10340 ProcessMethodType(method);
10348 // Tricky spot here... To use instance versus class virtual table
10349 // Put it back to what it was... What did we break?
10351 // Had to put it back for overriding Main of Thread global instance
10353 //exp.expType.methodClass = _class;
10354 exp.expType.methodClass = (id && id._class) ? _class : null;
10356 // Need the actual class used for templated classes
10357 exp.expType.usedClass = _class;
10359 else if(!classProp)
10361 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10363 FreeExpContents(exp);
10364 exp.type = identifierExp;
10365 exp.identifier = MkIdentifier("class");
10366 FreeType(exp.expType);
10367 exp.expType = MkClassType("ecere::com::Class");
10370 yylloc = exp.member.member.loc;
10371 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10373 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10376 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10380 tClass = type._class && type._class.registered ? type._class.registered : _class;
10381 while(tClass && !tClass.templateClass) tClass = tClass.base;
10383 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10386 ClassTemplateParameter curParam = null;
10389 for(sClass = tClass; sClass; sClass = sClass.base)
10392 if(sClass.templateClass) sClass = sClass.templateClass;
10393 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10395 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10397 for(sClass = sClass.base; sClass; sClass = sClass.base)
10398 id += sClass.templateParams.count;
10403 if(curParam) break;
10406 if(curParam && tClass.templateArgs[id].dataTypeString)
10408 ClassTemplateArgument arg = tClass.templateArgs[id];
10409 Context context = SetupTemplatesContext(tClass);
10410 bool constant = exp.expType.constant;
10411 bool passAsTemplate = false;
10412 Class thisClassFrom = null;
10413 Type t = ProcessTypeString(exp.expType.templateParameter.dataTypeString, false);
10414 if(t && t.kind == classType && t._class)
10415 thisClassFrom = t._class.registered;
10417 // Mark that 'thisClassFrom' was set to something
10418 thisClassFrom = eSystem_FindClass(GetPrivateModule(), "class");
10422 passAsTemplate = tClass.templateClass && (exp.expType.kind != templateType ||
10423 (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType)));
10425 /*if(!arg.dataType)
10426 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10427 FreeType(exp.expType);
10429 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10430 exp.expType.thisClassFrom = thisClassFrom;
10431 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10432 else if(exp.expType.kind == pointerType)
10434 Type t = exp.expType.type;
10435 while(t.kind == pointerType) t = t.type;
10436 if(constant) t.constant = constant;
10440 if(exp.expType.kind == thisClassType)
10442 FreeType(exp.expType);
10443 exp.expType = ReplaceThisClassType(_class);
10447 exp.expType.passAsTemplate = true;
10448 //exp.expType.refCount++;
10451 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10452 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10453 else if(exp.destType.kind == pointerType)
10455 Type t = exp.destType.type;
10456 while(t.kind == pointerType) t = t.type;
10457 if(constant) t.constant = constant;
10460 //exp.destType.refCount++;
10462 if(exp.destType.kind == thisClassType)
10464 FreeType(exp.destType);
10465 exp.destType = ReplaceThisClassType(_class);
10469 FinishTemplatesContext(context);
10472 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10473 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10476 ClassTemplateParameter curParam = null;
10479 for(sClass = tClass; sClass; sClass = sClass.base)
10482 if(sClass.templateClass) sClass = sClass.templateClass;
10483 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10485 if(curParam.type == TemplateParameterType::type &&
10486 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10488 for(sClass = sClass.base; sClass; sClass = sClass.base)
10489 id += sClass.templateParams.count;
10494 if(curParam) break;
10499 ClassTemplateArgument arg = tClass.templateArgs[id];
10500 Context context = SetupTemplatesContext(tClass);
10502 /*if(!arg.dataType)
10503 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10505 basicType = ProcessTypeString(arg.dataTypeString, false);
10508 if(basicType.kind == thisClassType)
10510 FreeType(basicType);
10511 basicType = ReplaceThisClassType(_class);
10514 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10515 if(tClass.templateClass)
10516 basicType.passAsTemplate = true;
10519 FreeType(exp.expType);
10521 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10522 //exp.expType.refCount++;
10525 exp.destType = exp.expType;
10526 exp.destType.refCount++;
10530 Expression newExp { };
10531 OldList * specs = MkList();
10533 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10535 if(exp.destType) exp.destType.refCount++;
10536 if(exp.expType) exp.expType.refCount++;
10537 exp.type = castExp;
10538 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10539 exp.cast.exp = newExp;
10540 //FreeType(exp.expType);
10541 //exp.expType = null;
10542 //ProcessExpressionType(sourceExp);
10545 FinishTemplatesContext(context);
10548 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10550 Class expClass = exp.expType._class.registered;
10553 Class cClass = null;
10555 int paramCount = 0;
10556 int lastParam = -1;
10557 char templateString[1024];
10558 ClassTemplateParameter param;
10559 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10560 while(cClass != expClass)
10563 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10566 for(param = cClass.templateParams.first; param; param = param.next)
10568 Class cClassCur = null;
10570 ClassTemplateParameter paramCur = null;
10571 ClassTemplateArgument arg;
10572 while(cClassCur != tClass && !paramCur)
10575 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10576 cClassCur = sClassCur;
10578 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10580 if(!strcmp(paramCur.name, param.name))
10588 if(paramCur && paramCur.type == TemplateParameterType::type)
10589 arg = tClass.templateArgs[cp];
10591 arg = expClass.templateArgs[p];
10594 char argument[256];
10595 argument[0] = '\0';
10598 strcat(argument, arg.name.string);
10599 strcat(argument, " = ");
10605 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10606 char expString[1024];
10607 OldList * specs = MkList();
10608 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10610 char * string = PrintHexUInt64(arg.expression.ui64);
10611 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10614 ProcessExpressionType(exp);
10615 ComputeExpression(exp);
10616 expString[0] = '\0';
10617 PrintExpression(exp, expString);
10618 strcat(argument, expString);
10620 FreeExpression(exp);
10625 strcat(argument, arg.member.name);
10628 case TemplateParameterType::type:
10630 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10631 strcat(argument, arg.dataTypeString);
10637 if(paramCount) strcat(templateString, ", ");
10638 if(lastParam != p - 1)
10640 strcat(templateString, param.name);
10641 strcat(templateString, " = ");
10643 strcat(templateString, argument);
10652 int len = strlen(templateString);
10653 if(templateString[len-1] == '>') templateString[len++] = ' ';
10654 templateString[len++] = '>';
10655 templateString[len++] = '\0';
10658 FreeType(exp.expType);
10660 Context context = SetupTemplatesContext(tClass);
10661 exp.expType = ProcessTypeString(templateString, false);
10662 FinishTemplatesContext(context);
10669 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10671 else if(type && (type.kind == structType || type.kind == unionType))
10673 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10676 exp.expType = memberType;
10678 memberType.refCount++;
10683 char expString[10240];
10684 expString[0] = '\0';
10685 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10686 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10689 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10691 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10693 Identifier id = exp.member.member;
10694 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10697 FreeType(exp.expType);
10698 exp.expType = ReplaceThisClassType(_class);
10702 yylloc = oldyylloc;
10705 // Convert x->y into (*x).y
10708 Type destType = exp.destType;
10710 // DOING THIS LATER NOW...
10711 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10713 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10714 /* TODO: Name Space Fix ups
10715 if(!exp.member.member.classSym)
10716 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10720 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10721 exp.type = memberExp;
10724 ProcessExpressionType(exp);
10731 //ComputeExpression(exp);
10733 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10734 if(classSym && classSym.registered)
10736 if(classSym.registered.type == noHeadClass || (classSym.registered.fixed && classSym.registered.structSize))
10739 Class b = classSym.registered;
10741 DeclareStruct(curExternal, classSym.string, false, true);
10742 FreeSpecifier(exp._class);
10743 FullClassNameCat(name, classSym.string, false);
10747 exp.type = typeSizeExp;
10748 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10754 if(b.structSize == b.offset)
10755 exp.op.exp1 = MkExpConstant("0");
10757 exp.op.exp1 = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10760 while(b.offset != 0)
10763 Expression typeSize;
10766 sym = FindClass(b.fullName);
10769 DeclareStruct(curExternal, sym.string, false, true);
10770 FullClassNameCat(name, sym.string, false);
10772 if(b.structSize == b.offset)
10773 typeSize = MkExpConstant("0");
10775 typeSize = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10776 e.op.exp2 = b.offset ? MkExpOp(typeSize, '+', null) : typeSize;
10783 if(classSym.registered.fixed && !classSym.registered.structSize)
10785 FreeSpecifier(exp._class);
10786 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10787 exp.type = constantExp;
10791 char className[1024];
10792 strcpy(className, "__ecereClass_");
10793 FullClassNameCat(className, classSym.string, true);
10795 DeclareClass(curExternal, classSym, className);
10797 FreeExpContents(exp);
10798 exp.type = pointerExp;
10799 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10800 exp.member.member = MkIdentifier("structSize");
10808 kind = intSizeType;
10810 // exp.isConstant = true;
10815 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10820 kind = intSizeType;
10822 exp.isConstant = true;
10824 DeclareType(curExternal, type, true, false);
10830 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10832 FreeType(exp.cast.exp.destType);
10833 exp.cast.exp.destType = type;
10835 type.casted = true;
10836 ProcessExpressionType(exp.cast.exp);
10837 type.casted = false;
10839 exp.expType = type;
10842 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10843 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10845 void * prev = exp.prev, * next = exp.next;
10846 Type expType = exp.cast.exp.destType;
10847 Expression castExp = exp.cast.exp;
10848 Type destType = exp.destType;
10850 if(expType) expType.refCount++;
10852 //FreeType(exp.destType);
10853 FreeType(exp.expType);
10854 FreeTypeName(exp.cast.typeName);
10857 FreeType(exp.expType);
10858 FreeType(exp.destType);
10860 exp.expType = expType;
10861 exp.destType = destType;
10871 exp.isConstant = exp.cast.exp.isConstant;
10876 case extensionInitializerExp:
10878 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10879 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10880 // ProcessInitializer(exp.initializer.initializer, type);
10881 exp.expType = type;
10886 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10887 ProcessExpressionType(exp.vaArg.exp);
10888 exp.expType = type;
10894 Type t = exp.destType;
10895 if(t && !exp.destType.casted)
10898 CopyTypeInto(t, exp.destType);
10904 exp.isConstant = true;
10906 FreeType(exp.cond.cond.destType);
10907 exp.cond.cond.destType = MkClassType("bool");
10908 exp.cond.cond.destType.truth = true;
10909 ProcessExpressionType(exp.cond.cond);
10910 if(!exp.cond.cond.isConstant)
10911 exp.isConstant = false;
10912 for(e = exp.cond.exp->first; e; e = e.next)
10916 FreeType(e.destType);
10918 if(e.destType) e.destType.refCount++;
10920 ProcessExpressionType(e);
10923 exp.expType = e.expType;
10924 if(e.expType) e.expType.refCount++;
10927 exp.isConstant = false;
10930 FreeType(exp.cond.elseExp.destType);
10931 // Added this check if we failed to find an expType
10932 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10935 exp.cond.elseExp.destType = t ? t : exp.expType;
10937 if(exp.cond.elseExp.destType)
10938 exp.cond.elseExp.destType.refCount++;
10939 ProcessExpressionType(exp.cond.elseExp);
10941 // FIXED THIS: Was done before calling process on elseExp
10942 if(!exp.cond.elseExp.isConstant)
10943 exp.isConstant = false;
10948 case extensionCompoundExp:
10950 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10952 Statement last = exp.compound.compound.statements->last;
10953 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10955 ((Expression)last.expressions->last).destType = exp.destType;
10957 exp.destType.refCount++;
10959 ProcessStatement(exp.compound);
10960 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10962 exp.expType.refCount++;
10968 Specifier spec = exp._classExp.specifiers->first;
10969 if(spec && spec.type == nameSpecifier)
10971 exp.expType = MkClassType(spec.name);
10972 exp.expType.kind = subClassType;
10973 exp.byReference = true;
10977 exp.expType = MkClassType("ecere::com::Class");
10978 exp.byReference = true;
10984 Class _class = thisClass ? thisClass : currentClass;
10987 Identifier id = exp.classData.id;
10988 char structName[1024];
10989 Expression classExp;
10990 strcpy(structName, "__ecereClassData_");
10991 FullClassNameCat(structName, _class.fullName, false);
10992 exp.type = pointerExp;
10993 exp.member.member = id;
10994 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10995 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10997 classExp = MkExpIdentifier(MkIdentifier("class"));
10999 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
11000 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
11001 MkExpBrackets(MkListOne(MkExpOp(
11002 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
11003 MkExpMember(classExp, MkIdentifier("data"))), '+',
11004 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
11007 ProcessExpressionType(exp);
11015 const char * typeString = null;
11016 char typeStringBuf[1024];
11017 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
11018 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
11020 Class templateClass = exp.destType._class.registered;
11021 typeString = templateClass.templateArgs[2].dataTypeString;
11025 // Guess type from expressions in the array
11027 for(e = exp.list->first; e; e = e.next)
11029 ProcessExpressionType(e);
11032 if(!type) { type = e.expType; type.refCount++; }
11035 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11036 if(!MatchTypeExpression(e, type, null, false, true))
11042 e = exp.list->first;
11043 ProcessExpressionType(e);
11046 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
11047 if(!MatchTypeExpression(e, type, null, false, true))
11049 FreeType(e.expType);
11060 FreeType(e.expType);
11067 typeStringBuf[0] = '\0';
11068 PrintTypeNoConst(type, typeStringBuf, false, true);
11069 typeString = typeStringBuf;
11077 (Container)& (struct BuiltInContainer)
11079 ._vTbl = class(BuiltInContainer)._vTbl,
11080 ._class = class(BuiltInContainer),
11082 .data = (int[]){ 1, 7, 3, 4, 5 },
11084 .type = class(int),
11087 char templateString[1024];
11088 OldList * initializers = MkList();
11089 OldList * structInitializers = MkList();
11090 OldList * specs = MkList();
11092 Declarator decl = SpecDeclFromString(typeString, specs, null);
11093 sprintf(templateString, "Container<%s>", typeString);
11098 type = ProcessTypeString(typeString, false);
11099 while((e = exp.list->first))
11101 exp.list->Remove(e);
11104 ProcessExpressionType(e);
11105 ListAdd(initializers, MkInitializerAssignment(e));
11111 DeclareStruct(curExternal, "ecere::com::BuiltInContainer", false, true);
11113 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
11114 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11115 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
11116 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11117 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
11118 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11119 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
11120 MkTypeName(specs, MkDeclaratorArray(decl, null)),
11121 MkInitializerList(initializers))));
11122 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11123 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
11124 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11125 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
11126 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11127 exp.expType = ProcessTypeString(templateString, false);
11128 exp.type = bracketsExp;
11129 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
11131 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
11132 MkInitializerList(structInitializers)))));
11133 ProcessExpressionType(expExt);
11137 exp.expType = ProcessTypeString("Container", false);
11138 Compiler_Error($"Couldn't determine type of array elements\n");
11144 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
11146 FreeType(exp.expType);
11147 exp.expType = ReplaceThisClassType(thisClass);
11150 // Resolve structures here
11151 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
11153 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
11154 // TODO: Fix members reference...
11157 if(exp.expType.kind != enumType)
11160 String enumName = CopyString(exp.expType.enumName);
11162 // Fixed a memory leak on self-referencing C structs typedefs
11163 // by instantiating a new type rather than simply copying members
11164 // into exp.expType
11165 FreeType(exp.expType);
11166 exp.expType = Type { };
11167 exp.expType.kind = symbol.type.kind;
11168 exp.expType.refCount++;
11169 exp.expType.enumName = enumName;
11171 exp.expType.members = symbol.type.members;
11172 for(member = symbol.type.members.first; member; member = member.next)
11177 NamedLink64 member;
11178 for(member = symbol.type.members.first; member; member = member.next)
11180 NamedLink64 value { name = CopyString(member.name) };
11181 exp.expType.members.Add(value);
11187 // Trying to do this here before conversion properties kick in and this becomes a new expression... (Fixing Class c; const char * a = c;)
11188 // Mark nohead classes as by reference, unless we're casting them to an integral type
11189 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11190 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11191 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11192 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11194 exp.byReference = true;
11198 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11199 else if(exp.destType && !exp.destType.keepCast)
11201 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11202 exp.needTemplateCast = 1;
11204 if(exp.destType.kind == voidType);
11205 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11207 // Warn for casting unrelated types to/from struct classes
11208 bool invalidCast = false;
11209 if(inCompiler && exp.destType.count && exp.expType)
11211 Class c1 = (exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
11212 Class c2 = (exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
11213 if(c1 && c1.type != structClass) c1 = null;
11214 if(c2 && c2.type != structClass) c2 = null;
11215 if((c1 && !exp.expType.byReference && !c2 && !exp.destType.isPointerType) || (c2 && !exp.destType.byReference && !c1 && !exp.expType.isPointerType))
11216 invalidCast = true;
11218 if(!exp.destType.count || unresolved || invalidCast)
11223 if(exp.destType.kind != ellipsisType)
11229 char expString[10240];
11230 expString[0] = '\0';
11232 PrintType(exp.destType, type2, false, true);
11234 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11236 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11237 else if(exp.type != dummyExp)
11238 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11243 char expString[10240] ;
11244 expString[0] = '\0';
11245 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11248 Compiler_Error($"unresolved identifier %s\n", expString);
11249 else if(exp.type != dummyExp)
11250 Compiler_Error($"couldn't determine type of %s\n", expString);
11261 PrintType(exp.expType, type1, false, true);
11262 PrintType(exp.destType, type2, false, true);
11265 //CheckExpressionType(exp, exp.destType, false);
11267 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11268 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11269 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11272 Expression nbExp = GetNonBracketsExp(exp);
11273 bool skipWarning = false;
11274 TypeKind kind = exp.destType.kind;
11275 if(nbExp.type == conditionExp && nbExp.destType && !nbExp.destType.casted && nbExp.destType.kind == exp.destType.kind)
11276 // The if/else operands have already been checked / warned about
11277 skipWarning = true;
11278 if((kind == charType || kind == shortType) && exp.destType.isSigned == exp.expType.signedBeforePromotion && nbExp.type == opExp && nbExp.op.exp1 && nbExp.op.exp2)
11280 int op = nbExp.op.op;
11281 Expression nbExp1, nbExp2;
11286 case '%': case '/':
11287 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11288 from = nbExp1.expType.promotedFrom;
11289 // Division and Modulo will not take more room than type before promotion
11290 if(from == charType || (kind == shortType && from == shortType))
11291 skipWarning = true;
11294 case LEFT_OP: case RIGHT_OP:
11295 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11296 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11297 from = nbExp1.expType.promotedFrom;
11298 // Right shift will not take more room than type before promotion
11299 if(op == RIGHT_OP && (from == charType || (kind == shortType && from == shortType)))
11300 skipWarning = true;
11301 else if(nbExp2.isConstant && nbExp2.type == constantExp && (nbExp.op.op == RIGHT_OP || nbExp1.expType.bitMemberSize))
11303 int n = (int)strtol(nbExp2.constant, null, 0);
11304 int s = from == charType ? 8 : 16;
11305 // Left shifting a bit member constrained in size may still fit in type before promotion
11306 if(nbExp1.expType.bitMemberSize && nbExp1.expType.bitMemberSize < s)
11307 s = nbExp1.expType.bitMemberSize;
11309 // If right shifted enough things will fit in smaller type
11310 if(nbExp.op.op == RIGHT_OP)
11314 if(s <= (kind == charType ? 8 : 16))
11315 skipWarning = true;
11319 if(!exp.destType.isSigned)
11321 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11322 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11323 from = nbExp2.expType.promotedFrom;
11324 // Max value of unsigned type before promotion minus the same will always fit
11325 if((from == charType || from == shortType) && nbExp1.isConstant && nbExp1.type == constantExp)
11327 int n = (int)strtol(nbExp1.constant, null, 0);
11328 if(n == (from == charType ? 255 : 65535))
11329 skipWarning = true;
11335 TypeKind kind1, kind2;
11336 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11337 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11338 kind1 = nbExp1.expType.promotedFrom ? nbExp1.expType.promotedFrom : nbExp1.expType.kind;
11339 kind2 = nbExp2.expType.promotedFrom ? nbExp2.expType.promotedFrom : nbExp2.expType.kind;
11340 if(((kind1 == charType || (kind1 == shortType && kind == shortType)) || MatchTypeExpression(nbExp1, exp.destType, null, false, false)) &&
11341 ((kind2 == charType || (kind2 == shortType && kind == shortType)) || MatchTypeExpression(nbExp2, exp.destType, null, false, false)))
11342 skipWarning = true;
11347 TypeKind kind1, kind2;
11348 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11349 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11350 kind1 = nbExp1.expType.promotedFrom ? nbExp1.expType.promotedFrom : nbExp1.expType.kind;
11351 kind2 = nbExp2.expType.promotedFrom ? nbExp2.expType.promotedFrom : nbExp2.expType.kind;
11352 if(((kind1 == charType || (kind1 == shortType && kind == shortType)) || MatchTypeExpression(nbExp1, exp.destType, null, false, false)) ||
11353 ((kind2 == charType || (kind2 == shortType && kind == shortType)) || MatchTypeExpression(nbExp2, exp.destType, null, false, false)))
11354 skipWarning = true;
11362 char expString[10240];
11363 expString[0] = '\0';
11364 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11367 CheckExpressionType(exp, exp.destType, false, true);
11370 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11371 if(!sourceFile || (!strstr(sourceFile, "src\\lexer.ec") && !strstr(sourceFile, "src/lexer.ec") &&
11372 !strstr(sourceFile, "src\\grammar.ec") && !strstr(sourceFile, "src/grammar.ec") &&
11373 !strstr(sourceFile, "src\\type.ec") && !strstr(sourceFile, "src/type.ec") &&
11374 !strstr(sourceFile, "src\\expression.ec") && !strstr(sourceFile, "src/expression.ec")))
11377 Compiler_Error($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11379 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11383 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11386 FreeType(exp.expType);
11387 exp.destType.refCount++;
11388 exp.expType = exp.destType;
11394 // Cast function pointers to void * as eC already checked compatibility
11395 else if(exp.destType && exp.destType.kind == pointerType && exp.destType.type && exp.destType.type.kind == functionType &&
11396 exp.expType && (exp.expType.kind == functionType || exp.expType.kind == methodType))
11398 Expression nbExp = GetNonBracketsExp(exp);
11399 if(nbExp.type != castExp || !IsVoidPtrCast(nbExp.cast.typeName))
11401 Expression e = MoveExpContents(exp);
11402 exp.cast.exp = MkExpBrackets(MkListOne(e));
11403 exp.type = castExp;
11404 exp.cast.exp.destType = exp.destType;
11405 if(exp.destType) exp.destType.refCount++;
11406 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
11410 else if(unresolved)
11412 if(exp.identifier._class && exp.identifier._class.name)
11413 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11414 else if(exp.identifier.string && exp.identifier.string[0])
11415 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11417 else if(!exp.expType && exp.type != dummyExp)
11419 char expString[10240];
11420 expString[0] = '\0';
11421 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11422 Compiler_Error($"couldn't determine type of %s\n", expString);
11425 // Let's try to support any_object & typed_object here:
11427 ApplyAnyObjectLogic(exp);
11429 // Mark nohead classes as by reference, unless we're casting them to an integral type
11430 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11431 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11432 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11433 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11435 exp.byReference = true;
11437 yylloc = oldyylloc;
11440 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11442 // THIS CODE WILL FIND NEXT MEMBER...
11445 *curMember = (*curMember).next;
11447 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11449 *curMember = subMemberStack[--(*subMemberStackPos)];
11450 *curMember = (*curMember).next;
11453 // SKIP ALL PROPERTIES HERE...
11454 while((*curMember) && (*curMember).isProperty)
11455 *curMember = (*curMember).next;
11457 if(subMemberStackPos)
11459 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11461 subMemberStack[(*subMemberStackPos)++] = *curMember;
11463 *curMember = (*curMember).members.first;
11464 while(*curMember && (*curMember).isProperty)
11465 *curMember = (*curMember).next;
11473 if(subMemberStackPos && *subMemberStackPos)
11475 *curMember = subMemberStack[--(*subMemberStackPos)];
11476 *curMember = (*curMember).next;
11480 Class lastCurClass = *curClass;
11482 if(*curClass == _class) break; // REACHED THE END
11484 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11485 *curMember = (*curClass).membersAndProperties.first;
11488 while((*curMember) && (*curMember).isProperty)
11489 *curMember = (*curMember).next;
11490 if(subMemberStackPos)
11492 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11494 subMemberStack[(*subMemberStackPos)++] = *curMember;
11496 *curMember = (*curMember).members.first;
11497 while(*curMember && (*curMember).isProperty)
11498 *curMember = (*curMember).next;
11506 static void ProcessInitializer(Initializer init, Type type)
11510 case expInitializer:
11511 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11513 // TESTING THIS FOR SHUTTING = 0 WARNING
11514 if(init.exp && !init.exp.destType)
11516 FreeType(init.exp.destType);
11517 init.exp.destType = type;
11518 if(type) type.refCount++;
11522 ProcessExpressionType(init.exp);
11523 init.isConstant = init.exp.isConstant;
11529 Expression exp = init.exp;
11530 Instantiation inst = exp.instance;
11531 MembersInit members;
11533 init.type = listInitializer;
11534 init.list = MkList();
11538 for(members = inst.members->first; members; members = members.next)
11540 if(members.type == dataMembersInit)
11543 for(member = members.dataMembers->first; member; member = member.next)
11545 ListAdd(init.list, member.initializer);
11546 member.initializer = null;
11549 // Discard all MembersInitMethod
11552 FreeExpression(exp);
11554 case listInitializer:
11557 Type initializerType = null;
11558 Class curClass = null;
11559 DataMember curMember = null;
11560 DataMember subMemberStack[256];
11561 int subMemberStackPos = 0;
11563 if(type && type.kind == arrayType)
11564 initializerType = Dereference(type);
11565 else if(type && (type.kind == structType || type.kind == unionType))
11566 initializerType = type.members.first;
11568 for(i = init.list->first; i; i = i.next)
11570 if(type && type.kind == classType && type._class && type._class.registered)
11572 // 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)
11573 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11574 // TODO: Generate error on initializing a private data member this way from another module...
11577 if(!curMember.dataType)
11578 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11579 initializerType = curMember.dataType;
11582 ProcessInitializer(i, initializerType);
11583 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11584 initializerType = initializerType.next;
11586 init.isConstant = false;
11589 if(type && type.kind == arrayType)
11590 FreeType(initializerType);
11592 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11594 Compiler_Error($"Assigning list initializer to non list\n");
11601 static void ProcessSpecifier(Specifier spec, bool declareStruct, bool warnClasses)
11605 case baseSpecifier:
11607 if(spec.specifier == THISCLASS)
11611 spec.type = nameSpecifier;
11612 spec.name = ReplaceThisClass(thisClass);
11613 spec.symbol = FindClass(spec.name);
11614 ProcessSpecifier(spec, declareStruct, false);
11619 case nameSpecifier:
11621 Symbol symbol = FindType(curContext, spec.name);
11623 DeclareType(curExternal, symbol.type, true, true);
11624 else if(spec.symbol /*&& declareStruct*/)
11626 Class c = spec.symbol.registered;
11627 if(warnClasses && !c)
11628 Compiler_Warning("Undeclared class %s\n", spec.name);
11629 DeclareStruct(curExternal, spec.name, c && c.type == noHeadClass, declareStruct && c && c.type == structClass);
11633 case enumSpecifier:
11638 for(e = spec.list->first; e; e = e.next)
11641 ProcessExpressionType(e.exp);
11644 // Fall through for IDE type processing
11648 case structSpecifier:
11649 case unionSpecifier:
11651 if(spec.definitions)
11654 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11656 ProcessClass(spec.definitions, symbol);
11659 for(def = spec.definitions->first; def; def = def.next)
11661 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11662 ProcessDeclaration(def.decl);
11669 case classSpecifier:
11671 Symbol classSym = FindClass(spec.name);
11672 if(classSym && classSym.registered && classSym.registered.type == structClass)
11673 DeclareStruct(spec.name, false, true);
11681 static void ProcessDeclarator(Declarator decl, bool isFunction)
11685 case identifierDeclarator:
11686 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11688 FreeSpecifier(decl.identifier._class);
11689 decl.identifier._class = null;
11692 case arrayDeclarator:
11694 ProcessExpressionType(decl.array.exp);
11695 case structDeclarator:
11696 case bracketsDeclarator:
11697 case functionDeclarator:
11698 case pointerDeclarator:
11699 case extendedDeclarator:
11700 case extendedDeclaratorEnd:
11702 Identifier id = null;
11703 Specifier classSpec = null;
11704 if(decl.type == functionDeclarator)
11706 id = GetDeclId(decl);
11707 if(id && id._class)
11709 classSpec = id._class;
11713 if(decl.declarator)
11714 ProcessDeclarator(decl.declarator, isFunction);
11715 if(decl.type == functionDeclarator)
11721 qualifiers = MkListOne(classSpec);
11724 if(!decl.function.parameters)
11725 decl.function.parameters = MkList();
11726 decl.function.parameters->Insert(null, param);
11728 if(decl.function.parameters)
11732 for(param = decl.function.parameters->first; param; param = param.next)
11734 if(param.qualifiers)
11737 for(spec = param.qualifiers->first; spec; spec = spec.next)
11739 if(spec.type == baseSpecifier)
11741 if(spec.specifier == TYPED_OBJECT)
11743 Declarator d = param.declarator;
11746 qualifiers = MkListOne(MkSpecifier(VOID));
11747 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11749 if(!d || d.type != pointerDeclarator)
11750 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11752 FreeList(param.qualifiers, FreeSpecifier);
11754 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11755 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11757 DeclareStruct(curExternal, "ecere::com::Class", false, true);
11759 decl.function.parameters->Insert(param, newParam);
11763 else if(spec.specifier == ANY_OBJECT)
11765 Declarator d = param.declarator;
11767 FreeList(param.qualifiers, FreeSpecifier);
11769 param.qualifiers = MkListOne(MkSpecifier(VOID));
11770 if(!d || d.type != pointerDeclarator)
11771 param.qualifiers->Insert(null, MkSpecifier(CONST));
11772 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11775 else if(spec.specifier == THISCLASS)
11779 spec.type = nameSpecifier;
11780 spec.name = ReplaceThisClass(thisClass);
11781 spec.symbol = FindClass(spec.name);
11782 ProcessSpecifier(spec, false, false);
11787 else if(spec.type == nameSpecifier)
11789 ProcessSpecifier(spec, isFunction, true);
11791 else if((spec.type == structSpecifier || spec.type == unionSpecifier) && !spec.definitions && spec.id && spec.id.string)
11793 Declarator d = param.declarator;
11794 if(!d || d.type != pointerDeclarator)
11795 DeclareStruct(curExternal, spec.id.string, false, true);
11800 if(param.declarator)
11801 ProcessDeclarator(param.declarator, false);
11810 static void ProcessDeclaration(Declaration decl, bool warnClasses)
11815 case initDeclaration:
11817 bool declareStruct = false;
11819 lineNum = decl.pos.line;
11820 column = decl.pos.col;
11823 if(decl.declarators)
11827 for(d = decl.declarators->first; d; d = d.next)
11829 Type type, subType;
11830 ProcessDeclarator(d.declarator, false);
11832 type = ProcessType(decl.specifiers, d.declarator);
11836 ProcessInitializer(d.initializer, type);
11838 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11840 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11841 d.initializer.exp.type == instanceExp)
11843 if(type.kind == classType && type._class ==
11844 d.initializer.exp.expType._class)
11846 Instantiation inst = d.initializer.exp.instance;
11847 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11849 d.initializer.exp.instance = null;
11850 if(decl.specifiers)
11851 FreeList(decl.specifiers, FreeSpecifier);
11852 FreeList(decl.declarators, FreeInitDeclarator);
11856 decl.type = instDeclaration;
11861 for(subType = type; subType;)
11863 if(subType.kind == classType)
11865 declareStruct = true;
11868 else if(subType.kind == pointerType)
11870 else if(subType.kind == arrayType)
11871 subType = subType.arrayType;
11881 if(decl.specifiers)
11884 for(s = decl.specifiers->first; s; s = s.next)
11886 ProcessSpecifier(s, declareStruct, true);
11891 case instDeclaration:
11893 ProcessInstantiationType(decl.inst);
11896 case structDeclaration:
11900 bool declareStruct = false;
11902 if(decl.declarators)
11904 for(d = decl.declarators->first; d; d = d.next)
11906 Type type = ProcessType(decl.specifiers, d.declarator);
11908 ProcessDeclarator(d, false);
11909 for(subType = type; subType;)
11911 if(subType.kind == classType)
11913 declareStruct = true;
11916 else if(subType.kind == pointerType)
11918 else if(subType.kind == arrayType)
11919 subType = subType.arrayType;
11926 if(decl.specifiers)
11928 for(spec = decl.specifiers->first; spec; spec = spec.next)
11929 ProcessSpecifier(spec, declareStruct, warnClasses);
11936 static FunctionDefinition curFunction;
11938 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11940 char propName[1024], propNameM[1024];
11941 char getName[1024], setName[1024];
11944 DeclareProperty(curExternal, prop, setName, getName);
11946 // eInstance_FireWatchers(object, prop);
11947 strcpy(propName, "__ecereProp_");
11948 FullClassNameCat(propName, prop._class.fullName, false);
11949 strcat(propName, "_");
11950 FullClassNameCat(propName, prop.name, true);
11952 strcpy(propNameM, "__ecerePropM_");
11953 FullClassNameCat(propNameM, prop._class.fullName, false);
11954 strcat(propNameM, "_");
11955 FullClassNameCat(propNameM, prop.name, true);
11957 if(prop.isWatchable)
11960 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11961 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11962 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11965 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11966 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11967 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11969 DeclareFunctionUtil(curExternal, "eInstance_FireWatchers");
11974 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11975 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11976 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11979 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11980 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11981 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11983 DeclareFunctionUtil(curExternal, "eInstance_FireSelfWatchers");
11986 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11987 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11988 curFunction.propSet.fireWatchersDone = true;
11991 static void ProcessStatement(Statement stmt)
11995 lineNum = stmt.pos.line;
11996 column = stmt.pos.col;
12001 ProcessStatement(stmt.labeled.stmt);
12004 // This expression should be constant...
12005 if(stmt.caseStmt.exp)
12007 FreeType(stmt.caseStmt.exp.destType);
12008 stmt.caseStmt.exp.destType = curSwitchType;
12009 if(curSwitchType) curSwitchType.refCount++;
12010 ProcessExpressionType(stmt.caseStmt.exp);
12011 ComputeExpression(stmt.caseStmt.exp);
12013 if(stmt.caseStmt.stmt)
12014 ProcessStatement(stmt.caseStmt.stmt);
12018 if(stmt.compound.context)
12023 Statement prevCompound = curCompound;
12024 Context prevContext = curContext;
12026 if(!stmt.compound.isSwitch)
12027 curCompound = stmt;
12028 curContext = stmt.compound.context;
12030 if(stmt.compound.declarations)
12032 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
12033 ProcessDeclaration(decl, true);
12035 if(stmt.compound.statements)
12037 for(s = stmt.compound.statements->first; s; s = s.next)
12038 ProcessStatement(s);
12041 curContext = prevContext;
12042 curCompound = prevCompound;
12046 case expressionStmt:
12049 if(stmt.expressions)
12051 for(exp = stmt.expressions->first; exp; exp = exp.next)
12052 ProcessExpressionType(exp);
12060 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
12061 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
12062 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
12063 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
12065 ProcessExpressionType(exp);
12067 if(stmt.ifStmt.stmt)
12068 ProcessStatement(stmt.ifStmt.stmt);
12069 if(stmt.ifStmt.elseStmt)
12070 ProcessStatement(stmt.ifStmt.elseStmt);
12075 Type oldSwitchType = curSwitchType;
12076 if(stmt.switchStmt.exp)
12079 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
12089 e.exp.destType = destType;
12092 ProcessExpressionType(exp);
12095 curSwitchType = exp.expType;
12098 ProcessStatement(stmt.switchStmt.stmt);
12099 curSwitchType = oldSwitchType;
12104 if(stmt.whileStmt.exp)
12108 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
12109 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
12110 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
12111 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
12113 ProcessExpressionType(exp);
12116 if(stmt.whileStmt.stmt)
12117 ProcessStatement(stmt.whileStmt.stmt);
12122 if(stmt.doWhile.exp)
12126 if(stmt.doWhile.exp->last)
12128 FreeType(((Expression)stmt.doWhile.exp->last).destType);
12129 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
12130 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
12132 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
12134 ProcessExpressionType(exp);
12137 if(stmt.doWhile.stmt)
12138 ProcessStatement(stmt.doWhile.stmt);
12144 if(stmt.forStmt.init)
12145 ProcessStatement(stmt.forStmt.init);
12147 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
12149 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
12150 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
12151 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
12154 if(stmt.forStmt.check)
12155 ProcessStatement(stmt.forStmt.check);
12156 if(stmt.forStmt.increment)
12158 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
12159 ProcessExpressionType(exp);
12162 if(stmt.forStmt.stmt)
12163 ProcessStatement(stmt.forStmt.stmt);
12168 Identifier id = stmt.forEachStmt.id;
12169 OldList * exp = stmt.forEachStmt.exp;
12170 OldList * filter = stmt.forEachStmt.filter;
12171 Statement block = stmt.forEachStmt.stmt;
12172 char iteratorType[1024];
12175 bool isBuiltin = exp && exp->last &&
12176 (((Expression)exp->last).type == ExpressionType::arrayExp ||
12177 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
12178 Expression arrayExp;
12179 const char * typeString = null;
12180 int builtinCount = 0;
12182 for(e = exp ? exp->first : null; e; e = e.next)
12186 FreeType(e.destType);
12187 e.destType = ProcessTypeString("Container", false);
12189 if(!isBuiltin || e.next)
12190 ProcessExpressionType(e);
12193 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
12194 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
12195 eClass_IsDerived(source._class.registered, containerClass)))
12197 Class _class = source ? source._class.registered : null;
12199 Expression expIt = null;
12200 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
12201 Class arrayClass = eSystem_FindClass(privateModule, "Array");
12202 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
12203 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
12207 stmt.type = compoundStmt;
12209 stmt.compound.context = Context { };
12210 stmt.compound.context.parent = curContext;
12211 curContext = stmt.compound.context;
12214 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
12216 Class mapClass = eSystem_FindClass(privateModule, "Map");
12217 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
12218 isCustomAVLTree = true;
12219 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
12221 else */if(eClass_IsDerived(source._class.registered, mapClass))
12224 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
12225 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
12227 Class listClass = eSystem_FindClass(privateModule, "List");
12229 isList = eClass_IsDerived(source._class.registered, listClass);
12232 if(inCompiler && isArray)
12235 OldList * specs = MkList();
12236 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12237 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12238 stmt.compound.declarations = MkListOne(
12239 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12240 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12241 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
12242 MkInitializerAssignment(MkExpBrackets(exp))))));
12247 char typeStringBuf[1024];
12249 // TODO: Merge this code?
12250 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
12251 if(((Expression)exp->last).type == castExp)
12253 TypeName typeName = ((Expression)exp->last).cast.typeName;
12255 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
12258 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
12259 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
12260 arrayExp.destType._class.registered.templateArgs)
12262 Class templateClass = arrayExp.destType._class.registered;
12263 typeString = templateClass.templateArgs[2].dataTypeString;
12265 else if(arrayExp.list)
12267 // Guess type from expressions in the array
12269 for(e = arrayExp.list->first; e; e = e.next)
12271 ProcessExpressionType(e);
12274 if(!type) { type = e.expType; type.refCount++; }
12277 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
12278 if(!MatchTypeExpression(e, type, null, false, true))
12284 e = arrayExp.list->first;
12285 ProcessExpressionType(e);
12288 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
12289 if(!MatchTypeExpression(e, type, null, false, true))
12291 FreeType(e.expType);
12302 FreeType(e.expType);
12309 typeStringBuf[0] = '\0';
12310 PrintType(type, typeStringBuf, false, true);
12311 typeString = typeStringBuf;
12319 OldList * initializers = MkList();
12321 OldList * specs = MkList();
12326 builtinCount = arrayExp.list->count;
12327 type = ProcessTypeString(typeString, false);
12328 while((e = arrayExp.list->first))
12330 arrayExp.list->Remove(e);
12333 ProcessExpressionType(e);
12335 ListAdd(initializers, MkInitializerAssignment(e));
12338 delete arrayExp.list;
12340 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12342 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12343 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12345 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12347 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12348 ), MkInitializerList(initializers)))));
12349 FreeList(exp, FreeExpression);
12351 else if(arrayExp.list)
12354 type = ProcessTypeString(typeString, false);
12355 for(e = arrayExp.list->first; e; e = e.next)
12359 ProcessExpressionType(e);
12366 arrayExp.expType = ProcessTypeString("Container", false);
12367 Compiler_Error($"Couldn't determine type of array elements\n");
12372 OldList * specs = MkList();
12374 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12375 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12376 stmt.compound.declarations = MkListOne(
12377 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12378 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12379 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12380 MkInitializerAssignment(MkExpBrackets(exp))))));
12383 else if(inCompiler && isLinkList && !isList)
12386 OldList * specs = MkList();
12387 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12388 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12389 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12390 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12391 MkInitializerAssignment(MkExpBrackets(exp))))));
12393 /*else if(isCustomAVLTree)
12396 OldList * specs = MkList();
12397 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12398 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12399 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12400 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12401 MkInitializerAssignment(MkExpBrackets(exp))))));
12403 else if(inCompiler && _class.templateArgs)
12406 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12408 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12410 stmt.compound.declarations = MkListOne(
12411 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12412 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12413 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12417 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12421 // Reparent sub-contexts in this statement
12425 if(block.compound.context)
12426 block.compound.context.parent = stmt.compound.context;
12429 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12430 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12431 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12432 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12435 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12436 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12439 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12440 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12443 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12444 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12447 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12448 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12451 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12452 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12454 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12457 case expressionStmt:
12463 case badDeclarationStmt:
12464 case fireWatchersStmt:
12465 case stopWatchingStmt:
12473 block = MkIfStmt(filter, block, null);
12477 stmt.compound.statements = MkListOne(MkForStmt(
12478 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12479 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12480 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12481 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12483 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12484 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12485 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12490 //OldList * specs = MkList();
12491 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12493 sprintf(count, "%d", builtinCount);
12495 stmt.compound.statements = MkListOne(MkForStmt(
12496 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12497 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12498 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12499 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12503 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12504 stmt.compound.statements = MkListOne(MkForStmt(
12505 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12506 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12507 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12508 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12511 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12512 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12513 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12515 else if(isLinkList && !isList)
12517 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12518 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12519 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12520 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12522 stmt.compound.statements = MkListOne(MkForStmt(
12523 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12524 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12525 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12530 OldList * specs = MkList();
12531 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12532 stmt.compound.statements = MkListOne(MkForStmt(
12533 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12534 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12535 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12536 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12537 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12540 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12541 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12542 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12544 /*else if(isCustomAVLTree)
12546 stmt.compound.statements = MkListOne(MkForStmt(
12547 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12548 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12549 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12550 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12553 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12554 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12555 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12559 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12560 MkIdentifier("Next")), null)), block));
12562 ProcessExpressionType(expIt);
12563 if(stmt.compound.declarations->first)
12564 ProcessDeclaration(stmt.compound.declarations->first, true);
12567 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12569 ProcessStatement(stmt);
12572 ProcessStatement(stmt.forEachStmt.stmt);
12574 curContext = stmt.compound.context.parent;
12579 Compiler_Error($"Expression is not a container\n");
12592 if(stmt.expressions)
12594 for(exp = stmt.expressions->first; exp; exp = exp.next)
12598 if(curFunction && !curFunction.type)
12599 curFunction.type = ProcessType(
12600 curFunction.specifiers, curFunction.declarator);
12601 FreeType(exp.destType);
12602 // TODO: current property if not compiling
12603 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12604 if(exp.destType) exp.destType.refCount++;
12606 ProcessExpressionType(exp);
12611 case badDeclarationStmt:
12613 ProcessDeclaration(stmt.decl, true);
12619 if(stmt.asmStmt.inputFields)
12621 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12622 if(field.expression)
12623 ProcessExpressionType(field.expression);
12625 if(stmt.asmStmt.outputFields)
12627 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12628 if(field.expression)
12629 ProcessExpressionType(field.expression);
12631 if(stmt.asmStmt.clobberedFields)
12633 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12635 if(field.expression)
12636 ProcessExpressionType(field.expression);
12643 PropertyWatch propWatch;
12644 OldList * watches = stmt._watch.watches;
12645 Expression object = stmt._watch.object;
12646 Expression watcher = stmt._watch.watcher;
12648 ProcessExpressionType(watcher);
12650 ProcessExpressionType(object);
12654 if(watcher || thisClass)
12656 External external = curExternal;
12657 Context context = curContext;
12659 stmt.type = expressionStmt;
12660 stmt.expressions = MkList();
12662 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12664 ClassFunction func;
12665 char watcherName[1024];
12666 Class watcherClass = watcher ?
12667 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12668 External createdExternal;
12670 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12671 if(propWatch.deleteWatch)
12672 strcat(watcherName, "_delete");
12676 for(propID = propWatch.properties->first; propID; propID = propID.next)
12678 strcat(watcherName, "_");
12679 strcat(watcherName, propID.string);
12683 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12685 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12686 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12687 ProcessClassFunctionBody(func, propWatch.compound);
12688 propWatch.compound = null;
12690 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12692 FreeClassFunction(func);
12694 curExternal = createdExternal;
12695 ProcessFunction(createdExternal.function);
12697 if(propWatch.deleteWatch)
12699 OldList * args = MkList();
12700 ListAdd(args, CopyExpression(object));
12701 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12702 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12703 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12707 Class _class = object.expType._class.registered;
12710 for(propID = propWatch.properties->first; propID; propID = propID.next)
12712 char propName[1024];
12713 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12716 char getName[1024], setName[1024];
12717 OldList * args = MkList();
12719 DeclareProperty(createdExternal, prop, setName, getName);
12721 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12722 strcpy(propName, "__ecereProp_");
12723 FullClassNameCat(propName, prop._class.fullName, false);
12724 strcat(propName, "_");
12725 FullClassNameCat(propName, prop.name, true);
12727 ListAdd(args, CopyExpression(object));
12728 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12729 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12730 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpIdentifier(MkIdentifier(watcherName))));
12732 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12734 external.CreateUniqueEdge(createdExternal, true);
12737 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12742 Compiler_Error($"Invalid watched object\n");
12745 curExternal = external;
12746 curContext = context;
12749 FreeExpression(watcher);
12751 FreeExpression(object);
12752 FreeList(watches, FreePropertyWatch);
12755 Compiler_Error($"No observer specified and not inside a class\n");
12759 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12761 ProcessStatement(propWatch.compound);
12767 case fireWatchersStmt:
12769 OldList * watches = stmt._watch.watches;
12770 Expression object = stmt._watch.object;
12772 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12773 // printf("%X\n", watches);
12774 // printf("%X\n", stmt._watch.watches);
12776 ProcessExpressionType(object);
12781 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12787 stmt.type = expressionStmt;
12788 stmt.expressions = MkList();
12790 // Check if we're inside a property set
12791 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12793 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12797 //Compiler_Error($"No property specified and not inside a property set\n");
12801 for(propID = watches->first; propID; propID = propID.next)
12803 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12806 CreateFireWatcher(prop, object, stmt);
12809 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12814 // Fire all properties!
12817 for(base = _class; base; base = base.base)
12819 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12821 if(prop.isProperty && prop.isWatchable)
12823 CreateFireWatcher(prop, object, stmt);
12830 FreeExpression(object);
12831 FreeList(watches, FreeIdentifier);
12834 Compiler_Error($"Invalid object specified and not inside a class\n");
12838 case stopWatchingStmt:
12840 OldList * watches = stmt._watch.watches;
12841 Expression object = stmt._watch.object;
12842 Expression watcher = stmt._watch.watcher;
12845 ProcessExpressionType(object);
12847 ProcessExpressionType(watcher);
12850 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12852 if(watcher || thisClass)
12858 stmt.type = expressionStmt;
12859 stmt.expressions = MkList();
12864 // eInstance_StopWatching(object, null, watcher);
12866 ListAdd(args, CopyExpression(object));
12867 ListAdd(args, MkExpConstant("0"));
12868 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12869 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12873 for(propID = watches->first; propID; propID = propID.next)
12875 char propName[1024];
12876 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12879 char getName[1024], setName[1024];
12880 OldList * args = MkList();
12882 DeclareProperty(curExternal, prop, setName, getName);
12884 // eInstance_StopWatching(object, prop, watcher);
12885 strcpy(propName, "__ecereProp_");
12886 FullClassNameCat(propName, prop._class.fullName, false);
12887 strcat(propName, "_");
12888 FullClassNameCat(propName, prop.name, true);
12890 ListAdd(args, CopyExpression(object));
12891 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12892 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12893 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12896 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12901 FreeExpression(object);
12903 FreeExpression(watcher);
12904 FreeList(watches, FreeIdentifier);
12907 Compiler_Error($"Invalid object specified and not inside a class\n");
12910 Compiler_Error($"No observer specified and not inside a class\n");
12917 static void ProcessFunction(FunctionDefinition function)
12919 Identifier id = GetDeclId(function.declarator);
12920 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12921 Type type = symbol ? symbol.type : null;
12922 Class oldThisClass = thisClass;
12923 Context oldTopContext = topContext;
12925 yylloc = function.loc;
12926 // Process thisClass
12928 if(type && type.thisClass)
12930 Symbol classSym = type.thisClass;
12931 Class _class = type.thisClass.registered;
12932 char className[1024];
12933 char structName[1024];
12934 Declarator funcDecl;
12937 bool typedObject = false;
12939 if(_class && !_class.base)
12941 _class = currentClass;
12942 if(_class && !_class.symbol)
12943 _class.symbol = FindClass(_class.fullName);
12944 classSym = _class ? _class.symbol : null;
12945 typedObject = true;
12948 thisClass = _class;
12950 if(inCompiler && _class)
12952 if(type.kind == functionType)
12954 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12956 //TypeName param = symbol.type.params.first;
12957 Type param = symbol.type.params.first;
12958 symbol.type.params.Remove(param);
12959 //FreeTypeName(param);
12962 if(type.classObjectType != classPointer)
12964 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12965 symbol.type.staticMethod = true;
12966 symbol.type.thisClass = null;
12968 // HIGH DANGER: VERIFYING THIS...
12969 symbol.type.extraParam = false;
12973 strcpy(className, "__ecereClass_");
12974 FullClassNameCat(className, _class.fullName, true);
12977 FullClassNameCat(structName, _class.fullName, false);
12980 funcDecl = GetFuncDecl(function.declarator);
12983 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12985 TypeName param = funcDecl.function.parameters->first;
12986 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12988 funcDecl.function.parameters->Remove(param);
12989 FreeTypeName(param);
12993 if(!function.propertyNoThis)
12995 TypeName thisParam = null;
12997 if(type.classObjectType != classPointer)
12999 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
13000 if(!funcDecl.function.parameters)
13001 funcDecl.function.parameters = MkList();
13002 funcDecl.function.parameters->Insert(null, thisParam);
13007 if(type.classObjectType != classPointer)
13009 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
13010 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
13013 thisParam = TypeName
13015 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
13016 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
13018 DeclareStruct(curExternal, "ecere::com::Class", false, true);
13019 funcDecl.function.parameters->Insert(null, thisParam);
13024 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13026 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13027 funcDecl = GetFuncDecl(initDecl.declarator);
13030 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
13032 TypeName param = funcDecl.function.parameters->first;
13033 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
13035 funcDecl.function.parameters->Remove(param);
13036 FreeTypeName(param);
13040 if(type.classObjectType != classPointer)
13042 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
13044 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
13046 if(!funcDecl.function.parameters)
13047 funcDecl.function.parameters = MkList();
13048 funcDecl.function.parameters->Insert(null, thisParam);
13055 // Add this to the context
13058 if(type.classObjectType != classPointer)
13060 thisSymbol = Symbol
13062 string = CopyString("this");
13063 type = classSym ? MkClassType(classSym.string) : null;
13065 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
13067 if(typedObject && thisSymbol.type)
13069 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
13070 thisSymbol.type.byReference = type.byReference;
13071 thisSymbol.type.typedByReference = type.byReference;
13076 // Pointer to class data
13077 if(inCompiler && _class && _class.type == normalClass && type.classObjectType != classPointer)
13079 DataMember member = null;
13082 for(base = _class; base && base.type != systemClass; base = base.next)
13084 for(member = base.membersAndProperties.first; member; member = member.next)
13085 if(!member.isProperty)
13091 for(member = _class.membersAndProperties.first; member; member = member.next)
13092 if(!member.isProperty)
13096 char pointerName[1024];
13099 Initializer initializer;
13100 Expression exp, bytePtr;
13102 strcpy(pointerName, "__ecerePointer_");
13103 FullClassNameCat(pointerName, _class.fullName, false);
13105 char className[1024];
13106 strcpy(className, "__ecereClass_");
13107 FullClassNameCat(className, classSym.string, true);
13109 DeclareClass(curExternal, classSym, className);
13113 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
13118 if(_class.offset && _class.offset == (_class.base.type == noHeadClass ? _class.base.memberOffset : _class.base.structSize))
13120 e = MkExpClassSize(MkSpecifierName(_class.base.fullName));
13121 ProcessExpressionType(e);
13126 sprintf(string, "%d", _class.offset); // Need Bootstrap Fix
13127 e = MkExpConstant(string);
13129 exp = QBrackets(MkExpOp(bytePtr, '+', e));
13133 // ([bytePtr] + [className]->offset)
13134 exp = QBrackets(MkExpOp(bytePtr, '+',
13135 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
13138 // (this ? [exp] : 0)
13139 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
13143 kind = pointerType;
13144 type = Type { refCount = 1, kind = voidType };
13149 yylloc = function.body.loc;
13150 // ([structName] *) [exp]
13151 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
13152 initializer = MkInitializerAssignment(
13153 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
13155 // [structName] * [pointerName] = [initializer];
13156 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
13159 Context prevContext = curContext;
13161 curContext = function.body.compound.context;
13163 decl = MkDeclaration((list = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null))),
13164 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
13165 list->Insert(null, MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
13167 curContext = prevContext;
13171 decl.symbol = null;
13173 if(!function.body.compound.declarations)
13174 function.body.compound.declarations = MkList();
13175 function.body.compound.declarations->Insert(null, decl);
13181 // Loop through the function and replace undeclared identifiers
13182 // which are a member of the class (methods, properties or data)
13183 // by "this.[member]"
13190 FreeSpecifier(id._class);
13193 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13195 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13196 id = GetDeclId(initDecl.declarator);
13198 FreeSpecifier(id._class);
13203 topContext = function.body.compound.context;
13205 FunctionDefinition oldFunction = curFunction;
13206 curFunction = function;
13208 ProcessStatement(function.body);
13210 // If this is a property set and no firewatchers has been done yet, add one here
13211 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
13213 Statement prevCompound = curCompound;
13214 Context prevContext = curContext;
13216 Statement fireWatchers = MkFireWatchersStmt(null, null);
13217 if(!function.body.compound.statements) function.body.compound.statements = MkList();
13218 ListAdd(function.body.compound.statements, fireWatchers);
13220 curCompound = function.body;
13221 curContext = function.body.compound.context;
13223 ProcessStatement(fireWatchers);
13225 curContext = prevContext;
13226 curCompound = prevCompound;
13230 curFunction = oldFunction;
13233 if(function.declarator)
13235 ProcessDeclarator(function.declarator, true);
13238 topContext = oldTopContext;
13239 thisClass = oldThisClass;
13242 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
13243 static void ProcessClass(OldList definitions, Symbol symbol)
13246 External external = curExternal;
13247 Class regClass = symbol ? symbol.registered : null;
13249 // Process all functions
13250 for(def = definitions.first; def; def = def.next)
13252 if(def.type == functionClassDef)
13254 if(def.function.declarator)
13255 curExternal = def.function.declarator.symbol.pointerExternal;
13257 curExternal = external;
13259 ProcessFunction((FunctionDefinition)def.function);
13261 else if(def.type == declarationClassDef)
13263 if(def.decl.type == instDeclaration)
13265 thisClass = regClass;
13266 ProcessInstantiationType(def.decl.inst);
13272 Class backThisClass = thisClass;
13273 if(regClass) thisClass = regClass;
13274 ProcessDeclaration(def.decl, symbol ? true : false);
13275 thisClass = backThisClass;
13278 else if(def.type == defaultPropertiesClassDef && def.defProperties)
13280 MemberInit defProperty;
13282 // Add this to the context
13283 Symbol thisSymbol = Symbol
13285 string = CopyString("this");
13286 type = regClass ? MkClassType(regClass.fullName) : null;
13288 globalContext.symbols.Add((BTNode)thisSymbol);
13290 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
13292 thisClass = regClass;
13293 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
13297 globalContext.symbols.Remove((BTNode)thisSymbol);
13298 FreeSymbol(thisSymbol);
13300 else if(def.type == propertyClassDef && def.propertyDef)
13302 PropertyDef prop = def.propertyDef;
13304 // Add this to the context
13305 thisClass = regClass;
13312 string = CopyString("this");
13313 type = MkClassType(regClass.fullName);
13315 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13318 curExternal = prop.symbol ? prop.symbol.externalSet : null;
13319 ProcessStatement(prop.setStmt);
13327 string = CopyString("this");
13328 type = MkClassType(regClass.fullName);
13330 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13333 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13334 ProcessStatement(prop.getStmt);
13342 string = CopyString("this");
13343 type = MkClassType(regClass.fullName);
13345 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13348 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13349 ProcessStatement(prop.issetStmt);
13354 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13356 PropertyWatch propertyWatch = def.propertyWatch;
13358 thisClass = regClass;
13359 if(propertyWatch.compound)
13363 string = CopyString("this");
13364 type = regClass ? MkClassType(regClass.fullName) : null;
13367 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13369 curExternal = null;
13370 ProcessStatement(propertyWatch.compound);
13377 void DeclareFunctionUtil(External neededBy, const String s)
13379 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13384 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13385 strcpy(name, "__ecereFunction_");
13386 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13387 DeclareFunction(neededBy, function, name);
13390 FindSymbol(s, globalContext, globalContext, false, false);
13393 bool reachedPass15;
13395 void ComputeDataTypes()
13399 currentClass = null;
13401 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13403 DeclareStruct(null, "ecere::com::Class", false, true);
13404 DeclareStruct(null, "ecere::com::Instance", false, true);
13405 DeclareStruct(null, "ecere::com::Property", false, true);
13406 DeclareStruct(null, "ecere::com::DataMember", false, true);
13407 DeclareStruct(null, "ecere::com::Method", false, true);
13408 DeclareStruct(null, "ecere::com::SerialBuffer", false, true);
13409 DeclareStruct(null, "ecere::com::ClassTemplateArgument", false, true);
13411 DeclareFunctionUtil(null, "eSystem_New");
13412 DeclareFunctionUtil(null, "eSystem_New0");
13413 DeclareFunctionUtil(null, "eSystem_Renew");
13414 DeclareFunctionUtil(null, "eSystem_Renew0");
13415 DeclareFunctionUtil(null, "eSystem_Delete");
13416 DeclareFunctionUtil(null, "eClass_GetProperty");
13417 DeclareFunctionUtil(null, "eClass_SetProperty");
13418 DeclareFunctionUtil(null, "eInstance_FireSelfWatchers");
13419 DeclareFunctionUtil(null, "eInstance_SetMethod");
13420 DeclareFunctionUtil(null, "eInstance_IncRef");
13421 DeclareFunctionUtil(null, "eInstance_StopWatching");
13422 DeclareFunctionUtil(null, "eInstance_Watch");
13423 DeclareFunctionUtil(null, "eInstance_FireWatchers");
13424 reachedPass15 = true;
13426 for(external = ast->first; external; external = external.next)
13428 afterExternal = curExternal = external;
13429 if(external.type == functionExternal)
13433 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13434 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13437 currentClass = external.function._class;
13438 ProcessFunction(external.function);
13440 // There shouldn't be any _class member access here anyways...
13441 else if(external.type == declarationExternal)
13443 if(memoryGuard && external.declaration && external.declaration.type == instDeclaration)
13445 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13446 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13449 currentClass = null;
13450 if(external.declaration)
13451 ProcessDeclaration(external.declaration, true);
13453 else if(external.type == classExternal)
13455 ClassDefinition _class = external._class;
13456 currentClass = external.symbol.registered;
13459 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13460 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13462 if(_class.definitions)
13464 ProcessClass(_class.definitions, _class.symbol);
13468 // Free class data...
13469 ast->Remove(external);
13473 else if(external.type == nameSpaceExternal)
13475 thisNameSpace = external.id.string;
13478 currentClass = null;
13479 thisNameSpace = null;
13480 curExternal = null;