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, null, _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)
1634 type = { refCount = 1 };
1635 CopyTypeInto(type, source);
1636 type.isVector = false;
1638 else if(source.kind == pointerType || source.kind == arrayType)
1641 source.type.refCount++;
1643 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1651 // Support dereferencing of no head classes for now...
1652 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1658 Compiler_Error($"cannot dereference type\n");
1663 static Type Reference(Type source)
1679 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1681 Identifier ident = member.identifiers ? member.identifiers->first : null;
1683 DataMember dataMember = null;
1684 Method method = null;
1685 bool freeType = false;
1687 yylloc = member.loc;
1693 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1697 dataMember = *curMember;
1703 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1704 DataMember _subMemberStack[256];
1705 int _subMemberStackPos = 0;
1707 // FILL MEMBER STACK
1709 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1712 dataMember = thisMember;
1713 if(curMember && thisMember.memberAccess == publicAccess)
1715 *curMember = thisMember;
1716 *curClass = thisMember._class;
1717 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1718 *subMemberStackPos = _subMemberStackPos;
1725 method = eClass_FindMethod(_class, ident.string, privateModule);
1726 if(method && method.type == virtualMethod)
1738 if(!dataMember.dataType && dataMember.dataTypeString)
1740 //Context context = SetupTemplatesContext(dataMember._class);
1741 Context context = SetupTemplatesContext(_class);
1742 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1743 FinishTemplatesContext(context);
1745 type = dataMember.dataType;
1749 // This is for destination type...
1750 if(!method.dataType)
1751 ProcessMethodType(method);
1752 //DeclareMethod(method);
1753 // method.dataType = ((Symbol)method.symbol)->type;
1754 type = method.dataType;
1757 if(ident && ident.next)
1759 for(ident = ident.next; ident && type; ident = ident.next)
1761 if(type.kind == classType)
1763 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1765 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1767 type = dataMember.dataType;
1769 else if(type.kind == structType || type.kind == unionType)
1772 for(memberType = type.members.first; memberType; memberType = memberType.next)
1774 if(!strcmp(memberType.name, ident.string))
1784 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1785 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1788 ClassTemplateParameter curParam = null;
1790 for(sClass = _class; sClass; sClass = sClass.base)
1793 if(sClass.templateClass) sClass = sClass.templateClass;
1794 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1796 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1798 for(sClass = sClass.base; sClass; sClass = sClass.base)
1800 if(sClass.templateClass) sClass = sClass.templateClass;
1801 id += sClass.templateParams.count;
1812 ClassTemplateArgument arg = _class.templateArgs[id];
1813 if(arg.dataTypeString)
1815 bool constant = type.constant;
1817 type = ProcessTypeString(arg.dataTypeString, false);
1818 if(type.kind == classType && constant) type.constant = true;
1819 else if(type.kind == pointerType)
1822 while(t.kind == pointerType) t = t.type;
1823 if(constant) t.constant = constant;
1826 if(type && _class.templateClass)
1827 type.passAsTemplate = true;
1833 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1834 exp.destType.refCount++;
1840 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1842 Class expClass = type._class.registered;
1843 Class cClass = null;
1847 char templateString[1024];
1848 ClassTemplateParameter param;
1849 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1850 for(cClass = expClass; cClass; cClass = cClass.base)
1853 if(cClass.templateClass) cClass = cClass.templateClass;
1854 for(param = cClass.templateParams.first; param; param = param.next)
1858 ClassTemplateArgument arg;
1859 for(sClass = cClass.base; sClass; sClass = sClass.base)
1861 if(sClass.templateClass) sClass = sClass.templateClass;
1862 id += sClass.templateParams.count;
1864 arg = expClass.templateArgs[id];
1866 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1868 ClassTemplateParameter cParam;
1869 //int p = numParams - sClass.templateParams.count;
1872 if(sClass.templateClass) sClass = sClass.templateClass;
1874 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1876 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1877 p += nextClass.templateParams.count;
1880 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1882 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1884 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1886 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1887 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1899 strcat(argument, arg.name.string);
1900 strcat(argument, " = ");
1906 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1907 char expString[1024];
1908 OldList * specs = MkList();
1909 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1911 char * string = PrintHexUInt64(arg.expression.ui64);
1912 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1915 ProcessExpressionType(exp);
1916 ComputeExpression(exp);
1917 expString[0] = '\0';
1918 PrintExpression(exp, expString);
1919 strcat(argument, expString);
1921 FreeExpression(exp);
1926 strcat(argument, arg.member.name);
1929 case TemplateParameterType::type:
1931 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1932 strcat(argument, arg.dataTypeString);
1938 if(paramCount) strcat(templateString, ", ");
1939 if(lastParam != p - 1)
1941 strcat(templateString, param.name);
1942 strcat(templateString, " = ");
1944 strcat(templateString, argument);
1953 int len = strlen(templateString);
1954 if(templateString[len-1] == '<')
1958 if(templateString[len-1] == '>')
1959 templateString[len++] = ' ';
1960 templateString[len++] = '>';
1962 templateString[len++] = '\0';
1965 Context context = SetupTemplatesContext(_class);
1966 if(freeType) FreeType(type);
1967 type = ProcessTypeString(templateString, false);
1969 FinishTemplatesContext(context);
1973 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1975 ProcessExpressionType(member.initializer.exp);
1976 if(!member.initializer.exp.expType)
1980 char expString[10240];
1981 expString[0] = '\0';
1982 PrintExpression(member.initializer.exp, expString);
1983 ChangeCh(expString, '\n', ' ');
1984 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1987 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1988 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
1990 Compiler_Error($"incompatible instance method %s\n", ident.string);
1993 else if(member.initializer)
1996 FreeType(member.exp.destType);
1997 member.exp.destType = type;
1998 if(member.exp.destType)
1999 member.exp.destType.refCount++;
2000 ProcessExpressionType(member.exp);
2003 ProcessInitializer(member.initializer, type);
2005 if(freeType) FreeType(type);
2009 if(_class && _class.type == unitClass)
2011 if(member.initializer)
2014 FreeType(member.exp.destType);
2015 member.exp.destType = MkClassType(_class.fullName);
2016 ProcessExpressionType(member.initializer, type);
2018 Type type = MkClassType(_class.fullName);
2019 ProcessInitializer(member.initializer, type);
2025 if(member.initializer)
2027 //ProcessExpressionType(member.exp);
2028 ProcessInitializer(member.initializer, null);
2034 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
2038 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
2040 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
2044 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
2049 void ProcessInstantiationType(Instantiation inst)
2054 MembersInit members;
2058 classSym = inst._class.symbol;
2059 _class = classSym ? classSym.registered : null;
2061 if(!_class || _class.type != noHeadClass)
2062 DeclareStruct(curExternal, inst._class.name, false, true);
2064 afterExternal = afterExternal ? afterExternal : curExternal;
2067 ProcessExpressionType(inst.exp);
2069 inst.isConstant = true;
2072 DataMember curMember = null;
2073 Class curClass = null;
2074 DataMember subMemberStack[256];
2075 int subMemberStackPos = 0;
2077 for(members = inst.members->first; members; members = members.next)
2079 switch(members.type)
2081 case methodMembersInit:
2084 static uint instMethodID = 0;
2085 External external = curExternal;
2086 Context context = curContext;
2087 Declarator declarator = members.function.declarator;
2088 Identifier nameID = GetDeclId(declarator);
2089 char * unmangled = nameID ? nameID.string : null;
2091 External createdExternal = null;
2096 strcpy(name, "__ecereInstMeth_");
2097 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2099 strcat(name, nameID.string);
2101 sprintf(number, "_%08d", instMethodID++);
2102 strcat(name, number);
2103 nameID.string = CopyString(name);
2106 // Do modifications here...
2109 Symbol symbol = declarator.symbol;
2110 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2112 if(method && method.type == virtualMethod)
2114 symbol.method = method;
2115 ProcessMethodType(method);
2117 if(!symbol.type.thisClass)
2119 if(method.dataType.thisClass && currentClass &&
2120 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2122 if(!currentClass.symbol)
2123 currentClass.symbol = FindClass(currentClass.fullName);
2124 symbol.type.thisClass = currentClass.symbol;
2129 _class.symbol = FindClass(_class.fullName);
2130 symbol.type.thisClass = _class.symbol;
2133 DeclareType(curExternal, symbol.type, true, true);
2138 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2139 unmangled, classSym.string);
2143 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2147 FreeSpecifier(nameID._class);
2148 nameID._class = null;
2151 curExternal = createdExternal;
2154 if(createdExternal.function)
2155 ProcessFunction(createdExternal.function);
2159 curExternal = declarator.symbol.pointerExternal;
2160 ProcessFunction((FunctionDefinition)members.function);
2162 curExternal = external;
2163 curContext = context;
2167 FreeClassFunction(members.function);
2169 // In this pass, turn this into a MemberInitData
2170 exp = QMkExpId(name);
2171 members.type = dataMembersInit;
2172 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2178 case dataMembersInit:
2180 if(members.dataMembers && classSym)
2183 Location oldyyloc = yylloc;
2184 for(member = members.dataMembers->first; member; member = member.next)
2186 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2187 if(member.initializer && !member.initializer.isConstant)
2188 inst.isConstant = false;
2200 void DeclareType(External neededFor, Type type, bool needDereference, bool forFunctionDef)
2202 _DeclareType(neededFor, type, needDereference, forFunctionDef, false);
2205 void DeclareTypeForwardDeclare(External neededFor, Type type, bool needDereference, bool forFunctionDef)
2207 _DeclareType(neededFor, type, needDereference, forFunctionDef, true);
2210 static void _DeclareType(External neededFor, Type type, bool needDereference, bool forFunctionDef, bool fwdDecl)
2214 if(type.kind == functionType)
2217 for(param = type.params.first; param; param = param.next)
2218 _DeclareType(neededFor, param, forFunctionDef, false, fwdDecl);
2219 _DeclareType(neededFor, type.returnType, forFunctionDef, false, fwdDecl);
2221 else if(type.kind == pointerType)
2222 _DeclareType(neededFor, type.type, false, false, fwdDecl);
2223 else if(type.kind == classType)
2225 Class c = type._class ? type._class.registered : null;
2226 _DeclareStruct(neededFor, c ? c.fullName : "ecere::com::Instance", c ? c.type == noHeadClass : false, needDereference && c && c.type == structClass, fwdDecl);
2228 else if(type.kind == structType || type.kind == unionType)
2231 for(member = type.members.first; member; member = member.next)
2232 _DeclareType(neededFor, member, needDereference, forFunctionDef, fwdDecl);
2234 else if(type.kind == arrayType)
2235 _DeclareType(neededFor, type.arrayType, true, false, fwdDecl);
2239 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2241 ClassTemplateArgument * arg = null;
2243 ClassTemplateParameter curParam = null;
2245 for(sClass = _class; sClass; sClass = sClass.base)
2248 if(sClass.templateClass) sClass = sClass.templateClass;
2249 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2251 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2253 for(sClass = sClass.base; sClass; sClass = sClass.base)
2255 if(sClass.templateClass) sClass = sClass.templateClass;
2256 id += sClass.templateParams.count;
2266 arg = &_class.templateArgs[id];
2267 if(arg && param.type == type)
2268 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2273 public Context SetupTemplatesContext(Class _class)
2275 Context context = PushContext();
2276 context.templateTypesOnly = true;
2277 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2279 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2280 for(; param; param = param.next)
2282 if(param.type == type && param.identifier)
2284 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2285 curContext.templateTypes.Add((BTNode)type);
2292 for(sClass = _class; sClass; sClass = sClass.base)
2294 ClassTemplateParameter p;
2295 for(p = sClass.templateParams.first; p; p = p.next)
2297 //OldList * specs = MkList();
2298 //Declarator decl = null;
2299 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2302 TemplateParameter param = p.param;
2306 // ADD DATA TYPE HERE...
2307 p.param = param = TemplateParameter
2309 identifier = MkIdentifier(p.name), type = p.type,
2310 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2313 type = TemplatedType { key = (uintptr)p.name, param = param };
2314 curContext.templateTypes.Add((BTNode)type);
2322 public void FinishTemplatesContext(Context context)
2324 PopContext(context);
2325 FreeContext(context);
2329 public void ProcessMethodType(Method method)
2331 if(!method.dataType)
2333 Context context = SetupTemplatesContext(method._class);
2335 method.dataType = ProcessTypeString(method.dataTypeString, false);
2337 FinishTemplatesContext(context);
2339 if(method.type != virtualMethod && method.dataType)
2341 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2343 if(!method._class.symbol)
2344 method._class.symbol = FindClass(method._class.fullName);
2345 method.dataType.thisClass = method._class.symbol;
2349 // Why was this commented out? Working fine without now...
2352 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2353 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2360 char * par = strstr(type, "(");
2361 char * classOp = null;
2366 for(c = par-type-1; c >= 0; c++)
2368 if(type[c] == ':' && type[c+1] == ':')
2370 classOp = type + c - 1;
2371 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2378 else if(!isspace(type[c]))
2385 int typeLen = strlen(type);
2386 memcpy(temp, classOp, classOpLen);
2387 temp[classOpLen] = '\0';
2389 _class = eSystem_FindClass(module, temp);
2392 method.dataTypeString = new char[typeLen - classOpLen + 1];
2393 memcpy(method.dataTypeString, type, classOp - type);
2394 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2397 method.dataTypeString = type;
2403 public void ProcessPropertyType(Property prop)
2407 Context context = SetupTemplatesContext(prop._class);
2408 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2409 FinishTemplatesContext(context);
2413 public void DeclareMethod(External neededFor, Method method, const char * name)
2415 Symbol symbol = method.symbol;
2416 if(!symbol || (!symbol.pointerExternal && (!symbol.methodCodeExternal || method.type == virtualMethod)))
2418 bool dllImport = false;
2420 if(!method.dataType)
2421 method.dataType = ProcessTypeString(method.dataTypeString, false);
2423 //if(!symbol || symbol._import || method.type == virtualMethod)
2425 if(!symbol || method.type == virtualMethod)
2428 if(!method._class.symbol)
2429 method._class.symbol = FindClass(method._class.fullName);
2430 classSym = method._class.symbol;
2431 if(!classSym._import)
2433 ModuleImport module;
2435 if(method._class.module && method._class.module.name)
2436 module = FindModule(method._class.module);
2438 module = mainModule;
2439 classSym._import = ClassImport
2441 name = CopyString(method._class.fullName);
2442 isRemote = method._class.isRemote;
2444 module.classes.Add(classSym._import);
2448 symbol = method.symbol = Symbol { };
2452 symbol._import = (ClassImport)MethodImport
2454 name = CopyString(method.name);
2455 isVirtual = method.type == virtualMethod;
2457 classSym._import.methods.Add(symbol._import);
2461 symbol.type = method.dataType;
2462 if(symbol.type) symbol.type.refCount++;
2465 if(!method.dataType.dllExport)
2467 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2474 // We need a declaration here :)
2476 OldList * specifiers, * declarators;
2478 Declarator funcDecl;
2481 specifiers = MkList();
2482 declarators = MkList();
2485 ListAdd(specifiers, MkSpecifier(EXTERN));
2486 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2487 ListAdd(specifiers, MkSpecifier(STATIC));
2489 if(method.type == virtualMethod)
2491 ListAdd(specifiers, MkSpecifier(INT));
2492 d = MkDeclaratorIdentifier(MkIdentifier(name));
2496 d = MkDeclaratorIdentifier(MkIdentifier(name));
2498 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2500 Context context = SetupTemplatesContext(method._class);
2501 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2502 FinishTemplatesContext(context);
2504 funcDecl = GetFuncDecl(d);
2508 Specifier spec, next;
2509 for(spec = specifiers->first; spec; spec = next)
2512 if(spec.type == extendedSpecifier)
2514 specifiers->Remove(spec);
2515 FreeSpecifier(spec);
2520 // Add this parameter if not a static method
2521 if(method.dataType && !method.dataType.staticMethod)
2523 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2525 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2526 TypeName thisParam = MkTypeName(MkListOne(
2527 MkSpecifierName(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2528 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2529 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2530 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2532 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2534 TypeName param = funcDecl.function.parameters->first;
2535 funcDecl.function.parameters->Remove(param);
2536 FreeTypeName(param);
2539 if(!funcDecl.function.parameters)
2540 funcDecl.function.parameters = MkList();
2541 funcDecl.function.parameters->Insert(null, thisParam);
2545 ProcessDeclarator(d, true);
2547 ListAdd(declarators, MkInitDeclarator(d, null));
2549 decl = MkDeclaration(specifiers, declarators);
2551 ReplaceThisClassSpecifiers(specifiers, method._class);
2553 external = MkExternalDeclaration(decl);
2554 external.symbol = symbol;
2555 symbol.pointerExternal = external;
2557 DeclareStruct(external, method._class.fullName, true, true);
2559 DeclareType(external, method.dataType, true, true);
2562 if(inCompiler && neededFor)
2564 External external = symbol.pointerExternal ? symbol.pointerExternal : symbol.methodCodeExternal;
2565 neededFor.CreateUniqueEdge(external, external.type == functionExternal);
2569 char * ReplaceThisClass(Class _class)
2571 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2575 ClassTemplateParameter param;
2578 char className[1024];
2579 strcpy(className, _class.fullName);
2580 for(param = _class.templateParams.first; param; param = param.next)
2582 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2584 if(first) strcat(className, "<");
2585 if(!first) strcat(className, ", ");
2586 if(lastParam + 1 != p)
2588 strcat(className, param.name);
2589 strcat(className, " = ");
2591 strcat(className, param.name);
2599 int len = strlen(className);
2600 if(className[len-1] == '>') className[len++] = ' ';
2601 className[len++] = '>';
2602 className[len++] = '\0';
2604 return CopyString(className);
2607 return CopyString(_class.fullName);
2610 Type ReplaceThisClassType(Class _class)
2613 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2617 ClassTemplateParameter param;
2619 char className[1024];
2620 strcpy(className, _class.fullName);
2622 for(param = _class.templateParams.first; param; param = param.next)
2624 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2626 if(first) strcat(className, "<");
2627 if(!first) strcat(className, ", ");
2628 if(lastParam + 1 != p)
2630 strcat(className, param.name);
2631 strcat(className, " = ");
2633 strcat(className, param.name);
2641 int len = strlen(className);
2642 if(className[len-1] == '>') className[len++] = ' ';
2643 className[len++] = '>';
2644 className[len++] = '\0';
2646 type = MkClassType(className);
2647 //type = ProcessTypeString(className, false);
2651 type = MkClassType(_class.fullName);
2652 //type = ProcessTypeString(_class.fullName, false);
2654 //type.wasThisClass = true;
2658 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2660 if(specs != null && _class)
2663 for(spec = specs.first; spec; spec = spec.next)
2665 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2667 spec.type = nameSpecifier;
2668 spec.name = ReplaceThisClass(_class);
2669 spec.symbol = FindClass(spec.name); //_class.symbol;
2675 // Returns imported or not
2676 bool DeclareFunction(External neededFor, GlobalFunction function, char * name)
2678 Symbol symbol = function.symbol;
2679 // TOCHECK: Might get rid of the pointerExternal check in favor of marking the edge as breakable
2680 if(!symbol || !symbol.pointerExternal)
2682 bool imported = false;
2683 bool dllImport = false;
2685 if(!function.dataType)
2687 function.dataType = ProcessTypeString(function.dataTypeString, false);
2688 if(!function.dataType.thisClass)
2689 function.dataType.staticMethod = true;
2696 ModuleImport module = FindModule(function.module);
2697 // WARNING: This is not added anywhere...
2698 symbol = function.symbol = Symbol { };
2702 if(!function.dataType.dllExport)
2704 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2705 module.functions.Add(symbol._import);
2708 // Set the symbol type
2710 symbol.type = ProcessTypeString(function.dataTypeString, false);
2711 if(!symbol.type.thisClass)
2712 symbol.type.staticMethod = true;
2715 imported = symbol._import ? true : false;
2716 if(imported && function.module != privateModule && function.module.importType != staticImport)
2722 // TOCHECK: What's with the functionExternal check here? Is it Edge breaking / forward declaration?
2723 //if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2725 // We need a declaration here :)
2727 OldList * specifiers, * declarators;
2729 Declarator funcDecl;
2732 specifiers = MkList();
2733 declarators = MkList();
2735 ListAdd(specifiers, MkSpecifier(EXTERN));
2737 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2739 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2741 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2742 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2743 if(function.module.importType == staticImport)
2746 for(spec = specifiers->first; spec; spec = spec.next)
2747 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2749 specifiers->Remove(spec);
2750 FreeSpecifier(spec);
2755 funcDecl = GetFuncDecl(d);
2757 // Make sure we don't have empty parameter declarations for static methods...
2758 if(funcDecl && !funcDecl.function.parameters)
2760 funcDecl.function.parameters = MkList();
2761 funcDecl.function.parameters->Insert(null,
2762 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2765 ListAdd(declarators, MkInitDeclarator(d, null));
2768 Context oldCtx = curContext;
2769 curContext = globalContext;
2770 decl = MkDeclaration(specifiers, declarators);
2771 curContext = oldCtx;
2774 // Keep a different symbol for the function definition than the declaration...
2775 /* Note: This should be handled by the edge breaking...
2776 if(symbol.pointerExternal && symbol.pointerExternal.type == functionExternal)
2778 Symbol functionSymbol { };
2781 *functionSymbol = *symbol;
2782 functionSymbol.string = CopyString(symbol.string);
2783 if(functionSymbol.type)
2784 functionSymbol.type.refCount++;
2787 excludedSymbols->Add(functionSymbol);
2789 symbol.pointerExternal.symbol = functionSymbol;
2792 external = MkExternalDeclaration(decl);
2794 external.symbol = symbol;
2795 symbol.pointerExternal = external;
2797 DeclareType(external, function.dataType, true, true);
2801 if(inCompiler && neededFor && symbol && symbol.pointerExternal)
2802 neededFor.CreateUniqueEdge(symbol.pointerExternal, symbol.pointerExternal.type == functionExternal);
2803 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2806 void DeclareGlobalData(External neededFor, GlobalData data)
2808 Symbol symbol = data.symbol;
2809 // TOCHECK: Might get rid of the pointerExternal check in favor of marking the edge as breakable
2810 if(!symbol || !symbol.pointerExternal)
2815 symbol = data.symbol = Symbol { };
2818 data.dataType = ProcessTypeString(data.dataTypeString, false);
2822 // We need a declaration here :)
2824 OldList * specifiers, * declarators;
2828 specifiers = MkList();
2829 declarators = MkList();
2831 ListAdd(specifiers, MkSpecifier(EXTERN));
2832 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2833 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2835 ListAdd(declarators, MkInitDeclarator(d, null));
2837 decl = MkDeclaration(specifiers, declarators);
2838 external = MkExternalDeclaration(decl);
2840 ast->Insert(curExternal.prev, external);
2841 external.symbol = symbol;
2842 symbol.pointerExternal = external;
2844 DeclareType(external, data.dataType, true, true);
2847 if(inCompiler && neededFor && symbol && symbol.pointerExternal)
2848 neededFor.CreateUniqueEdge(symbol.pointerExternal, false);
2851 class Conversion : struct
2853 Conversion prev, next;
2859 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
2862 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
2863 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
2865 Class sourceClass = source.kind == classType ? source._class.registered : null;
2866 Class destClass = dest.kind == classType ? dest._class.registered : null;
2867 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
2868 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
2870 Type sourceType = source, destType = dest;
2871 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
2872 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
2873 if(!destType.constant && sourceType.constant)
2877 Compiler_Warning($"discarding const qualifier\n");
2884 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
2885 bool isConversionExploration, bool warnConst)
2890 CheckConstCompatibility(source, dest, true);
2891 // Property convert;
2893 if(source.kind == templateType && dest.kind != templateType)
2895 Type type = ProcessTemplateParameterType(source.templateParameter);
2896 if(type) source = type;
2899 if(dest.kind == templateType && source.kind != templateType)
2901 Type type = ProcessTemplateParameterType(dest.templateParameter);
2902 if(type) dest = type;
2905 if(dest.classObjectType == typedObject && dest.kind != functionType)
2907 if(source.classObjectType != anyObject)
2911 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2912 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2920 if(source.kind != functionType && source.classObjectType == anyObject)
2922 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
2926 if((dest.kind == structType && source.kind == structType) ||
2927 (dest.kind == unionType && source.kind == unionType))
2929 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2930 (source.members.first && source.members.first == dest.members.first))
2934 if(dest.kind == ellipsisType && source.kind != voidType)
2937 if(dest.kind == pointerType && dest.type.kind == voidType &&
2938 ((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))
2939 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2941 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2943 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2945 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2946 ((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))
2947 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2948 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2950 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2953 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2955 if(source._class.registered && source._class.registered.type == unitClass)
2957 if(conversions != null)
2959 if(source._class.registered == dest._class.registered)
2964 Class sourceBase, destBase;
2965 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2966 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2967 if(sourceBase == destBase)
2971 // Don't match enum inheriting from other enum if resolving enumeration values
2972 // TESTING: !dest.classObjectType
2973 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2975 (!source._class.registered || source._class.registered.type != enumClass) ||
2976 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2980 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2981 if(dest._class && dest._class.registered && source._class && source._class.registered &&
2982 (dest.casted || (enumBaseType && dest._class.registered.type == enumClass &&
2983 (source.kind == classType || // Added this here for a base enum to be acceptable for a derived enum (#139)
2984 source._class.registered.type != enumClass)
2987 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2995 // JUST ADDED THIS...
2996 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3001 // Just added this for Straight conversion of ColorAlpha => Color
3002 if(source.kind == classType)
3005 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3008 for(convert = _class.conversions.first; convert; convert = convert.next)
3010 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3012 Conversion after = (conversions != null) ? conversions.last : null;
3014 if(!convert.dataType)
3015 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3016 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3017 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3018 MatchTypes(convert.dataType, dest, conversions, null, null,
3019 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3020 convert.dataType.kind == classType, false, true, warnConst))
3022 if(!conversions && !convert.Get)
3024 else if(conversions != null)
3026 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3027 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3028 (dest.kind != classType || dest._class.registered != _class.base))
3032 Conversion conv { convert = convert, isGet = true };
3033 // conversions.Add(conv);
3034 conversions.Insert(after, conv);
3047 if(dest.kind == classType)
3050 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3053 for(convert = _class.conversions.first; convert; convert = convert.next)
3055 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3057 Type constType = null;
3058 bool success = false;
3059 // Conversion after = (conversions != null) ? conversions.last : null;
3061 if(!convert.dataType)
3062 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3064 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3067 constType = { kind = pointerType, refCount = 1, type = ptrType };
3068 CopyTypeInto(ptrType, convert.dataType.type);
3069 ptrType.constant = true;
3072 // Just added this equality check to prevent recursion.... Make it safer?
3073 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3074 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3076 if(!conversions && !convert.Set)
3078 else if(conversions != null)
3080 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3081 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3082 (source.kind != classType || source._class.registered != _class.base))
3086 // *** Testing this! ***
3087 Conversion conv { convert = convert };
3088 conversions.Add(conv);
3089 //conversions.Insert(after, conv);
3095 FreeType(constType);
3101 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3103 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3104 (source.kind != classType || source._class.registered.type != structClass))
3108 // TESTING THIS... IS THIS OK??
3109 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3111 if(!dest._class.registered.dataType)
3112 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3113 // Only support this for classes...
3114 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3115 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3117 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3126 if(source.kind == classType)
3129 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3132 for(convert = _class.conversions.first; convert; convert = convert.next)
3134 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3136 Conversion after = (conversions != null) ? conversions.last : null;
3138 if(!convert.dataType)
3139 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3140 if(convert.dataType != source &&
3141 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3142 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3144 if(!conversions && !convert.Get)
3146 else if(conversions != null)
3148 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3149 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3150 (dest.kind != classType || dest._class.registered != _class.base))
3154 Conversion conv { convert = convert, isGet = true };
3156 // conversions.Add(conv);
3157 conversions.Insert(after, conv);
3166 // TESTING THIS... IS THIS OK??
3167 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3169 if(!source._class.registered.dataType)
3170 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3171 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3173 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))
3175 // For bool to be accepted by byte, short, etc.
3176 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3183 if(source.kind == classType || source.kind == subClassType)
3185 else if(dest.kind == source.kind &&
3186 (dest.kind != structType && dest.kind != unionType &&
3187 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3189 // RECENTLY ADDED THESE
3190 else if(dest.kind == doubleType && source.kind == floatType)
3192 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3194 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3196 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3198 else if(dest.kind == int128Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == int64Type || source.kind == intSizeType))
3200 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3202 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3204 else if(source.kind == enumType &&
3205 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3207 else if(dest.kind == enumType && !isConversionExploration &&
3208 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3210 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3211 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3213 Type paramSource, paramDest;
3215 if(dest.kind == methodType)
3216 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3217 if(source.kind == methodType)
3218 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3220 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3221 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3222 if(dest.kind == methodType)
3223 dest = dest.method.dataType;
3224 if(source.kind == methodType)
3225 source = source.method.dataType;
3227 paramSource = source.params.first;
3228 if(paramSource && paramSource.kind == voidType) paramSource = null;
3229 paramDest = dest.params.first;
3230 if(paramDest && paramDest.kind == voidType) paramDest = null;
3233 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3234 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3236 // Source thisClass must be derived from destination thisClass
3237 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3238 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3240 if(paramDest && paramDest.kind == classType)
3241 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3243 Compiler_Error($"method class should not take an object\n");
3246 paramDest = paramDest.next;
3248 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3250 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3254 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3256 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3262 // THIS WAS BACKWARDS:
3263 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3264 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3267 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3269 Compiler_Error($"overriding class expected to be derived from method class\n");
3273 paramSource = paramSource.next;
3279 // Source thisClass must be derived from destination thisClass
3280 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3282 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3288 // THIS WAS BACKWARDS TOO??
3289 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3290 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3293 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3295 //Compiler_Error($"overriding class expected to be derived from method class\n");
3303 // Source return type must be derived from destination return type
3304 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3306 Compiler_Warning($"incompatible return type for function\n");
3309 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3311 CheckConstCompatibility(dest.returnType, source.returnType, true);
3315 for(; paramDest; paramDest = paramDest.next)
3319 //Compiler_Warning($"not enough parameters\n");
3320 Compiler_Error($"not enough parameters\n");
3324 Type paramDestType = paramDest;
3325 Type paramSourceType = paramSource;
3326 Type type = paramDestType;
3328 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3329 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3330 paramSource.kind != templateType)
3333 ClassTemplateParameter curParam = null;
3335 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3338 if(sClass.templateClass) sClass = sClass.templateClass;
3339 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3341 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3343 for(sClass = sClass.base; sClass; sClass = sClass.base)
3345 if(sClass.templateClass) sClass = sClass.templateClass;
3346 id += sClass.templateParams.count;
3357 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3358 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3362 // paramDest must be derived from paramSource
3363 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3364 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3368 PrintType(paramDest, type, false, true);
3369 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3371 if(paramDestType != paramDest)
3372 FreeType(paramDestType);
3375 if(paramDestType != paramDest)
3376 FreeType(paramDestType);
3379 paramSource = paramSource.next;
3383 Compiler_Error($"too many parameters\n");
3388 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3392 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3393 (source.kind == arrayType || source.kind == pointerType))
3395 // Pointers to pointer is incompatible with non normal/nohead classes
3396 if(!(dest.type && dest.type.kind == pointerType && source.type.kind == classType && source.type._class &&
3397 source.type._class.registered && (source.type._class.registered.type != normalClass && source.type._class.registered.type != noHeadClass) && !source.type.byReference))
3399 ComputeTypeSize(source.type);
3400 ComputeTypeSize(dest.type);
3401 if(source.type.size == dest.type.size && MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3409 static void FreeConvert(Conversion convert)
3411 if(convert.resultType)
3412 FreeType(convert.resultType);
3415 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3416 char * string, OldList conversions)
3420 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3422 Class _class = link.data;
3423 if(_class.type == enumClass)
3425 OldList converts { };
3427 type.kind = classType;
3430 _class.symbol = FindClass(_class.fullName);
3431 type._class = _class.symbol;
3433 if(MatchTypes(type, dest, &converts, null, null, dest.kind != classType || !dest._class || strcmp(dest._class.string, "bool"),
3434 false, false, false, false))
3437 Class enumClass = eSystem_FindClass(privateModule, "enum");
3441 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3443 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3444 for(value = e.values.first; value; value = value.next)
3446 if(!strcmp(value.name, string))
3451 FreeType(sourceExp.expType);
3453 sourceExp.isConstant = true;
3454 sourceExp.expType = MkClassType(baseClass.fullName);
3455 if(inCompiler || inPreCompiler || inDebugger)
3458 FreeExpContents(sourceExp);
3460 sourceExp.type = constantExp;
3461 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "short") || !strcmp(baseClass.dataTypeString, "char"))
3462 sprintf(constant, FORMAT64D, value.data);
3464 sprintf(constant, FORMAT64HEXLL, value.data);
3465 sourceExp.constant = CopyString(constant);
3466 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3469 while(converts.first)
3471 Conversion convert = converts.first;
3472 converts.Remove(convert);
3473 conversions.Add(convert);
3482 converts.Free(FreeConvert);
3486 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3487 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3492 public bool ModuleVisibility(Module searchIn, Module searchFor)
3494 SubModule subModule;
3496 if(searchFor == searchIn)
3499 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3501 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3503 if(ModuleVisibility(subModule.module, searchFor))
3510 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3514 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3516 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3518 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3521 for(module = mainModule.application.allModules.first; module; module = module.next)
3523 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3529 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3532 Type realDest = dest;
3533 Type backupSourceExpType = null;
3534 Expression nbExp = GetNonBracketsExp(sourceExp);
3535 Expression computedExp = nbExp;
3538 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3539 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3541 computedExp = CopyExpression(nbExp); // Keep the original expression, but compute for checking enum ranges
3542 ComputeExpression(computedExp /*sourceExp*/);
3545 source = sourceExp.expType;
3547 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3549 if(computedExp != nbExp)
3551 FreeExpression(computedExp);
3552 computedExp = nbExp;
3558 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3560 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3562 Class sourceBase, destBase;
3563 for(sourceBase = source._class.registered;
3564 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3565 sourceBase = sourceBase.base);
3566 for(destBase = dest._class.registered;
3567 destBase && destBase.base && destBase.base.type != systemClass;
3568 destBase = destBase.base);
3569 //if(source._class.registered == dest._class.registered)
3570 if(sourceBase == destBase)
3572 if(computedExp != nbExp)
3574 FreeExpression(computedExp);
3575 computedExp = nbExp;
3587 int64 value = MAXINT;
3591 if(computedExp.type == constantExp)
3594 value = strtoll(computedExp.constant, null, 0);
3596 value = strtoull(computedExp.constant, null, 0);
3598 else if(computedExp.type == opExp && computedExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3601 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3603 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3605 if(computedExp != nbExp)
3607 FreeExpression(computedExp);
3608 computedExp = nbExp;
3611 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3612 !strcmp(source._class.registered.fullName, "unichar" /*"ecere::com::unichar"*/))
3615 source = Type { kind = intType, isSigned = false, refCount = 1 };
3618 if(dest.kind == classType)
3620 Class _class = dest._class ? dest._class.registered : null;
3622 if(_class && _class.type == unitClass)
3624 if(source.kind != classType)
3627 Type tempDest, tempSource;
3629 for(; _class.base.type != systemClass; _class = _class.base);
3631 tempDest = tempType;
3633 tempType.kind = classType;
3635 _class.symbol = FindClass(_class.fullName);
3637 tempType._class = _class.symbol;
3638 tempType.truth = dest.truth;
3640 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3642 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3643 backupSourceExpType = sourceExp.expType;
3644 if(dest.passAsTemplate)
3646 // Don't carry passAsTemplate
3647 sourceExp.expType = { };
3648 CopyTypeInto(sourceExp.expType, dest);
3649 sourceExp.expType.passAsTemplate = false;
3653 sourceExp.expType = dest;
3656 //sourceExp.expType = MkClassType(_class.fullName);
3664 // Why wasn't there something like this?
3665 if(_class && _class.type == bitClass && source.kind != classType)
3667 if(!dest._class.registered.dataType)
3668 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3669 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3672 FreeType(sourceExp.expType);
3673 source = sourceExp.expType = MkClassType(dest._class.string);
3676 //source.kind = classType;
3677 //source._class = dest._class;
3681 // Adding two enumerations
3683 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3685 if(!source._class.registered.dataType)
3686 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3687 if(!dest._class.registered.dataType)
3688 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3690 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3693 source = sourceExp.expType = MkClassType(dest._class.string);
3696 //source.kind = classType;
3697 //source._class = dest._class;
3701 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3703 OldList * specs = MkList();
3707 ReadString(string, sourceExp.string);
3708 decl = SpecDeclFromString(string, specs, null);
3710 FreeExpContents(sourceExp);
3711 FreeType(sourceExp.expType);
3713 sourceExp.type = classExp;
3714 sourceExp._classExp.specifiers = specs;
3715 sourceExp._classExp.decl = decl;
3716 sourceExp.expType = dest;
3721 if(backupSourceExpType) FreeType(backupSourceExpType);
3725 else if(source.kind == classType)
3727 Class _class = source._class ? source._class.registered : null;
3729 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || _class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3732 if(dest.kind != classType)
3734 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3735 if(!source._class.registered.dataType)
3736 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3739 dest = MkClassType(source._class.string);
3740 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3741 // dest = MkClassType(source._class.string);
3745 if(dest.kind != classType)
3748 Type tempDest, tempSource;
3750 if(!source._class.registered.dataType)
3751 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3753 for(; _class.base.type != systemClass; _class = _class.base);
3755 tempSource = tempType;
3756 tempType.kind = classType;
3757 tempType._class = FindClass(_class.fullName);
3758 tempType.truth = source.truth;
3759 tempType.classObjectType = source.classObjectType;
3762 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3764 // PUT THIS BACK TESTING UNITS?
3765 if(conversions && conversions.last)
3767 ((Conversion)(conversions.last)).resultType = dest;
3770 // This fixes passing unit as template to a double
3771 modifyPassAsTemplate(&((Conversion)(conversions.last)).resultType, false);
3774 FreeType(sourceExp.expType);
3775 sourceExp.expType = MkClassType(_class.fullName);
3776 sourceExp.expType.truth = source.truth;
3777 sourceExp.expType.classObjectType = source.classObjectType;
3779 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3781 if(!sourceExp.destType)
3783 FreeType(sourceExp.destType);
3784 sourceExp.destType = sourceExp.expType;
3785 if(sourceExp.expType)
3786 sourceExp.expType.refCount++;
3789 //source = _class.dataType;
3792 // TOCHECK: TESTING THIS NEW CODE
3793 if(!_class.dataType)
3794 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3796 dest = MkClassType(source._class.string);
3797 dest.truth = source.truth;
3798 dest.classObjectType = source.classObjectType;
3801 source = _class.dataType;
3811 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3821 if(source.kind == classType)
3823 Class _class = source._class.registered;
3824 if(_class.type == unitClass)
3826 if(!_class.dataType)
3827 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3828 source = _class.dataType;
3832 if(dest.kind == classType)
3834 Class _class = dest._class ? dest._class.registered : null;
3835 bool fittingValue = false;
3836 if(_class && _class.type == enumClass)
3838 Class enumClass = eSystem_FindClass(privateModule, "enum");
3839 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3840 if(c && value >= 0 && value <= c.largest)
3841 fittingValue = true;
3844 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3845 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3847 if(_class.type == normalClass || _class.type == noHeadClass)
3849 Expression newExp { };
3850 *newExp = *sourceExp;
3851 if(sourceExp.destType) sourceExp.destType.refCount++;
3852 if(sourceExp.expType) sourceExp.expType.refCount++;
3853 sourceExp.type = castExp;
3854 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3855 sourceExp.cast.exp = newExp;
3856 FreeType(sourceExp.expType);
3857 sourceExp.expType = null;
3858 ProcessExpressionType(sourceExp);
3860 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3863 FreeType(sourceExp.expType);
3864 sourceExp.expType = dest;
3868 if(inCompiler) FreeType(dest);
3870 if(backupSourceExpType) FreeType(backupSourceExpType);
3874 if(!_class.dataType)
3875 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3877 dest = _class.dataType;
3881 // Accept lower precision types for units, since we want to keep the unit type
3882 if(dest.kind == doubleType &&
3883 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3884 source.kind == charType || source.kind == _BoolType))
3886 specs = MkListOne(MkSpecifier(DOUBLE));
3888 else if(dest.kind == floatType &&
3889 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3890 source.kind == _BoolType || source.kind == doubleType))
3892 specs = MkListOne(MkSpecifier(FLOAT));
3894 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3895 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3898 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3899 ListAdd(specs, MkSpecifier(INT64));
3901 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3902 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3905 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3906 ListAdd(specs, MkSpecifier(INT));
3908 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3909 source.kind == floatType || source.kind == doubleType))
3912 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3913 ListAdd(specs, MkSpecifier(SHORT));
3915 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3916 source.kind == floatType || source.kind == doubleType))
3919 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3920 ListAdd(specs, MkSpecifier(CHAR));
3926 if(backupSourceExpType)
3928 // Failed to convert: revert previous exp type
3929 if(sourceExp.expType) FreeType(sourceExp.expType);
3930 sourceExp.expType = backupSourceExpType;
3935 else if(dest.kind == doubleType &&
3936 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3937 source.kind == _BoolType || source.kind == charType))
3939 specs = MkListOne(MkSpecifier(DOUBLE));
3941 else if(dest.kind == floatType &&
3942 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3944 specs = MkListOne(MkSpecifier(FLOAT));
3946 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3947 (value == 1 || value == 0))
3950 ListAdd(specs, MkSpecifier(BOOL));
3952 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3953 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3955 if(source.kind == intType)
3959 if(backupSourceExpType) FreeType(backupSourceExpType);
3965 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3966 ListAdd(specs, MkSpecifier(CHAR));
3969 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3970 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3972 if(source.kind == intType)
3976 if(backupSourceExpType) FreeType(backupSourceExpType);
3982 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3983 ListAdd(specs, MkSpecifier(SHORT));
3986 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3989 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3990 ListAdd(specs, MkSpecifier(INT));
3992 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3995 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3996 ListAdd(specs, MkSpecifier(INT64));
3998 else if(dest.kind == enumType &&
3999 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4001 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
4007 if(backupSourceExpType)
4009 // Failed to convert: revert previous exp type
4010 if(sourceExp.expType) FreeType(sourceExp.expType);
4011 sourceExp.expType = backupSourceExpType;
4016 if(!flag && !sourceExp.opDestType)
4018 Expression newExp { };
4019 *newExp = *sourceExp;
4022 if(sourceExp.destType) sourceExp.destType.refCount++;
4023 if(sourceExp.expType) sourceExp.expType.refCount++;
4025 sourceExp.type = castExp;
4026 if(realDest.kind == classType)
4028 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4029 FreeList(specs, FreeSpecifier);
4032 sourceExp.cast.typeName = MkTypeName(specs, null);
4033 if(newExp.type == opExp)
4035 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4038 sourceExp.cast.exp = newExp;
4040 FreeType(sourceExp.expType);
4041 sourceExp.expType = null;
4042 ProcessExpressionType(sourceExp);
4045 FreeList(specs, FreeSpecifier);
4049 if(backupSourceExpType) FreeType(backupSourceExpType);
4055 if(computedExp != nbExp)
4057 FreeExpression(computedExp);
4058 computedExp = nbExp;
4061 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4062 if(sourceExp.type == identifierExp)
4064 Identifier id = sourceExp.identifier;
4065 if(dest.kind == classType)
4067 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4069 Class _class = dest._class.registered;
4070 Class enumClass = eSystem_FindClass(privateModule, "enum");
4073 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4076 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4077 for(value = e.values.first; value; value = value.next)
4079 if(!strcmp(value.name, id.string))
4084 FreeType(sourceExp.expType);
4086 sourceExp.isConstant = true;
4087 sourceExp.expType = MkClassType(_class.fullName);
4088 if(inCompiler || inPreCompiler || inDebugger)
4090 FreeExpContents(sourceExp);
4092 sourceExp.type = constantExp;
4093 if(_class.dataTypeString && (!strcmp(_class.dataTypeString, "int") || !strcmp(_class.dataTypeString, "int64") || !strcmp(_class.dataTypeString, "short") || !strcmp(_class.dataTypeString, "char"))) // _class cannot be null here!
4094 sourceExp.constant = PrintInt64(value.data);
4096 sourceExp.constant = PrintUInt64(value.data);
4097 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4107 // Loop through all enum classes
4108 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4119 #define TERTIARY(o, name, m, t, p) \
4120 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4122 exp.type = constantExp; \
4123 exp.string = p(op1.m ? op2.m : op3.m); \
4125 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4129 #define BINARY(o, name, m, t, p) \
4130 static bool name(Expression exp, Operand op1, Operand op2) \
4133 exp.type = constantExp; \
4134 exp.string = p((t)(op1.m o value2)); \
4136 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4140 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4141 static bool name(Expression exp, Operand op1, Operand op2) \
4144 exp.type = constantExp; \
4145 exp.string = p(value2 ? ((t)(op1.m o value2)) : 0); \
4147 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4151 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4152 static bool name(Expression exp, Operand op1, Operand op2) \
4155 exp.type = constantExp; \
4156 exp.string = p((t)(op1.m o value2)); \
4158 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4162 #define UNARY(o, name, m, t, p) \
4163 static bool name(Expression exp, Operand op1) \
4165 exp.type = constantExp; \
4166 exp.string = p((t)(o op1.m)); \
4168 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4172 #define OPERATOR_ALL(macro, o, name) \
4173 macro(o, Int##name, i, int, PrintInt) \
4174 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4175 macro(o, Int64##name, i64, int64, PrintInt64) \
4176 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4177 macro(o, Short##name, s, short, PrintShort) \
4178 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4179 macro(o, Char##name, c, char, PrintChar) \
4180 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4181 macro(o, Float##name, f, float, PrintFloat) \
4182 macro(o, Double##name, d, double, PrintDouble)
4184 #define OPERATOR_INTTYPES(macro, o, name) \
4185 macro(o, Int##name, i, int, PrintInt) \
4186 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4187 macro(o, Int64##name, i64, int64, PrintInt64) \
4188 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4189 macro(o, Short##name, s, short, PrintShort) \
4190 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4191 macro(o, Char##name, c, char, PrintChar) \
4192 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4194 #define OPERATOR_REALTYPES(macro, o, name) \
4195 macro(o, Float##name, f, float, PrintFloat) \
4196 macro(o, Double##name, d, double, PrintDouble)
4198 // binary arithmetic
4199 OPERATOR_ALL(BINARY, +, Add)
4200 OPERATOR_ALL(BINARY, -, Sub)
4201 OPERATOR_ALL(BINARY, *, Mul)
4202 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4203 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4204 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4207 OPERATOR_ALL(UNARY, -, Neg)
4209 // unary arithmetic increment and decrement
4210 OPERATOR_ALL(UNARY, ++, Inc)
4211 OPERATOR_ALL(UNARY, --, Dec)
4213 // binary arithmetic assignment
4214 OPERATOR_ALL(BINARY, =, Asign)
4215 OPERATOR_ALL(BINARY, +=, AddAsign)
4216 OPERATOR_ALL(BINARY, -=, SubAsign)
4217 OPERATOR_ALL(BINARY, *=, MulAsign)
4218 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4219 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4220 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4223 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4224 OPERATOR_INTTYPES(BINARY, |, BitOr)
4225 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4226 OPERATOR_INTTYPES(BINARY, <<, LShift)
4227 OPERATOR_INTTYPES(BINARY, >>, RShift)
4230 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4232 // binary bitwise assignment
4233 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4234 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4235 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4236 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4237 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4239 // unary logical negation
4240 OPERATOR_INTTYPES(UNARY, !, Not)
4242 // binary logical equality
4243 OPERATOR_ALL(BINARY, ==, Equ)
4244 OPERATOR_ALL(BINARY, !=, Nqu)
4247 OPERATOR_ALL(BINARY, &&, And)
4248 OPERATOR_ALL(BINARY, ||, Or)
4250 // binary logical relational
4251 OPERATOR_ALL(BINARY, >, Grt)
4252 OPERATOR_ALL(BINARY, <, Sma)
4253 OPERATOR_ALL(BINARY, >=, GrtEqu)
4254 OPERATOR_ALL(BINARY, <=, SmaEqu)
4256 // tertiary condition operator
4257 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4259 //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
4260 #define OPERATOR_TABLE_ALL(name, type) \
4261 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4263 type##Inc, type##Dec, \
4264 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4265 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4267 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4269 type##Equ, type##Nqu, \
4270 type##And, type##Or, \
4271 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4274 #define OPERATOR_TABLE_INTTYPES(name, type) \
4275 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4277 type##Inc, type##Dec, \
4278 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4279 null, null, null, null, null, \
4281 null, null, null, null, null, \
4283 type##Equ, type##Nqu, \
4284 type##And, type##Or, \
4285 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4288 OPERATOR_TABLE_ALL(int, Int)
4289 OPERATOR_TABLE_ALL(uint, UInt)
4290 OPERATOR_TABLE_ALL(int64, Int64)
4291 OPERATOR_TABLE_ALL(uint64, UInt64)
4292 OPERATOR_TABLE_ALL(short, Short)
4293 OPERATOR_TABLE_ALL(ushort, UShort)
4294 OPERATOR_TABLE_INTTYPES(float, Float)
4295 OPERATOR_TABLE_INTTYPES(double, Double)
4296 OPERATOR_TABLE_ALL(char, Char)
4297 OPERATOR_TABLE_ALL(uchar, UChar)
4299 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4300 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4301 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4302 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4303 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4304 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4305 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4306 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4308 public void ReadString(char * output, char * string)
4310 int len = strlen(string);
4312 bool quoted = false, escaped = false;
4313 for(c = 0; c<len; c++)
4315 char ch = string[c];
4320 case 'n': output[d] = '\n'; break;
4321 case 't': output[d] = '\t'; break;
4322 case 'a': output[d] = '\a'; break;
4323 case 'b': output[d] = '\b'; break;
4324 case 'f': output[d] = '\f'; break;
4325 case 'r': output[d] = '\r'; break;
4326 case 'v': output[d] = '\v'; break;
4327 case '\\': output[d] = '\\'; break;
4328 case '\"': output[d] = '\"'; break;
4329 case '\'': output[d] = '\''; break;
4330 default: output[d] = ch;
4351 // String Unescape Copy
4353 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4354 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4355 public int UnescapeString(char * d, char * s, int len)
4359 while(j < len && (ch = s[j]))
4364 switch((ch = s[++j]))
4366 case 'n': d[k] = '\n'; break;
4367 case 't': d[k] = '\t'; break;
4368 case 'a': d[k] = '\a'; break;
4369 case 'b': d[k] = '\b'; break;
4370 case 'f': d[k] = '\f'; break;
4371 case 'r': d[k] = '\r'; break;
4372 case 'v': d[k] = '\v'; break;
4373 case '\\': d[k] = '\\'; break;
4374 case '\"': d[k] = '\"'; break;
4375 case '\'': d[k] = '\''; break;
4376 default: d[k] = '\\'; d[k] = ch;
4388 public char * OffsetEscapedString(char * s, int len, int offset)
4392 while(j < len && k < offset && (ch = s[j]))
4397 return (k == offset) ? s + j : null;
4400 public Operand GetOperand(Expression exp)
4403 Type type = exp.expType;
4406 while(type.kind == classType && type._class &&
4407 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4409 if(!type._class.registered.dataType)
4410 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4411 type = type._class.registered.dataType;
4414 if(exp.type == stringExp && op.kind == pointerType)
4416 op.ui64 = (uint64)(uintptr)exp.string;
4417 op.kind = pointerType;
4420 else if(exp.isConstant && exp.type == constantExp)
4422 op.kind = type.kind;
4430 if(exp.constant[0] == '\'')
4432 op.c = exp.constant[1];
4435 else if(type.isSigned)
4437 op.c = (char)strtol(exp.constant, null, 0);
4442 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4448 if(exp.constant[0] == '\'')
4450 op.s = exp.constant[1];
4453 else if(type.isSigned)
4455 op.s = (short)strtol(exp.constant, null, 0);
4460 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4466 if(exp.constant[0] == '\'')
4468 op.i = exp.constant[1];
4471 else if(type.isSigned)
4473 op.i = (int)strtol(exp.constant, null, 0);
4478 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
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;
4512 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4517 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4520 op.kind = int64Type;
4523 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4524 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4525 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4526 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4528 op.f = (float)strtod(exp.constant, null);
4532 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4533 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4534 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4535 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4537 op.d = (double)strtod(exp.constant, null);
4540 //case classType: For when we have operator overloading...
4541 // Pointer additions
4542 //case functionType:
4546 op.ui64 = _strtoui64(exp.constant, null, 0);
4547 op.kind = pointerType;
4557 static int64 GetEnumValue(Class _class, void * ptr)
4560 switch(_class.typeSize)
4563 if(!strcmp(_class.dataTypeString, "uint64"))
4564 v = (int64)*(uint64 *)ptr;
4566 v = (int64)*(int64 *)ptr;
4569 if(!strcmp(_class.dataTypeString, "uint"))
4570 v = (int64)*(uint *)ptr;
4572 v = (int64)*(int *)ptr;
4575 if(!strcmp(_class.dataTypeString, "uint16"))
4576 v = (int64)*(uint16 *)ptr;
4578 v = (int64)*(short *)ptr;
4581 if(!strcmp(_class.dataTypeString, "byte"))
4582 v = (int64)*(byte *)ptr;
4584 v = (int64)*(char *)ptr;
4590 static __attribute__((unused)) void UnusedFunction()
4593 a.OnGetString(0,0,0);
4596 extern int __ecereVMethodID_class_OnGetString;
4599 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4601 DataMember dataMember;
4602 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4604 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4605 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4609 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4611 void * ptr = inst.data + dataMember.offset + offset;
4612 char * result = null;
4613 exp.loc = member.loc = inst.loc;
4614 ((Identifier)member.identifiers->first).loc = inst.loc;
4616 if(!dataMember.dataType)
4617 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4618 type = dataMember.dataType;
4619 if(type.kind == classType)
4621 Class _class = type._class.registered;
4622 if(_class.type == enumClass)
4624 Class enumClass = eSystem_FindClass(privateModule, "enum");
4627 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4629 for(item = e.values.first; item; item = item.next)
4631 if(item.data == GetEnumValue(_class, ptr))
4639 exp.identifier = MkIdentifier(result);
4640 exp.type = identifierExp;
4641 exp.destType = MkClassType(_class.fullName);
4642 ProcessExpressionType(exp);
4646 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4648 if(!_class.dataType)
4649 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4650 type = _class.dataType;
4659 FreeExpContents(exp);
4661 exp.constant = PrintFloat(*(float*)ptr);
4662 exp.type = constantExp;
4667 FreeExpContents(exp);
4669 exp.constant = PrintDouble(*(double*)ptr);
4670 exp.type = constantExp;
4675 FreeExpContents(exp);
4677 exp.constant = PrintInt(*(int*)ptr);
4678 exp.type = constantExp;
4683 FreeExpContents(exp);
4685 exp.constant = PrintInt64(*(int64*)ptr);
4686 exp.type = constantExp;
4691 FreeExpContents(exp);
4692 // TODO: This should probably use proper type
4693 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4694 exp.type = constantExp;
4699 FreeExpContents(exp);
4700 // TODO: This should probably use proper type
4701 exp.constant = PrintInt64((int64)*(intsize*)ptr);
4702 exp.type = constantExp;
4706 Compiler_Error($"Unhandled type populating instance\n");
4709 ListAdd(memberList, member);
4712 if(parentDataMember.type == unionMember)
4717 void PopulateInstance(Instantiation inst)
4719 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4720 Class _class = classSym.registered;
4721 DataMember dataMember;
4722 OldList * memberList = MkList();
4723 // Added this check and ->Add to prevent memory leaks on bad code
4725 inst.members = MkListOne(MkMembersInitList(memberList));
4727 inst.members->Add(MkMembersInitList(memberList));
4728 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4730 if(!dataMember.isProperty)
4732 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4733 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4737 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4739 void * ptr = inst.data + dataMember.offset;
4740 char * result = null;
4742 exp.loc = member.loc = inst.loc;
4743 ((Identifier)member.identifiers->first).loc = inst.loc;
4745 if(!dataMember.dataType)
4746 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4747 type = dataMember.dataType;
4748 if(type.kind == classType)
4750 Class _class = type._class.registered;
4751 if(_class.type == enumClass)
4753 Class enumClass = eSystem_FindClass(privateModule, "enum");
4756 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4758 for(item = e.values.first; item; item = item.next)
4760 if(item.data == GetEnumValue(_class, ptr))
4769 exp.identifier = MkIdentifier(result);
4770 exp.type = identifierExp;
4771 exp.destType = MkClassType(_class.fullName);
4772 ProcessExpressionType(exp);
4775 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4777 if(!_class.dataType)
4778 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4779 type = _class.dataType;
4788 exp.constant = PrintFloat(*(float*)ptr);
4789 exp.type = constantExp;
4794 exp.constant = PrintDouble(*(double*)ptr);
4795 exp.type = constantExp;
4800 exp.constant = PrintInt(*(int*)ptr);
4801 exp.type = constantExp;
4806 exp.constant = PrintInt64(*(int64*)ptr);
4807 exp.type = constantExp;
4812 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4813 exp.type = constantExp;
4817 Compiler_Error($"Unhandled type populating instance\n");
4820 ListAdd(memberList, member);
4826 void ComputeInstantiation(Expression exp)
4828 Instantiation inst = exp.instance;
4829 MembersInit members;
4830 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4831 Class _class = classSym ? classSym.registered : null;
4832 DataMember curMember = null;
4833 Class curClass = null;
4834 DataMember subMemberStack[256];
4835 int subMemberStackPos = 0;
4838 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4840 // Don't recompute the instantiation...
4841 // Non Simple classes will have become constants by now
4845 if(_class.type == normalClass || _class.type == noHeadClass)
4847 inst.data = (byte *)eInstance_New(_class);
4848 if(_class.type == normalClass)
4849 ((Instance)inst.data)._refCount++;
4852 inst.data = new0 byte[_class.structSize];
4857 for(members = inst.members->first; members; members = members.next)
4859 switch(members.type)
4861 case dataMembersInit:
4863 if(members.dataMembers)
4866 for(member = members.dataMembers->first; member; member = member.next)
4868 Identifier ident = member.identifiers ? member.identifiers->first : null;
4871 Property prop = null;
4872 DataMember dataMember = null;
4873 uint dataMemberOffset;
4877 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4880 if(curMember.isProperty)
4881 prop = (Property)curMember;
4884 dataMember = curMember;
4886 // CHANGED THIS HERE
4887 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4889 // 2013/17/29 -- It seems that this was missing here!
4890 if(_class.type == normalClass)
4891 dataMemberOffset += _class.base.structSize;
4892 // dataMemberOffset = dataMember.offset;
4899 prop = eClass_FindProperty(_class, ident.string, privateModule);
4903 if(prop.memberAccess == publicAccess)
4905 curMember = (DataMember)prop;
4906 curClass = prop._class;
4911 DataMember _subMemberStack[256];
4912 int _subMemberStackPos = 0;
4914 // FILL MEMBER STACK
4915 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4920 if(dataMember.memberAccess == publicAccess)
4922 curMember = dataMember;
4923 curClass = dataMember._class;
4924 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4925 subMemberStackPos = _subMemberStackPos;
4931 if(found && member.initializer && member.initializer.type == expInitializer)
4933 Expression value = member.initializer.exp;
4935 bool deepMember = false;
4938 type = prop.dataType;
4942 if(!dataMember.dataType)
4943 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4945 type = dataMember.dataType;
4948 if(ident && ident.next)
4952 // for(; ident && type; ident = ident.next)
4953 for(ident = ident.next; ident && type; ident = ident.next)
4955 if(type.kind == classType)
4957 prop = eClass_FindProperty(type._class.registered,
4958 ident.string, privateModule);
4960 type = prop.dataType;
4963 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4964 ident.string, &dataMemberOffset, privateModule, null, null);
4966 type = dataMember.dataType;
4969 else if(type.kind == structType || type.kind == unionType)
4972 for(memberType = type.members.first; memberType; memberType = memberType.next)
4974 if(!strcmp(memberType.name, ident.string))
4985 FreeType(value.destType);
4986 value.destType = type;
4987 if(type) type.refCount++;
4988 ComputeExpression(value);
4990 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4992 if(type.kind == classType)
4994 Class _class = type._class.registered;
4995 if(_class && (_class.type == bitClass || _class.type == unitClass || _class.type == enumClass))
4997 if(!_class.dataType)
4998 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4999 type = _class.dataType;
5005 void * ptr = inst.data + dataMemberOffset;
5007 if(value.type == constantExp)
5013 GetInt(value, (int*)ptr);
5018 GetInt64(value, (int64*)ptr);
5023 GetIntPtr(value, (intptr*)ptr);
5028 GetIntSize(value, (intsize*)ptr);
5033 GetFloat(value, (float*)ptr);
5038 GetDouble(value, (double *)ptr);
5043 else if(value.type == instanceExp)
5045 if(type.kind == classType)
5047 Class _class = type._class.registered;
5048 if(_class.type == structClass)
5050 ComputeTypeSize(type);
5051 if(value.instance.data)
5052 memcpy(ptr, value.instance.data, type.size);
5057 else if(prop && prop.Set != (void *)(intptr)1)
5059 if(value.type == instanceExp && value.instance.data)
5061 if(type.kind == classType)
5063 Class _class = type._class.registered;
5064 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5066 void (*Set)(void *, void *) = (void *)prop.Set;
5067 Set(inst.data, value.instance.data);
5068 PopulateInstance(inst);
5072 else if(value.type == constantExp)
5078 void (*Set)(void *, double) = (void *)prop.Set;
5079 Set(inst.data, strtod(value.constant, null) );
5084 void (*Set)(void *, float) = (void *)prop.Set;
5085 Set(inst.data, (float)(strtod(value.constant, null)));
5090 void (*Set)(void *, int) = (void *)prop.Set;
5091 Set(inst.data, (int)strtol(value.constant, null, 0));
5096 void (*Set)(void *, int64) = (void *)prop.Set;
5097 Set(inst.data, _strtoi64(value.constant, null, 0));
5102 void (*Set)(void *, intptr) = (void *)prop.Set;
5103 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5108 void (*Set)(void *, intsize) = (void *)prop.Set;
5109 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5114 else if(value.type == stringExp)
5117 ReadString(temp, value.string);
5118 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5122 else if(!deepMember && type && _class.type == unitClass)
5126 // Only support converting units to units for now...
5127 if(value.type == constantExp)
5129 if(type.kind == classType)
5131 Class _class = type._class.registered;
5132 if(_class.type == unitClass)
5134 if(!_class.dataType)
5135 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5136 type = _class.dataType;
5139 // TODO: Assuming same base type for units...
5145 float (*Set)(float) = (void *)prop.Set;
5146 GetFloat(member.initializer.exp, &fValue);
5147 exp.constant = PrintFloat(Set(fValue));
5148 exp.type = constantExp;
5154 double (*Set)(double) = (void *)prop.Set;
5155 GetDouble(member.initializer.exp, &dValue);
5156 exp.constant = PrintDouble(Set(dValue));
5157 exp.type = constantExp;
5164 else if(!deepMember && type && _class.type == bitClass)
5168 if(value.type == instanceExp && value.instance.data)
5170 unsigned int (*Set)(void *) = (void *)prop.Set;
5171 bits = Set(value.instance.data);
5173 else if(value.type == constantExp)
5179 BitMember bitMember = (BitMember) dataMember;
5182 bits = (bits & ~bitMember.mask);
5183 if(!bitMember.dataType)
5184 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5185 type = bitMember.dataType;
5186 if(type.kind == classType && type._class && type._class.registered)
5188 if(!type._class.registered.dataType)
5189 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5190 type = type._class.registered.dataType;
5195 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5196 case shortType: { uint16 v; type.isSigned ? GetShort(value, (short *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5198 case longType: { uint v; type.isSigned ? GetInt(value, (int *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5199 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (int64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5200 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (intptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5201 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (intsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5203 bits |= part << bitMember.pos;
5209 if(_class && _class.type == unitClass)
5211 ComputeExpression(member.initializer.exp);
5212 exp.constant = member.initializer.exp.constant;
5213 exp.type = constantExp;
5215 member.initializer.exp.constant = null;
5225 if(_class && _class.type == bitClass)
5227 exp.constant = PrintHexUInt(bits);
5228 exp.type = constantExp;
5230 if(exp.type != instanceExp)
5236 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5238 bool result = false;
5242 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5243 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5247 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5248 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5251 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5252 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5253 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5256 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5257 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5258 result = GetOpFloat(op, &op.f);
5261 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5262 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5263 result = GetOpDouble(op, &op.d);
5266 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5267 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5268 result = GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5271 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5272 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5273 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5276 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5277 result = isSigned ? GetOpInt64 /*GetOpIntPtr*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5280 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5281 result = isSigned ? GetOpInt64 /*GetOpIntSize*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntSize*/(op, &op.ui64);
5287 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5289 if(exp.op.op == SIZEOF)
5291 FreeExpContents(exp);
5292 exp.type = constantExp;
5293 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5304 // Provide default unary +
5305 Expression exp2 = exp.op.exp2;
5307 FreeExpContents(exp);
5308 FreeType(exp.expType);
5309 FreeType(exp.destType);
5315 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5317 // unary arithmetic increment and decrement
5318 //OPERATOR_ALL(UNARY, ++, Inc)
5319 //OPERATOR_ALL(UNARY, --, Dec)
5322 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5324 // unary logical negation
5326 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5332 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5334 if(Promote(op2, op1.kind, op1.type.isSigned))
5335 op2.kind = op1.kind, op2.ops = op1.ops;
5336 else if(Promote(op1, op2.kind, op2.type.isSigned))
5337 op1.kind = op2.kind, op1.ops = op2.ops;
5341 // binary arithmetic
5343 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5346 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5349 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5352 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5355 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5357 // binary arithmetic assignment
5358 //OPERATOR_ALL(BINARY, =, Asign)
5359 //OPERATOR_ALL(BINARY, +=, AddAsign)
5360 //OPERATOR_ALL(BINARY, -=, SubAsign)
5361 //OPERATOR_ALL(BINARY, *=, MulAsign)
5362 //OPERATOR_ALL(BINARY, /=, DivAsign)
5363 //OPERATOR_ALL(BINARY, %=, ModAsign)
5368 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5372 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5375 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5378 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5381 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5383 // binary bitwise assignment
5384 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5385 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5386 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5387 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5388 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5389 // binary logical equality
5391 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5394 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5398 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5401 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5403 // binary logical relational
5405 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5408 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5411 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5414 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5421 void ComputeExpression(Expression exp)
5424 char expString[10240];
5425 expString[0] = '\0';
5426 PrintExpression(exp, expString);
5433 Identifier id = exp.identifier;
5434 if(id && exp.isConstant && !inCompiler && !inPreCompiler && !inDebugger)
5436 Class c = (exp.expType && exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
5437 if(c && c.type == enumClass)
5439 Class enumClass = eSystem_FindClass(privateModule, "enum");
5443 EnumClassData e = ACCESS_CLASSDATA(c, enumClass);
5444 for(value = e.values.first; value; value = value.next)
5446 if(!strcmp(value.name, id.string))
5451 const String dts = c.dataTypeString;
5452 FreeExpContents(exp);
5453 exp.type = constantExp;
5454 exp.constant = (dts && (!strcmp(dts, "int") || !strcmp(dts, "int64") || !strcmp(dts, "short") || !strcmp(dts, "char"))) ? PrintInt64(value.data) : PrintUInt64(value.data);
5463 ComputeInstantiation(exp);
5472 Expression exp1, exp2 = null;
5476 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5479 Expression e = exp.op.exp2;
5481 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5483 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5485 if(e.type == extensionCompoundExp)
5486 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5491 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5493 if(e.type == stringExp && e.string)
5495 char * string = e.string;
5496 int len = strlen(string);
5497 char * tmp = new char[len-2+1];
5498 len = UnescapeString(tmp, string + 1, len - 2);
5500 FreeExpContents(exp);
5501 exp.type = constantExp;
5502 exp.constant = PrintUInt(len + 1);
5506 Type type = e.expType;
5508 FreeExpContents(exp);
5509 exp.type = constantExp;
5510 exp.constant = PrintUInt(ComputeTypeSize(type));
5516 ComputeExpression(exp.op.exp2);
5520 ComputeExpression(exp.op.exp1);
5523 op1 = GetOperand(exp1);
5524 if(op1.type) op1.type.refCount++;
5527 op2 = GetOperand(exp2);
5528 if(op2.type) op2.type.refCount++;
5534 op1 = GetOperand(exp1);
5535 if(op1.type) op1.type.refCount++;
5538 CallOperator(exp, exp1, exp2, op1, op2);
5545 if(exp.op.exp1 && exp.op.exp2)
5550 FreeExpContents(exp);
5551 op1.ops.BitAnd(exp, op1, op2);
5560 FreeExpContents(exp);
5561 op1.ops.Mul(exp, op1, op2);
5570 FreeExpContents(exp);
5571 op1.ops.Add(exp, op1, op2);
5576 // Provide default unary +
5577 Expression exp2 = exp.op.exp2;
5579 FreeExpContents(exp);
5580 FreeType(exp.expType);
5581 FreeType(exp.destType);
5592 FreeExpContents(exp);
5593 op1.ops.Sub(exp, op1, op2);
5600 FreeExpContents(exp);
5601 op1.ops.Neg(exp, op1);
5608 FreeExpContents(exp);
5609 op1.ops.BitNot(exp, op1);
5615 FreeExpContents(exp);
5616 op1.ops.Not(exp, op1);
5619 // Binary only operators
5623 FreeExpContents(exp);
5624 op1.ops.Div(exp, op1, op2);
5630 FreeExpContents(exp);
5631 op1.ops.Mod(exp, op1, op2);
5643 FreeExpContents(exp);
5644 op1.ops.Sma(exp, op1, op2);
5653 FreeExpContents(exp);
5654 op1.ops.Grt(exp, op1, op2);
5663 FreeExpContents(exp);
5664 op1.ops.SmaEqu(exp, op1, op2);
5673 FreeExpContents(exp);
5674 op1.ops.GrtEqu(exp, op1, op2);
5683 FreeExpContents(exp);
5684 op1.ops.Equ(exp, op1, op2);
5693 FreeExpContents(exp);
5694 op1.ops.Nqu(exp, op1, op2);
5701 FreeExpContents(exp);
5702 op1.ops.BitOr(exp, op1, op2);
5708 FreeExpContents(exp);
5709 op1.ops.BitXor(exp, op1, op2);
5717 FreeExpContents(exp);
5718 exp.type = constantExp;
5719 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5723 if(op1.type) FreeType(op1.type);
5724 if(op2.type) FreeType(op2.type);
5728 case extensionExpressionExp:
5731 for(e = exp.list->first; e; e = n)
5736 OldList * list = exp.list;
5737 Expression prev = exp.prev;
5738 Expression next = exp.next;
5740 // For operations which set the exp type on brackets exp after the inner exp was processed...
5741 if(exp.expType && exp.expType.kind == classType && (!e.expType || e.expType.kind != classType))
5743 FreeType(e.expType);
5744 e.expType = exp.expType;
5745 e.expType.refCount++;
5747 ComputeExpression(e);
5748 //FreeExpContents(exp);
5749 FreeType(exp.expType);
5750 FreeType(exp.destType);
5769 exp.isConstant = true;
5771 ComputeExpression(exp.index.exp);
5772 if(!exp.index.exp.isConstant)
5773 exp.isConstant = false;
5775 for(e = exp.index.index->first; e; e = e.next)
5777 ComputeExpression(e);
5780 // Check if this type is int
5783 exp.isConstant = false;
5785 exp.expType = Dereference(exp.index.exp.expType);
5791 Expression memberExp = exp.member.exp;
5792 Identifier memberID = exp.member.member;
5795 ComputeExpression(exp.member.exp);
5796 type = exp.member.exp.expType;
5799 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);
5800 Property prop = null;
5801 DataMember member = null;
5802 Class convertTo = null;
5803 if(type.kind == subClassType && exp.member.exp.type == classExp)
5804 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5811 PrintTypeNoConst(type, string, false, true);
5812 classSym = FindClass(string);
5813 _class = classSym ? classSym.registered : null;
5816 if(exp.member.member)
5818 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5820 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5822 if(!prop && !member && _class && exp.member.member)
5824 Symbol classSym = FindClass(exp.member.member.string);
5826 _class = classSym ? classSym.registered : null;
5827 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5834 Type type = prop.dataType;
5835 // TODO: Assuming same base type for units...
5836 if(_class.type == unitClass)
5838 if(type.kind == classType)
5840 Class _class = type._class.registered;
5841 if(_class.type == unitClass)
5843 if(!_class.dataType)
5844 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5845 type = _class.dataType;
5853 float (*Get)(float) = (void *)prop.Get;
5854 GetFloat(exp.member.exp, &value);
5855 exp.constant = PrintFloat(Get ? Get(value) : value);
5856 exp.type = constantExp;
5862 double (*Get)(double);
5863 GetDouble(exp.member.exp, &value);
5866 Get = (void *)prop.Set;
5868 Get = (void *)prop.Get;
5869 exp.constant = PrintDouble(Get ? Get(value) : value);
5870 exp.type = constantExp;
5879 Expression value = exp.member.exp;
5882 ProcessPropertyType(prop);
5884 type = prop.dataType;
5887 // printf("Investigate this\n");
5889 else if(_class.type == structClass)
5895 Class propertyClass = type._class.registered;
5896 if(propertyClass.type == structClass && value.type == instanceExp)
5898 void (*Set)(void *, void *) = (void *)prop.Set;
5899 exp.instance = Instantiation { };
5900 exp.instance.data = new0 byte[_class.structSize];
5901 exp.instance._class = MkSpecifierName(_class.fullName);
5902 exp.instance.loc = exp.loc;
5903 exp.type = instanceExp;
5904 Set(exp.instance.data, value.instance.data);
5905 PopulateInstance(exp.instance);
5912 void (*Set)(void *, int) = (void *)prop.Set;
5914 exp.instance = Instantiation { };
5915 exp.instance.data = new0 byte[_class.structSize];
5916 exp.instance._class = MkSpecifierName(_class.fullName);
5917 exp.instance.loc = exp.loc;
5918 exp.type = instanceExp;
5920 GetInt(value, &intValue);
5922 Set(exp.instance.data, intValue);
5923 PopulateInstance(exp.instance);
5929 void (*Set)(void *, int64) = (void *)prop.Set;
5931 exp.instance = Instantiation { };
5932 exp.instance.data = new0 byte[_class.structSize];
5933 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5934 exp.instance.loc = exp.loc;
5935 exp.type = instanceExp;
5937 GetInt64(value, &intValue);
5939 Set(exp.instance.data, intValue);
5940 PopulateInstance(exp.instance);
5947 void (*Set)(void *, intptr) = (void *)prop.Set;
5949 exp.instance = Instantiation { };
5950 exp.instance.data = new0 byte[_class.structSize];
5951 exp.instance._class = MkSpecifierName(_class.fullName);
5952 exp.instance.loc = exp.loc;
5953 exp.type = instanceExp;
5955 GetIntPtr(value, &intValue);
5957 Set(exp.instance.data, intValue);
5958 PopulateInstance(exp.instance);
5965 void (*Set)(void *, intsize) = (void *)prop.Set;
5967 exp.instance = Instantiation { };
5968 exp.instance.data = new0 byte[_class.structSize];
5969 exp.instance._class = MkSpecifierName(_class.fullName);
5970 exp.instance.loc = exp.loc;
5971 exp.type = instanceExp;
5973 GetIntSize(value, &intValue);
5975 Set(exp.instance.data, intValue);
5976 PopulateInstance(exp.instance);
5982 void (*Set)(void *, float) = (void *)prop.Set;
5984 exp.instance = Instantiation { };
5985 exp.instance.data = new0 byte[_class.structSize];
5986 exp.instance._class = MkSpecifierName(_class.fullName);
5987 exp.instance.loc = exp.loc;
5988 exp.type = instanceExp;
5990 GetFloat(value, &floatValue);
5992 Set(exp.instance.data, floatValue);
5993 PopulateInstance(exp.instance);
5999 void (*Set)(void *, double) = (void *)prop.Set;
6001 exp.instance = Instantiation { };
6002 exp.instance.data = new0 byte[_class.structSize];
6003 exp.instance._class = MkSpecifierName(_class.fullName);
6004 exp.instance.loc = exp.loc;
6005 exp.type = instanceExp;
6007 GetDouble(value, &doubleValue);
6009 Set(exp.instance.data, doubleValue);
6010 PopulateInstance(exp.instance);
6015 else if(_class.type == bitClass)
6021 Class propertyClass = type._class.registered;
6022 if(propertyClass.type == structClass && value.instance.data)
6024 unsigned int (*Set)(void *) = (void *)prop.Set;
6025 unsigned int bits = Set(value.instance.data);
6026 exp.constant = PrintHexUInt(bits);
6027 exp.type = constantExp;
6030 else if(_class.type == bitClass)
6033 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6036 GetUInt(exp.member.exp, &value);
6038 exp.constant = PrintHexUInt(bits);
6039 exp.type = constantExp;
6047 if(_class.type == bitClass)
6050 GetUInt(exp.member.exp, &value);
6056 Class _class = type._class.registered;
6057 if(_class.type == structClass)
6059 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6061 exp.instance = Instantiation { };
6062 exp.instance.data = new0 byte[_class.structSize];
6063 exp.instance._class = MkSpecifierName(_class.fullName);
6064 exp.instance.loc = exp.loc;
6065 //exp.instance.fullSet = true;
6066 exp.type = instanceExp;
6067 Get(value, exp.instance.data);
6068 PopulateInstance(exp.instance);
6070 else if(_class.type == bitClass)
6072 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6073 uint64 bits = Get(value);
6074 exp.constant = PrintHexUInt64(bits);
6075 exp.type = constantExp;
6081 else if(_class.type == structClass)
6083 byte * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6088 Class _class = type._class.registered;
6089 if(_class.type == structClass && value)
6091 void (*Get)(void *, void *) = (void *)prop.Get;
6093 exp.instance = Instantiation { };
6094 exp.instance.data = new0 byte[_class.structSize];
6095 exp.instance._class = MkSpecifierName(_class.fullName);
6096 exp.instance.loc = exp.loc;
6097 //exp.instance.fullSet = true;
6098 exp.type = instanceExp;
6099 Get(value, exp.instance.data);
6100 PopulateInstance(exp.instance);
6108 char * value = exp.member.exp.instance.data;
6113 Class _class = type._class.registered;
6114 if(_class.type == normalClass)
6116 void *(*Get)(void *) = (void *)prop.Get;
6118 exp.instance = Instantiation { };
6119 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6120 exp.type = instanceExp;
6121 exp.instance.data = Get(value, exp.instance.data);
6133 exp.isConstant = false;
6141 if(exp.type != ExpressionType::memberExp)
6143 FreeExpression(memberExp);
6144 FreeIdentifier(memberID);
6150 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6151 FreeExpContents(exp);
6152 exp.constant = PrintUInt(ComputeTypeSize(type));
6153 exp.type = constantExp;
6159 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6160 if(classSym && classSym.registered)
6162 if(classSym.registered.fixed)
6164 FreeSpecifier(exp._class);
6165 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6166 exp.type = constantExp;
6170 char className[1024];
6171 strcpy(className, "__ecereClass_");
6172 FullClassNameCat(className, classSym.string, true);
6174 DeclareClass(curExternal, classSym, className);
6176 FreeExpContents(exp);
6177 exp.type = pointerExp;
6178 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6179 exp.member.member = MkIdentifier("structSize");
6189 if(exp.type == castExp)
6192 ComputeExpression(exp.cast.exp);
6195 if(e && exp.expType)
6198 type = exp.destType;
6201 if(type.kind == classType)
6203 Class _class = type._class.registered;
6204 if(_class && (_class.type == unitClass || _class.type == bitClass))
6206 if(!_class.dataType)
6207 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6208 type = _class.dataType;
6219 if(GetChar(e, &value))
6221 FreeExpContents(exp);
6222 exp.constant = PrintChar(value);
6223 exp.type = constantExp;
6228 unsigned char value = 0;
6229 if(GetUChar(e, &value))
6231 FreeExpContents(exp);
6232 exp.constant = PrintUChar(value);
6233 exp.type = constantExp;
6241 if(GetShort(e, &value))
6243 FreeExpContents(exp);
6244 exp.constant = PrintShort(value);
6245 exp.type = constantExp;
6250 unsigned short value = 0;
6251 if(GetUShort(e, &value))
6253 FreeExpContents(exp);
6254 exp.constant = PrintUShort(value);
6255 exp.type = constantExp;
6263 if(GetInt(e, &value))
6265 FreeExpContents(exp);
6266 exp.constant = PrintInt(value);
6267 exp.type = constantExp;
6272 unsigned int value = 0;
6273 if(GetUInt(e, &value))
6275 FreeExpContents(exp);
6276 exp.constant = PrintUInt(value);
6277 exp.type = constantExp;
6285 if(GetInt64(e, &value))
6287 FreeExpContents(exp);
6288 exp.constant = PrintInt64(value);
6289 exp.type = constantExp;
6295 if(GetUInt64(e, &value))
6297 FreeExpContents(exp);
6298 exp.constant = PrintUInt64(value);
6299 exp.type = constantExp;
6307 if(GetIntPtr(e, &value))
6309 FreeExpContents(exp);
6310 exp.constant = PrintInt64((int64)value);
6311 exp.type = constantExp;
6317 if(GetUIntPtr(e, &value))
6319 FreeExpContents(exp);
6320 exp.constant = PrintUInt64((uint64)value);
6321 exp.type = constantExp;
6329 if(GetIntSize(e, &value))
6331 FreeExpContents(exp);
6332 exp.constant = PrintInt64((int64)value);
6333 exp.type = constantExp;
6339 if(GetUIntSize(e, &value))
6341 FreeExpContents(exp);
6342 exp.constant = PrintUInt64((uint64)value);
6343 exp.type = constantExp;
6350 if(GetFloat(e, &value))
6352 FreeExpContents(exp);
6353 exp.constant = PrintFloat(value);
6354 exp.type = constantExp;
6361 if(GetDouble(e, &value))
6363 FreeExpContents(exp);
6364 exp.constant = PrintDouble(value);
6365 exp.type = constantExp;
6380 // Caring only about last expression for now...
6381 ComputeExpression(exp.cond.exp->last);
6382 if(exp.cond.elseExp)
6383 ComputeExpression(exp.cond.elseExp);
6385 ComputeExpression(exp.cond.cond);
6387 op1 = GetOperand(exp.cond.cond);
6388 if(op1.type) op1.type.refCount++;
6389 op2 = GetOperand(exp.cond.exp->last);
6390 if(op2.type) op2.type.refCount++;
6391 op3 = GetOperand(exp.cond.elseExp);
6392 if(op3.type) op3.type.refCount++;
6394 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6395 if(op1.type) FreeType(op1.type);
6396 if(op2.type) FreeType(op2.type);
6397 if(op3.type) FreeType(op3.type);
6403 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6408 OldList converts { };
6411 if(destType.kind == voidType)
6414 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6418 // for(convert = converts.last; convert; convert = convert.prev)
6419 for(convert = converts.first; convert; convert = convert.next)
6421 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6424 Expression newExp { };
6425 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6427 // TODO: Check this...
6431 newExp.destType = null;
6436 exp.type = memberExp;
6437 exp.addedThis = true;
6438 exp.member.exp = newExp;
6439 FreeType(exp.member.exp.expType);
6441 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6442 exp.member.exp.expType.classObjectType = objectType;
6443 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6444 exp.member.memberType = propertyMember;
6445 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6446 // TESTING THIS... for (int)degrees
6447 exp.needCast = true;
6448 if(exp.expType) exp.expType.refCount++;
6449 ApplyAnyObjectLogic(exp.member.exp);
6454 /*if(exp.isConstant)
6456 // Color { ColorRGB = [exp] };
6457 exp.type = instanceExp;
6458 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6459 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6460 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6464 // If not constant, don't turn it yet into an instantiation
6465 // (Go through the deep members system first)
6466 exp.type = memberExp;
6467 exp.addedThis = true;
6468 exp.member.exp = newExp;
6470 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6471 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6472 newExp.expType._class.registered.type == noHeadClass)
6474 newExp.byReference = true;
6477 FreeType(exp.member.exp.expType);
6478 /*exp.member.exp.expType = convert.convert.dataType;
6479 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6480 exp.member.exp.expType = null;
6481 if(convert.convert.dataType)
6483 exp.member.exp.expType = { };
6484 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6485 exp.member.exp.expType.refCount = 1;
6486 exp.member.exp.expType.classObjectType = objectType;
6487 ApplyAnyObjectLogic(exp.member.exp);
6490 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6491 exp.member.memberType = reverseConversionMember;
6492 exp.expType = convert.resultType ? convert.resultType :
6493 MkClassType(convert.convert._class.fullName);
6494 exp.needCast = true;
6495 if(convert.resultType) convert.resultType.refCount++;
6501 FreeType(exp.expType);
6504 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6505 if(exp.destType.casted)
6506 exp.needCast = true;
6507 if(exp.expType) exp.expType.refCount++;
6511 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6512 if(exp.destType.casted)
6513 exp.needCast = true;
6514 if(convert.resultType)
6515 convert.resultType.refCount++;
6519 if(exp.isConstant && inCompiler)
6520 ComputeExpression(exp);
6522 converts.Free(FreeConvert);
6525 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6527 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6529 if(!result && exp.expType && exp.destType)
6531 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6532 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6533 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6534 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6538 // if(result) CheckTemplateTypes(exp);
6542 void modifyPassAsTemplate(Type * typePtr, bool value)
6544 if(*typePtr && typePtr->passAsTemplate != value)
6546 Type type { refCount = 1 };
6547 CopyTypeInto(type, *typePtr);
6548 type.passAsTemplate = value;
6554 void CheckTemplateTypes(Expression exp)
6557 bool et = exp.expType ? exp.expType.passAsTemplate : false;
6558 bool dt = exp.destType ? exp.destType.passAsTemplate : false;
6560 Expression nbExp = GetNonBracketsExp(exp);
6561 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6562 (nbExp == exp || nbExp.type != castExp))
6564 Expression newExp { };
6566 TypeKind kind = exp.expType.kind;
6568 if(exp.destType) exp.destType.refCount++;
6569 if(exp.expType) exp.expType.refCount++;
6573 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6575 Class c = exp.expType._class.registered;
6576 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6579 c.dataType = ProcessTypeString(c.dataTypeString, false);
6580 kind = c.dataType.kind;
6587 if(exp.destType.classObjectType)
6589 // We need to pass the address, just pass it along (Undo what was done above)
6590 if(exp.destType) exp.destType.refCount--;
6591 if(exp.expType) exp.expType.refCount--;
6596 // We want to pass as a template argument
6597 // ({ union { double d; uint64 i; } u; u.d = [newExp]; u.i; })
6599 OldList * unionDefs = MkList();
6600 OldList * statements = MkList();
6601 context = PushContext();
6602 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6603 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6604 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6605 exp.type = extensionCompoundExp;
6607 modifyPassAsTemplate(&exp.expType, true);
6608 modifyPassAsTemplate(&newExp.destType, false);
6609 modifyPassAsTemplate(&newExp.expType, false);
6611 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6612 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6613 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6614 exp.compound.compound.context = context;
6615 PopContext(context);
6619 if(exp.destType.classObjectType)
6621 // We need to pass the address, just pass it along (Undo what was done above)
6622 if(exp.destType) exp.destType.refCount--;
6623 if(exp.expType) exp.expType.refCount--;
6628 // We want to pass as a template argument
6629 // ({ union { float f; uint64 i; } u; u.f = [newExp]; u.i; })
6631 OldList * unionDefs = MkList();
6632 OldList * statements = MkList();
6633 context = PushContext();
6634 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(FLOAT)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("f"))), null)));
6635 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6636 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6637 exp.type = extensionCompoundExp;
6638 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6640 modifyPassAsTemplate(&exp.expType, true);
6641 modifyPassAsTemplate(&newExp.destType, false);
6642 modifyPassAsTemplate(&newExp.expType, false);
6644 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("f")), '=', newExp))));
6645 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6646 exp.compound.compound.context = context;
6647 PopContext(context);
6651 // Generated code already processed...
6655 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6656 if((exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass) || exp.expType.isPointerType)
6657 exp.cast.exp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), MkExpBrackets(MkListOne(newExp)));
6659 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6660 exp.needCast = true;
6664 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6666 Expression newExp { };
6668 TypeKind kind = exp.expType.kind;
6670 if(exp.destType) exp.destType.refCount++;
6671 if(exp.expType) exp.expType.refCount++;
6675 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6677 Class c = exp.expType._class.registered;
6678 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6681 c.dataType = ProcessTypeString(c.dataTypeString, false);
6682 kind = c.dataType.kind;
6689 if(exp.destType.classObjectType)
6691 // We need to pass the address, just pass it along (Undo what was done above)
6692 if(exp.destType) exp.destType.refCount--;
6693 if(exp.expType) exp.expType.refCount--;
6698 // If we're looking for value:
6699 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6701 OldList * unionDefs = MkList();
6702 OldList * statements = MkList();
6703 context = PushContext();
6704 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6705 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6706 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6707 exp.type = extensionCompoundExp;
6708 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6710 modifyPassAsTemplate(&exp.expType, false);
6711 modifyPassAsTemplate(&newExp.destType, true);
6712 modifyPassAsTemplate(&newExp.expType, true);
6714 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6715 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6716 exp.compound.compound.context = context;
6717 PopContext(context);
6721 if(exp.destType.classObjectType)
6723 // We need to pass the address, just pass it along (Undo what was done above)
6724 if(exp.destType) exp.destType.refCount--;
6725 if(exp.expType) exp.expType.refCount--;
6730 // If we're looking for value:
6731 // ({ union { float f; uint64 i; } u; u.i = [newExp]; u.f; })
6733 OldList * unionDefs = MkList();
6734 OldList * statements = MkList();
6735 context = PushContext();
6736 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(FLOAT)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("f"))), null)));
6737 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6738 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6739 exp.type = extensionCompoundExp;
6740 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6742 modifyPassAsTemplate(&exp.expType, false);
6743 modifyPassAsTemplate(&newExp.destType, true);
6744 modifyPassAsTemplate(&newExp.expType, true);
6746 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6747 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("f")))));
6748 exp.compound.compound.context = context;
6749 PopContext(context);
6754 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6756 exp.type = bracketsExp;
6758 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6759 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6760 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6761 ProcessExpressionType(exp.list->first);
6766 exp.type = bracketsExp;
6767 if(exp.expType.isPointerType)
6769 exp.needTemplateCast = 2;
6770 newExp.needCast = true;
6771 newExp.needTemplateCast = 2;
6772 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6775 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6776 exp.needTemplateCast = 2;
6777 newExp.needCast = true;
6778 newExp.needTemplateCast = 2;
6779 ProcessExpressionType(exp.list->first);
6785 if(exp.expType.kind == templateType)
6787 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6790 FreeType(exp.destType);
6791 FreeType(exp.expType);
6796 /*if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6798 // When was this required? Removed to address using templated values to pass to printf()
6802 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6803 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6807 char typeString[1024];
6809 OldList * specs = MkList();
6810 typeString[0] = '\0';
6811 PrintType(exp.expType, typeString, false, false);
6812 decl = SpecDeclFromString(typeString, specs, null);
6815 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6816 exp.cast.typeName = MkTypeName(specs, decl);
6817 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6818 exp.cast.exp.needCast = true;
6819 exp.needTemplateCast = 2;
6820 newExp.needTemplateCast = 2;
6827 // TODO: The Symbol tree should be reorganized by namespaces
6829 // - Tree of all symbols within (stored without namespace)
6830 // - Tree of sub-namespaces
6832 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6834 int nsLen = strlen(nameSpace);
6836 // Start at the name space prefix
6837 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6839 char * s = symbol.string;
6840 if(!strncmp(s, nameSpace, nsLen))
6842 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6845 for(c = strlen(s)-1; c >= 0; c--)
6850 if(!strcmp(namePart, name))
6852 // TODO: Error on ambiguity
6862 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6865 char nameSpace[1024];
6866 const char * namePart;
6867 bool gotColon = false;
6869 nameSpace[0] = '\0';
6870 for(c = strlen(name)-1; c >= 0; c--)
6877 namePart = name+c+1;
6878 while(c >= 0 && name[c] == ':') c--;
6881 // Try an exact match first
6882 Symbol symbol = (Symbol)tree.FindString(name);
6886 // Namespace specified
6887 memcpy(nameSpace, name, c + 1);
6890 return ScanWithNameSpace(tree, nameSpace, namePart);
6894 // Looking for a global symbol, e.g. ::Sleep()
6895 Symbol symbol = (Symbol)tree.FindString(namePart);
6900 // Name only (no namespace specified)
6901 Symbol symbol = (Symbol)tree.FindString(namePart);
6904 return ScanWithNameSpace(tree, "", namePart);
6909 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6912 //Time startTime = GetTime();
6914 // Optimize this later? Do this before/less?
6916 Symbol symbol = null;
6918 // First, check if the identifier is declared inside the function
6919 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6921 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6923 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6929 strcpy(curName, thisNameSpace);
6930 strcat(curName, "::");
6931 strcat(curName, name);
6932 // Try to resolve in current namespace first
6933 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6936 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6939 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6941 if(symbol || ctx == endContext) break;
6943 if(inCompiler && symbol && ctx == globalContext && symbol.pointerExternal && curExternal && symbol.pointerExternal != curExternal)
6944 curExternal.CreateUniqueEdge(symbol.pointerExternal, symbol.pointerExternal.type == functionExternal);
6946 //findSymbolTotalTime += GetTime() - startTime;
6951 static void GetTypeSpecs(Type type, OldList * specs)
6953 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6958 if(type._class.registered)
6960 if(!type._class.registered.dataType)
6961 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6962 GetTypeSpecs(type._class.registered.dataType, specs);
6966 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6967 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6968 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6969 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6970 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6971 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6972 case int128Type: ListAdd(specs, MkSpecifier(INT128)); break;
6973 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6974 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6977 ListAdd(specs, MkSpecifier(INT)); break;
6981 static void PrintArraySize(Type arrayType, char * string)
6986 if(arrayType.enumClass)
6987 strcat(size, arrayType.enumClass.string);
6988 else if(arrayType.arraySizeExp)
6989 PrintExpression(arrayType.arraySizeExp, size);
6991 strcat(string, size);
6994 // WARNING : This function expects a null terminated string since it recursively concatenate...
6995 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6999 if(printConst && type.constant)
7000 strcat(string, "const ");
7005 Symbol c = type._class;
7006 bool isObjectBaseClass = !c || !c.string || !strcmp(c.string, "class");
7007 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
7008 // look into merging with thisclass ?
7009 if(type.classObjectType == typedObject && isObjectBaseClass)
7010 strcat(string, "typed_object");
7011 else if(type.classObjectType == anyObject && isObjectBaseClass)
7012 strcat(string, "any_object");
7016 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
7018 if(type.byReference)
7019 strcat(string, " &");
7022 case voidType: strcat(string, "void"); break;
7023 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
7024 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
7025 case int128Type: strcat(string, type.isSigned ? "__int128" : "unsigned __int128"); break;
7026 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
7027 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
7028 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
7029 case _BoolType: strcat(string, "_Bool"); break;
7030 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
7031 case floatType: strcat(string, "float"); break;
7032 case doubleType: strcat(string, "double"); break;
7036 strcat(string, "struct ");
7037 strcat(string, type.enumName);
7039 else if(type.typeName)
7040 strcat(string, type.typeName);
7044 strcat(string, "struct { ");
7045 for(member = type.members.first; member; member = member.next)
7047 PrintType(member, string, true, fullName);
7048 strcat(string,"; ");
7056 strcat(string, "union ");
7057 strcat(string, type.enumName);
7059 else if(type.typeName)
7060 strcat(string, type.typeName);
7063 strcat(string, "union ");
7064 strcat(string,"(unnamed)");
7070 strcat(string, "enum ");
7071 strcat(string, type.enumName);
7073 else if(type.typeName)
7074 strcat(string, type.typeName);
7076 strcat(string, "int"); // "enum");
7079 strcat(string, "...");
7082 strcat(string, "subclass(");
7083 strcat(string, type._class ? type._class.string : "int");
7084 strcat(string, ")");
7087 strcat(string, type.templateParameter.identifier.string);
7090 strcat(string, "thisclass");
7093 strcat(string, "__builtin_va_list");
7099 static void PrintName(Type type, char * string, bool fullName)
7101 if(type.name && type.name[0])
7104 strcat(string, type.name);
7107 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
7108 if(name) name += 2; else name = type.name;
7109 strcat(string, name);
7114 static void PrintAttribs(Type type, char * string)
7118 if(type.dllExport) strcat(string, "dllexport ");
7119 if(type.attrStdcall) strcat(string, "stdcall ");
7123 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7125 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7127 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7128 PrintAttribs(type, string);
7129 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7130 strcat(string, " const");
7131 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7132 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7133 strcat(string, " (");
7134 if(type.kind == pointerType)
7136 if(type.type.kind == functionType || type.type.kind == methodType)
7137 PrintAttribs(type.type, string);
7139 if(type.kind == pointerType)
7141 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7142 strcat(string, "*");
7144 strcat(string, " *");
7146 if(printConst && type.constant && type.kind == pointerType)
7147 strcat(string, " const");
7150 PrintTypeSpecs(type, string, fullName, printConst);
7153 static void PostPrintType(Type type, char * string, bool fullName)
7155 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7156 strcat(string, ")");
7157 if(type.kind == arrayType)
7158 PrintArraySize(type, string);
7159 else if(type.kind == functionType)
7162 strcat(string, "(");
7163 for(param = type.params.first; param; param = param.next)
7165 PrintType(param, string, true, fullName);
7166 if(param.next) strcat(string, ", ");
7168 strcat(string, ")");
7170 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7171 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7175 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7177 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7179 PrePrintType(type, string, fullName, null, printConst);
7181 if(type.thisClass || (printName && type.name && type.name[0]))
7182 strcat(string, " ");
7183 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7185 Symbol _class = type.thisClass;
7186 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7188 if(type.classObjectType == classPointer)
7189 strcat(string, "class");
7191 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7193 else if(_class && _class.string)
7195 String s = _class.string;
7200 char * name = RSearchString(s, "::", strlen(s), true, false);
7201 if(name) name += 2; else name = s;
7202 strcat(string, name);
7205 strcat(string, "::");
7208 if(printName && type.name)
7209 PrintName(type, string, fullName);
7210 PostPrintType(type, string, fullName);
7211 if(type.bitFieldCount)
7214 sprintf(count, ":%d", type.bitFieldCount);
7215 strcat(string, count);
7219 void PrintType(Type type, char * string, bool printName, bool fullName)
7221 _PrintType(type, string, printName, fullName, true);
7224 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7226 _PrintType(type, string, printName, fullName, false);
7229 static Type FindMember(Type type, char * string)
7232 for(memberType = type.members.first; memberType; memberType = memberType.next)
7234 if(!memberType.name)
7236 Type subType = FindMember(memberType, string);
7240 else if(!strcmp(memberType.name, string))
7246 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7249 for(memberType = type.members.first; memberType; memberType = memberType.next)
7251 if(!memberType.name)
7253 Type subType = FindMember(memberType, string);
7256 *offset += memberType.offset;
7260 else if(!strcmp(memberType.name, string))
7262 *offset += memberType.offset;
7269 public bool GetParseError() { return parseError; }
7271 Expression ParseExpressionString(char * expression)
7275 fileInput = TempFile { };
7276 fileInput.Write(expression, 1, strlen(expression));
7277 fileInput.Seek(0, start);
7280 parsedExpression = null;
7282 expression_yyparse();
7285 return parsedExpression;
7288 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7290 Identifier id = exp.identifier;
7291 Method method = null;
7292 Property prop = null;
7293 DataMember member = null;
7294 ClassProperty classProp = null;
7296 if(_class && _class.type == enumClass)
7298 NamedLink64 value = null;
7299 Class enumClass = eSystem_FindClass(privateModule, "enum");
7303 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7305 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7306 for(value = e.values.first; value; value = value.next)
7308 if(!strcmp(value.name, id.string))
7313 exp.isConstant = true;
7314 if(inCompiler || inPreCompiler || inDebugger)
7317 FreeExpContents(exp);
7319 exp.type = constantExp;
7320 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "char") || !strcmp(baseClass.dataTypeString, "short"))
7321 sprintf(constant, FORMAT64D, value.data);
7323 sprintf(constant, FORMAT64HEX, value.data);
7324 exp.constant = CopyString(constant);
7326 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7327 exp.expType = MkClassType(baseClass.fullName);
7335 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7337 ProcessMethodType(method);
7344 // TOCHECK: Put it back to what it was...
7345 // methodClass = _class;
7346 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7351 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7354 ProcessPropertyType(prop);
7355 exp.expType = prop.dataType;
7356 if(prop.dataType) prop.dataType.refCount++;
7359 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7361 if(!member.dataType)
7362 member.dataType = ProcessTypeString(member.dataTypeString, false);
7363 exp.expType = member.dataType;
7364 if(member.dataType) member.dataType.refCount++;
7367 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7369 if(!classProp.dataType)
7370 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7372 if(classProp.constant)
7374 FreeExpContents(exp);
7376 exp.isConstant = true;
7377 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7379 //char constant[256];
7380 exp.type = stringExp;
7381 exp.constant = QMkString((char *)(uintptr)classProp.Get(_class));
7386 exp.type = constantExp;
7387 sprintf(constant, "%d", (int)classProp.Get(_class));
7388 exp.constant = CopyString(constant);
7396 exp.expType = classProp.dataType;
7397 if(classProp.dataType) classProp.dataType.refCount++;
7403 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7405 BinaryTree * tree = &nameSpace.functions;
7406 GlobalData data = (GlobalData)tree->FindString(name);
7410 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7412 data = ScanGlobalData(child, name);
7420 static GlobalData FindGlobalData(char * name)
7423 NameSpace * nameSpace;
7424 nameSpace = globalData;
7425 for(c = 0; name[c]; c++)
7427 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7429 NameSpace * newSpace;
7430 char * spaceName = new char[c - start + 1];
7431 strncpy(spaceName, name + start, c - start);
7432 spaceName[c-start] = '\0';
7433 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7437 nameSpace = newSpace;
7438 if(name[c] == ':') c++;
7442 if(nameSpace && c - start)
7444 return ScanGlobalData(nameSpace, name + start);
7449 static int definedExpStackPos;
7450 static void * definedExpStack[512];
7452 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7453 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7455 Expression prev = checkedExp.prev, next = checkedExp.next;
7457 FreeExpContents(checkedExp);
7458 FreeType(checkedExp.expType);
7459 FreeType(checkedExp.destType);
7461 *checkedExp = *newExp;
7465 checkedExp.prev = prev;
7466 checkedExp.next = next;
7469 void ApplyAnyObjectLogic(Expression e)
7471 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7473 char debugExpString[4096];
7474 debugExpString[0] = '\0';
7475 PrintExpression(e, debugExpString);
7478 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7480 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7481 //ellipsisDestType = destType;
7484 Type type = e.expType;
7485 Class _class = null;
7486 //Type destType = e.destType;
7488 if(type.kind == classType && type._class && type._class.registered)
7490 _class = type._class.registered;
7492 else if(type.kind == subClassType)
7494 _class = FindClass("ecere::com::Class").registered;
7498 char string[1024] = "";
7501 PrintTypeNoConst(type, string, false, true);
7502 classSym = FindClass(string);
7503 if(classSym) _class = classSym.registered;
7506 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...
7507 (!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))) ||
7508 destType.byReference)))
7510 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7512 Expression checkedExp = e, newExp;
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 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7531 newExp = checkedExp.op.exp2;
7532 checkedExp.op.exp2 = null;
7533 FreeExpContents(checkedExp);
7535 if(e.expType && e.expType.passAsTemplate)
7538 ComputeTypeSize(e.expType);
7539 sprintf(size, "%d", e.expType.size); // Potential 32/64 Bootstrap issue
7540 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7541 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7542 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7545 ReplaceExpContents(checkedExp, newExp);
7546 e.byReference = true;
7548 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7550 Expression checkedExp; //, newExp;
7553 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7555 e.type == identifierExp ||
7556 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7557 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7558 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7561 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7563 Context context = PushContext();
7565 OldList * specs = MkList();
7566 char typeString[1024];
7567 Expression newExp { };
7569 typeString[0] = '\0';
7572 //if(e.destType) e.destType.refCount++;
7573 // if(exp.expType) exp.expType.refCount++;
7576 newExp.expType = null;
7578 PrintTypeNoConst(e.expType, typeString, false, true);
7579 decl = SpecDeclFromString(typeString, specs, null);
7580 newExp.destType = ProcessType(specs, decl);
7582 curContext = context;
7584 // We need a current compound for this
7588 OldList * stmts = MkList();
7589 e.type = extensionCompoundExp;
7590 sprintf(name, "__internalValue%03X", internalValueCounter++);
7591 if(!curCompound.compound.declarations)
7592 curCompound.compound.declarations = MkList();
7593 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7594 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7595 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7596 e.compound = MkCompoundStmt(null, stmts);
7599 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7602 e.compound = MkCompoundStmt(
7603 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7604 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7606 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7610 Type type = e.destType;
7612 CopyTypeInto(e.destType, type);
7613 e.destType.refCount = 1;
7614 e.destType.classObjectType = none;
7618 e.compound.compound.context = context;
7619 PopContext(context);
7620 curContext = context.parent;
7624 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7626 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7628 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7630 if(checkedExp.type == extensionCompoundExp)
7632 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7635 checkedExp = checkedExp.list->last;
7637 else if(checkedExp.type == castExp)
7638 checkedExp = checkedExp.cast.exp;
7641 Expression operand { };
7642 operand = *checkedExp;
7644 checkedExp.destType = ProcessTypeString("void *", false);
7645 checkedExp.expType = checkedExp.destType;
7646 checkedExp.destType.refCount++;
7648 checkedExp.type = opExp;
7649 checkedExp.op.op = '&';
7650 checkedExp.op.exp1 = null;
7651 checkedExp.op.exp2 = operand;
7653 //newExp = MkExpOp(null, '&', checkedExp);
7655 //ReplaceExpContents(checkedExp, newExp);
7662 // If expression type is a simple class, make it an address
7663 // FixReference(e, true);
7666 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7667 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7668 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7670 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"))
7672 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7676 Expression thisExp { };
7679 thisExp.prev = null;
7680 thisExp.next = null;
7683 e.type = bracketsExp;
7684 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7685 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7686 ((Expression)e.list->first).byReference = true;
7688 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7690 e.expType = thisExp.expType;
7691 e.expType.refCount++;
7696 CopyTypeInto(e.expType, thisExp.expType);
7697 e.expType.byReference = false;
7698 e.expType.refCount = 1;
7700 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7701 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7703 e.expType.classObjectType = none;
7708 // TOFIX: Try this for a nice IDE crash!
7710 // The other way around
7713 if(destType && e.expType &&
7714 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7715 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7716 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7718 if(destType.kind == ellipsisType)
7720 Compiler_Error($"Unspecified type\n");
7722 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7724 bool byReference = e.expType.byReference;
7725 Expression thisExp { };
7727 OldList * specs = MkList();
7728 char typeString[1024]; // Watch buffer overruns
7730 ClassObjectType backupClassObjectType;
7731 bool backupByReference;
7733 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7738 backupClassObjectType = type.classObjectType;
7739 backupByReference = type.byReference;
7741 type.classObjectType = none;
7742 type.byReference = false;
7744 typeString[0] = '\0';
7745 PrintType(type, typeString, false, true);
7746 decl = SpecDeclFromString(typeString, specs, null);
7748 type.classObjectType = backupClassObjectType;
7749 type.byReference = backupByReference;
7752 thisExp.prev = null;
7753 thisExp.next = null;
7756 if( ( type.kind == classType && type._class && type._class.registered &&
7757 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7758 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7759 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7760 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7762 bool passAsTemplate = thisExp.destType.passAsTemplate;
7765 destType.refCount++;
7770 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7773 CopyTypeInto(t, thisExp.destType);
7774 t.passAsTemplate = false;
7775 FreeType(thisExp.destType);
7776 thisExp.destType = t;
7779 CopyTypeInto(t, destType);
7780 t.passAsTemplate = passAsTemplate;
7783 destType.refCount = 0;
7786 CopyTypeInto(e.expType, type);
7787 if(type.passAsTemplate)
7789 e.expType.classObjectType = none;
7790 e.expType.passAsTemplate = false;
7792 e.expType.byReference = false;
7793 e.expType.refCount = 1;
7798 e.cast.typeName = MkTypeName(specs, decl);
7799 e.cast.exp = thisExp;
7800 e.byReference = true;
7806 FreeType(e.destType);
7808 e.destType = destType;
7809 destType.refCount++;
7814 void ApplyLocation(Expression exp, Location loc)
7820 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7821 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7827 for(e = exp.list->first; e; e = e.next)
7828 ApplyLocation(e, loc);
7835 for(e = exp.index.index->first; e; e = e.next)
7836 ApplyLocation(e, loc);
7839 ApplyLocation(exp.index.exp, loc);
7842 if(exp.call.arguments)
7845 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7846 ApplyLocation(arg, loc);
7849 ApplyLocation(exp.call.exp, loc);
7854 ApplyLocation(exp.member.exp, loc);
7858 ApplyLocation(exp.cast.exp, loc);
7864 for(e = exp.cond.exp->first; e; e = e.next)
7865 ApplyLocation(e, loc);
7868 ApplyLocation(exp.cond.cond, loc);
7869 if(exp.cond.elseExp)
7870 ApplyLocation(exp.cond.elseExp, loc);
7874 ApplyLocation(exp.vaArg.exp, loc);
7881 bool RelatedUnits(Class c1, Class c2)
7883 if(c1.base.type == unitClass) c1 = c1.base;
7884 if(c2.base.type == unitClass) c2 = c2.base;
7888 void ProcessExpressionType(Expression exp)
7890 bool unresolved = false;
7891 Location oldyylloc = yylloc;
7892 bool notByReference = false;
7894 char debugExpString[4096];
7895 debugExpString[0] = '\0';
7896 PrintExpression(exp, debugExpString);
7898 if(!exp || exp.expType)
7901 //eSystem_Logf("%s\n", expString);
7903 // Testing this here
7909 Identifier id = exp.identifier;
7910 if(!id || !topContext) return;
7912 // DOING THIS LATER NOW...
7913 if(id._class && id._class.name)
7915 id.classSym = id._class.symbol; // FindClass(id._class.name);
7916 /* TODO: Name Space Fix ups
7918 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7922 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7924 exp.expType = ProcessTypeString("Module", true);
7928 if(!strcmp(id.string, "__runtimePlatform"))
7930 exp.expType = ProcessTypeString("ecere::com::Platform", true);
7933 else if(strstr(id.string, "__ecereClass") == id.string)
7935 exp.expType = ProcessTypeString("ecere::com::Class", true);
7938 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7940 // Added this here as well
7941 ReplaceClassMembers(exp, thisClass);
7942 if(exp.type != identifierExp)
7944 ProcessExpressionType(exp);
7948 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7953 Symbol symbol = null;
7954 bool findInGlobal = false;
7955 if(!topContext.parent && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == enumClass)
7956 findInGlobal = true; // In global context, look at enum values first
7958 symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7960 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7961 if(!symbol/* && exp.destType*/)
7963 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7967 if(thisClass && strcmp(id.string, "this"))
7969 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7970 if(exp.type != identifierExp)
7972 ProcessExpressionType(exp);
7976 // Static methods called from inside the _class
7977 else if(currentClass && !id._class)
7979 if(ResolveIdWithClass(exp, currentClass, true))
7982 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7986 symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7988 // If we manage to resolve this symbol
7991 Type type = symbol.type;
7992 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7994 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7996 Context context = SetupTemplatesContext(_class);
7997 type = ReplaceThisClassType(_class);
7998 FinishTemplatesContext(context);
7999 if(type) type.refCount = 0; // We'll be incrementing it right below...
8002 FreeSpecifier(id._class);
8005 id.string = CopyString(symbol.string);
8012 // Commented this out, it was making non-constant enum parameters seen as constant
8013 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
8014 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
8015 // Add missing cases here... enum Classes...
8016 exp.isConstant = true;
8018 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
8019 if(symbol.isParam || !strcmp(id.string, "this"))
8021 if(_class && _class.type == structClass && !type.declaredWithStruct)
8022 exp.byReference = true;
8024 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
8025 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
8026 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
8027 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
8029 Identifier id = exp.identifier;
8030 exp.type = bracketsExp;
8031 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
8035 if(symbol.isIterator)
8037 if(symbol.isIterator == 3)
8039 exp.type = bracketsExp;
8040 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
8041 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
8043 ProcessExpressionType(exp);
8045 else if(symbol.isIterator != 4)
8047 exp.type = memberExp;
8048 exp.member.exp = MkExpIdentifier(exp.identifier);
8049 exp.member.exp.expType = exp.expType;
8050 /*if(symbol.isIterator == 6)
8051 exp.member.member = MkIdentifier("key");
8053 exp.member.member = MkIdentifier("data");
8055 ProcessExpressionType(exp);
8062 DefinedExpression definedExp = null;
8063 if(thisNameSpace && !(id._class && !id._class.name))
8066 strcpy(name, thisNameSpace);
8068 strcat(name, id.string);
8069 definedExp = eSystem_FindDefine(privateModule, name);
8072 definedExp = eSystem_FindDefine(privateModule, id.string);
8076 for(c = 0; c<definedExpStackPos; c++)
8077 if(definedExpStack[c] == definedExp)
8079 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
8081 Location backupYylloc = yylloc;
8082 File backInput = fileInput;
8083 definedExpStack[definedExpStackPos++] = definedExp;
8085 fileInput = TempFile { };
8086 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
8087 fileInput.Seek(0, start);
8090 parsedExpression = null;
8092 expression_yyparse();
8095 fileInput = backInput;
8097 yylloc = backupYylloc;
8099 if(parsedExpression)
8102 exp.type = bracketsExp;
8103 exp.list = MkListOne(parsedExpression);
8104 ApplyLocation(parsedExpression, yylloc);
8105 ProcessExpressionType(exp);
8106 definedExpStackPos--;
8109 definedExpStackPos--;
8115 Compiler_Error($"Recursion in defined expression %s\n", id.string);
8121 GlobalData data = null;
8122 if(thisNameSpace && !(id._class && !id._class.name))
8125 strcpy(name, thisNameSpace);
8127 strcat(name, id.string);
8128 data = FindGlobalData(name);
8131 data = FindGlobalData(id.string);
8134 DeclareGlobalData(curExternal, data);
8135 exp.expType = data.dataType;
8136 if(data.dataType) data.dataType.refCount++;
8139 id.string = CopyString(data.fullName);
8140 FreeSpecifier(id._class);
8147 GlobalFunction function = null;
8148 if(thisNameSpace && !(id._class && !id._class.name))
8151 strcpy(name, thisNameSpace);
8153 strcat(name, id.string);
8154 function = eSystem_FindFunction(privateModule, name);
8157 function = eSystem_FindFunction(privateModule, id.string);
8162 id.string = CopyString(function.name);
8165 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8166 strcpy(name, "__ecereFunction_");
8167 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8168 if(DeclareFunction(curExternal, function, name))
8171 id.string = CopyString(name);
8173 exp.expType = function.dataType;
8174 if(function.dataType) function.dataType.refCount++;
8176 FreeSpecifier(id._class);
8193 if(!exp.instance._class)
8195 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8197 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8201 //classSym = FindClass(exp.instance._class.fullName);
8202 //_class = classSym ? classSym.registered : null;
8204 ProcessInstantiationType(exp.instance);
8206 exp.isConstant = exp.instance.isConstant;
8209 if(_class.type == unitClass && _class.base.type != systemClass)
8212 Type destType = exp.destType;
8214 exp.destType = MkClassType(_class.base.fullName);
8215 exp.expType = MkClassType(_class.fullName);
8216 CheckExpressionType(exp, exp.destType, true);
8218 exp.destType = destType;
8220 exp.expType = MkClassType(_class.fullName);
8223 if(exp.instance._class)
8225 exp.expType = MkClassType(exp.instance._class.name);
8226 /*if(exp.expType._class && exp.expType._class.registered &&
8227 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8228 exp.expType.byReference = true;*/
8236 char * constant = exp.constant;
8244 if(constant[0] == '\'')
8246 if((int)((byte *)constant)[1] > 127)
8249 unichar ch = UTF8GetChar(constant + 1, &nb);
8250 if(nb < 2) ch = constant[1];
8252 exp.constant = PrintUInt(ch);
8253 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8254 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8255 type._class = FindClass("unichar");
8257 type.isSigned = false;
8261 type.kind = charType;
8262 type.isSigned = true;
8267 char * dot = strchr(constant, '.');
8268 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8272 exponent = strchr(constant, 'p');
8273 if(!exponent) exponent = strchr(constant, 'P');
8277 exponent = strchr(constant, 'e');
8278 if(!exponent) exponent = strchr(constant, 'E');
8283 if(strchr(constant, 'f') || strchr(constant, 'F'))
8284 type.kind = floatType;
8286 type.kind = doubleType;
8287 type.isSigned = true;
8291 bool isSigned = constant[0] == '-';
8293 int64 i64 = strtoll(constant, &endP, 0);
8294 uint64 ui64 = strtoull(constant, &endP, 0);
8295 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll") || !strcmp(endP, "LLU") || !strcmp(endP, "llu") || !strcmp(endP, "ull") || !strcmp(endP, "ULL"));
8296 bool forceUnsigned = endP && (!strcmp(endP, "U") || !strcmp(endP, "u") || !strcmp(endP, "LLU") || !strcmp(endP, "llu") || !strcmp(endP, "ull") || !strcmp(endP, "ULL"));
8309 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8313 else if(constant[0] != '0' || !constant[1])
8318 type.kind = is64Bit ? int64Type : intType;
8319 type.isSigned = isSigned;
8322 exp.isConstant = true;
8323 if(exp.destType && exp.destType.kind == doubleType)
8324 type.kind = doubleType;
8325 else if(exp.destType && exp.destType.kind == floatType)
8326 type.kind = floatType;
8327 else if(exp.destType && exp.destType.kind == int64Type)
8328 type.kind = int64Type;
8334 exp.isConstant = true; // Why wasn't this constant?
8342 kind = exp.wideString ? shortType : charType;
8344 isSigned = exp.wideString ? false : true;
8351 ProcessExpressionType(exp._new.size);
8356 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8358 DeclareType(curExternal, exp.expType.type, true, false);
8362 ProcessExpressionType(exp._renew.size);
8363 ProcessExpressionType(exp._renew.exp);
8368 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8370 DeclareType(curExternal, exp.expType.type, true, false);
8374 bool assign = false, boolResult = false, boolOps = false;
8375 Type type1 = null, type2 = null;
8376 bool useDestType = false, useSideType = false;
8377 Location oldyylloc = yylloc;
8378 bool useSideUnit = false;
8379 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8380 bool powerOp = false, relationOp = false;
8381 Class c1 = null, c2 = null;
8383 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8392 // Assignment Operators
8406 // boolean Operators
8408 // Expect boolean operators
8410 //boolResult = true;
8414 // Expect boolean operands
8425 // Gives boolean result
8439 // useSideType = true;
8440 // useDestType = true;
8453 if(exp.op.op == '/') powerOp = true;
8459 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8462 if(exp.op.op == '*') powerOp = true;
8466 /*// Implement speed etc.
8472 if(exp.op.op == '&')
8474 // Added this here earlier for Iterator address as key
8475 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8477 Identifier id = exp.op.exp2.identifier;
8478 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8479 if(symbol && symbol.isIterator == 2)
8481 exp.type = memberExp;
8482 exp.member.exp = exp.op.exp2;
8483 exp.member.member = MkIdentifier("key");
8485 exp.op.exp2.expType = symbol.type;
8486 symbol.type.refCount++;
8487 ProcessExpressionType(exp);
8491 // exp.op.exp2.usage.usageRef = true;
8495 //dummy.kind = TypeDummy;
8498 // Added this check here to use the dest type only for units derived from the base unit
8499 // So that untyped units will use the side unit as opposed to the untyped destination unit
8500 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8501 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8502 useDestType = false;
8504 if(destClass && useDestType &&
8505 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8507 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8509 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8510 exp.op.exp1.destType = exp.destType;
8511 exp.op.exp1.opDestType = true;
8513 exp.destType.refCount++;
8517 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8518 exp.op.exp1.destType = dummy;
8521 exp.op.exp1.opDestType = true;
8523 exp.op.exp1.usedInComparison = true;
8525 if(exp.op.op == '+' || exp.op.op == '-')
8528 exp.op.exp1.parentOpDestType = true;
8529 if(exp.usedInComparison)
8530 exp.op.exp1.usedInComparison = true;
8533 // TESTING THIS HERE...
8534 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8535 ProcessExpressionType(exp.op.exp1);
8536 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8538 exp.op.exp1.opDestType = false;
8539 exp.op.exp1.usedInComparison = false;
8541 // Fix for unit and ++ / --
8542 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8543 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8545 exp.op.exp2 = MkExpConstant("1");
8546 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8550 if(exp.op.exp1.destType == dummy)
8553 exp.op.exp1.destType = null;
8558 if(!assign && exp.op.exp1.expType && (exp.op.exp1.expType.kind == charType || exp.op.exp1.expType.kind == shortType))
8560 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 };
8561 FreeType(exp.op.exp1.expType);
8562 exp.op.exp1.expType = type;
8566 type1 = exp.op.exp1.expType;
8571 char expString[10240];
8572 expString[0] = '\0';
8573 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8577 exp.op.exp2.destType = exp.op.exp1.expType;
8578 if(exp.op.exp1.expType)
8579 exp.op.exp1.expType.refCount++;
8583 exp.op.exp2.destType = exp.destType;
8584 if(!exp.op.exp1 || (exp.op.op != '&' && exp.op.op != '^'))
8585 exp.op.exp2.opDestType = true;
8587 exp.destType.refCount++;
8590 if(type1) type1.refCount++;
8591 exp.expType = type1;
8596 PrintExpression(exp.op.exp2, expString);
8598 if(type1 && type1.kind == pointerType)
8600 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 ||
8601 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8602 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8603 else if(exp.op.op == '=')
8605 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8606 exp.op.exp2.destType = type1;
8613 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8614 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/* ||
8615 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8618 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8619 exp.op.exp2.destType = type1;
8624 if(type1) type1.refCount++;
8625 exp.expType = type1;
8627 else if(destClass &&
8628 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8629 (destClass.type == enumClass && useDestType)))
8631 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8632 exp.op.exp2.destType = exp.destType;
8633 if(exp.op.op != '&' && exp.op.op != '^')
8634 exp.op.exp2.opDestType = true;
8636 exp.destType.refCount++;
8640 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8641 exp.op.exp2.destType = dummy;
8644 exp.op.exp2.opDestType = true;
8646 exp.op.exp2.usedInComparison = true;
8649 // TESTING THIS HERE... (DANGEROUS)
8650 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8651 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8653 FreeType(exp.op.exp2.destType);
8654 exp.op.exp2.destType = type1;
8657 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8658 // Cannot lose the cast on a sizeof
8659 if(exp.op.op == SIZEOF)
8661 Expression e = exp.op.exp2;
8662 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8664 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8666 if(e.type == extensionCompoundExp)
8667 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8672 if(e.type == castExp && e.cast.exp)
8673 e.cast.exp.needCast = true;
8675 if(exp.op.op == '+' || exp.op.op == '-')
8678 exp.op.exp2.parentOpDestType = true;
8679 if(exp.usedInComparison)
8680 exp.op.exp2.usedInComparison = true;
8682 ProcessExpressionType(exp.op.exp2);
8683 exp.op.exp2.opDestType = false;
8684 exp.op.exp2.usedInComparison = false;
8685 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8687 if(!assign && (exp.op.exp1 || exp.op.op == '~'))
8689 if(exp.op.exp2.expType && (exp.op.exp2.expType.kind == charType || exp.op.exp2.expType.kind == shortType))
8691 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 };
8692 FreeType(exp.op.exp2.expType);
8693 exp.op.exp2.expType = type;
8697 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8699 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)
8701 if(exp.op.op != '=' && type1.type.kind == voidType)
8702 Compiler_Error($"void *: unknown size\n");
8704 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||
8705 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8706 (exp.op.exp2.expType._class.registered.type == normalClass ||
8707 exp.op.exp2.expType._class.registered.type == structClass ||
8708 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8710 if(exp.op.op == ADD_ASSIGN)
8711 Compiler_Error($"cannot add two pointers\n");
8713 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8714 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8716 if(exp.op.op == ADD_ASSIGN)
8717 Compiler_Error($"cannot add two pointers\n");
8721 char type1String[1024];
8722 char type2String[1024];
8723 type1String[0] = '\0';
8724 type2String[0] = '\0';
8726 PrintType(exp.op.exp2.expType, type1String, false, true);
8727 PrintType(type1, type2String, false, true);
8728 ChangeCh(expString, '\n', ' ');
8729 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8733 if(exp.op.exp2.destType == dummy)
8736 exp.op.exp2.destType = null;
8739 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8743 CopyTypeInto(type2, exp.op.exp2.expType);
8744 type2.isSigned = true;
8746 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8748 type2 = { kind = intType };
8750 type2.isSigned = true;
8754 type2 = exp.op.exp2.expType;
8755 if(type2) type2.refCount++;
8758 c1 = type1 && type1.kind == classType && type1._class ? type1._class.registered : null;
8759 c2 = type2 && type2.kind == classType && type2._class ? type2._class.registered : null;
8762 ( (exp.op.exp1 && exp.op.exp1.ambiguousUnits && (!c2 || c2.type != unitClass)) ||
8763 (exp.op.exp2 && exp.op.exp2.ambiguousUnits && (!c1 || c1.type != unitClass))) )
8764 Compiler_Warning($"ambiguous units in relational operation\n");
8767 ((exp.op.exp1 && exp.op.exp1.ambiguousUnits) ||
8768 (exp.op.exp2 && exp.op.exp2.ambiguousUnits)) &&
8769 (!powerOp || !c1 || c1.type != unitClass || !c2 || c2.type != unitClass || !RelatedUnits(c1, c2)))
8771 if(exp.opDestType || exp.usedInComparison)
8772 exp.ambiguousUnits = true;
8774 Compiler_Warning($"ambiguous units\n");
8777 dummy.kind = voidType;
8779 if(exp.op.op == SIZEOF)
8786 exp.isConstant = true;
8788 // Get type of dereferenced pointer
8789 else if(exp.op.op == '*' && !exp.op.exp1)
8791 exp.expType = Dereference(type2);
8792 if(type2 && type2.kind == classType)
8793 notByReference = true;
8795 else if(exp.op.op == '&' && !exp.op.exp1)
8796 exp.expType = Reference(type2);
8797 else if(exp.op.op == LEFT_OP || exp.op.op == RIGHT_OP)
8799 if(exp.op.exp1.expType)
8801 exp.expType = exp.op.exp1.expType;
8802 exp.expType.refCount++;
8807 if(c1 && !c1.dataType)
8808 c1.dataType = ProcessTypeString(c1.dataTypeString, false);
8809 if(c2 && !c2.dataType)
8810 c2.dataType = ProcessTypeString(c2.dataTypeString, false);
8816 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8817 exp.op.exp1.destType = MkClassType("bool");
8818 exp.op.exp1.destType.truth = true;
8819 if(!exp.op.exp1.expType)
8820 ProcessExpressionType(exp.op.exp1);
8822 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8823 FreeType(exp.op.exp1.expType);
8824 exp.op.exp1.expType = MkClassType("bool");
8825 exp.op.exp1.expType.truth = true;
8829 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8830 exp.op.exp2.destType = MkClassType("bool");
8831 exp.op.exp2.destType.truth = true;
8832 if(!exp.op.exp2.expType)
8833 ProcessExpressionType(exp.op.exp2);
8835 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8836 FreeType(exp.op.exp2.expType);
8837 exp.op.exp2.expType = MkClassType("bool");
8838 exp.op.exp2.expType.truth = true;
8841 else if(powerOp && exp.op.exp1 && exp.op.exp2 && ((c1 && c1.type == unitClass) || (c2 && c2.type == unitClass)))
8843 // * or / with at least one unit operand
8844 if(c1 && c1.type == unitClass && c2 && c2.type == unitClass)
8846 // This is where we'd handle unit powers e.g. square meters or meters/seconds
8847 // For now using base types
8848 if(c1.dataType.kind == doubleType) exp.expType = c1.dataType;
8849 else if(c2.dataType.kind == doubleType) exp.expType = c2.dataType;
8850 else if(c1.dataType.kind == floatType) exp.expType = c1.dataType;
8851 else if(c2.dataType.kind == floatType) exp.expType = c2.dataType;
8853 exp.expType = c1.dataType;
8855 else if((c1 && c1.type == unitClass) || exp.op.op == '/') // 1/units should not be typed with unit
8856 exp.expType = type1;
8858 exp.expType = type2;
8861 exp.expType.refCount++;
8863 else if(exp.op.exp1 && exp.op.exp2 &&
8866 ((!c1 || c1.type != unitClass) &&
8867 (!c2 || c2.type != unitClass)))*/) ||
8868 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8869 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8871 if(type1 && type2 &&
8872 // If either both are class or both are not class
8873 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8875 // Added this check for enum subtraction to result in an int type:
8876 if(exp.op.op == '-' && ((c1 && c1.type == enumClass) || (c2 && c2.type == enumClass)) )
8878 Type intType = ProcessTypeString((c1 && c1.dataType.kind == int64Type) || (c2 && c2.dataType.kind == int64Type) ? "int64" : "int", false);
8880 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8881 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8882 exp.op.exp1.destType = intType;
8883 exp.op.exp2.destType = intType;
8888 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8889 exp.op.exp2.destType = type1;
8891 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8892 exp.op.exp1.destType = type2;
8896 // Warning here for adding Radians + Degrees with no destination type
8897 if(!boolResult && !exp.opDestType && (!exp.destType || exp.destType.kind != classType) &&
8898 c1 && c1.type == unitClass &&
8899 c2 && c2.type == unitClass &&
8902 if(exp.usedInComparison || exp.parentOpDestType)
8903 exp.ambiguousUnits = true;
8905 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8906 type1._class.string, type2._class.string, type1._class.string);
8909 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8911 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, type1.type.thisClassFrom, thisClass, true);
8914 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8916 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8917 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8920 ProcessExpressionType(exp.op.exp1);
8922 if(type2.kind != pointerType)
8924 ProcessExpressionType(classExp);
8926 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8928 if(!exp.op.exp2.expType)
8932 type2 = exp.op.exp2.expType = ProcessTypeString("int", false); c2 = null;
8936 ProcessExpressionType(exp.op.exp2);
8941 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)))
8943 if(type1.kind != classType && type1.type.kind == voidType)
8944 Compiler_Error($"void *: unknown size\n");
8945 exp.expType = type1;
8946 if(type1) type1.refCount++;
8948 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)))
8950 if(type2.kind != classType && type2.type.kind == voidType)
8951 Compiler_Error($"void *: unknown size\n");
8952 exp.expType = type2;
8953 if(type2) type2.refCount++;
8955 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8956 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8958 Compiler_Warning($"different levels of indirection\n");
8962 bool success = false;
8963 if(type1.kind == pointerType && type2.kind == pointerType)
8965 if(exp.op.op == '+')
8966 Compiler_Error($"cannot add two pointers\n");
8967 else if(exp.op.op == '-')
8969 // Pointer Subtraction gives integer
8970 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8979 if(type1.type.kind == templateType)
8981 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, type1.type.thisClassFrom, thisClass, true);
8984 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8986 ProcessExpressionType(classExp);
8988 exp.type = bracketsExp;
8989 exp.list = MkListOne(MkExpOp(
8990 MkExpBrackets(MkListOne(MkExpOp(
8991 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8993 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8994 MkExpMember(classExp, MkIdentifier("typeSize"))));
8996 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
9005 if(!success && exp.op.exp1.type == constantExp)
9007 // If first expression is constant, try to match that first
9008 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9010 if(exp.expType) FreeType(exp.expType);
9011 exp.expType = exp.op.exp1.destType;
9012 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9015 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
9017 if(exp.expType) FreeType(exp.expType);
9018 exp.expType = exp.op.exp2.destType;
9019 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
9025 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
9027 if(exp.expType) FreeType(exp.expType);
9028 exp.expType = exp.op.exp2.destType;
9029 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
9032 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9034 if(exp.expType) FreeType(exp.expType);
9035 exp.expType = exp.op.exp1.destType;
9036 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9042 char expString1[10240];
9043 char expString2[10240];
9046 expString1[0] = '\0';
9047 expString2[0] = '\0';
9052 PrintExpression(exp.op.exp1, expString1);
9053 ChangeCh(expString1, '\n', ' ');
9054 PrintExpression(exp.op.exp2, expString2);
9055 ChangeCh(expString2, '\n', ' ');
9056 PrintType(exp.op.exp1.expType, type1, false, true);
9057 PrintType(exp.op.exp2.expType, type2, false, true);
9060 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
9064 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
9065 else if(!boolResult && !useSideUnit && c2 && c2.type == unitClass && type1 && type1.kind != classType)
9067 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9068 // Convert e.g. / 4 into / 4.0
9069 exp.op.exp1.destType = type2._class.registered.dataType;
9070 if(type2._class.registered.dataType)
9071 type2._class.registered.dataType.refCount++;
9072 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9073 exp.expType = type2;
9074 if(type2) type2.refCount++;
9076 else if(!boolResult && !useSideUnit && c1 && c1.type == unitClass && type2 && type2.kind != classType)
9078 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9079 // Convert e.g. / 4 into / 4.0
9080 exp.op.exp2.destType = type1._class.registered.dataType;
9081 if(type1._class.registered.dataType)
9082 type1._class.registered.dataType.refCount++;
9083 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9084 exp.expType = type1;
9085 if(type1) type1.refCount++;
9091 if(!boolResult && useSideUnit && c1 && c1.type == unitClass && type2 && type2.kind != classType)
9093 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9095 exp.op.exp2.destType = c1.dataType;
9096 exp.op.exp2.destType.refCount++;
9098 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9101 type2 = exp.op.exp2.destType;
9102 c2 = type2 && type2.kind == classType && type2._class ? type2._class.registered : null;
9103 if(type2) type2.refCount++;
9105 exp.expType = type2;
9109 if(!boolResult && useSideUnit && c2 && c2.type == unitClass && type1 && type1.kind != classType)
9111 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9113 exp.op.exp1.destType = c2.dataType;
9114 exp.op.exp1.destType.refCount++;
9116 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9117 type1 = exp.op.exp1.destType;
9118 c1 = type1 && type1.kind == classType && type1._class ? type1._class.registered : null;
9119 exp.expType = type1;
9123 // TESTING THIS NEW CODE
9124 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
9126 bool op1IsEnum = c1 && c1.type == enumClass;
9127 bool op2IsEnum = c2 && c2.type == enumClass;
9128 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
9130 // Convert the enum to an int instead for these operators
9131 if(op1IsEnum && exp.op.exp2.expType)
9133 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
9135 if(exp.expType) FreeType(exp.expType);
9136 exp.expType = exp.op.exp2.expType;
9137 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9141 else if(op2IsEnum && exp.op.exp1.expType)
9143 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
9145 if(exp.expType) FreeType(exp.expType);
9146 exp.expType = exp.op.exp1.expType;
9147 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9154 if(op1IsEnum && exp.op.exp2.expType)
9156 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
9158 if(exp.expType) FreeType(exp.expType);
9159 exp.expType = exp.op.exp1.expType;
9160 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9164 else if(op2IsEnum && exp.op.exp1.expType)
9166 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
9168 if(exp.expType) FreeType(exp.expType);
9169 exp.expType = exp.op.exp2.expType;
9170 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9179 // 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
9180 if(c2 && c2.type == unitClass && (!c1 || c1.type != unitClass))
9182 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9183 exp.op.exp1.destType = type2;
9186 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9188 if(exp.expType) FreeType(exp.expType);
9189 exp.expType = exp.op.exp1.destType;
9190 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9195 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9196 exp.op.exp2.destType = type1;
9200 // Maybe this was meant to be an enum...
9201 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9203 Type oldType = exp.op.exp2.expType;
9204 exp.op.exp2.expType = null;
9205 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
9208 exp.op.exp2.expType = oldType;
9213 // TESTING THIS HERE... LATEST ADDITION
9214 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9216 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9217 exp.op.exp2.destType = type2._class.registered.dataType;
9218 if(type2._class.registered.dataType)
9219 type2._class.registered.dataType.refCount++;
9220 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
9222 //exp.expType = type2._class.registered.dataType; //type2;
9223 //if(type2) type2.refCount++;
9226 // TESTING THIS HERE... LATEST ADDITION
9227 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9229 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9230 exp.op.exp1.destType = type1._class.registered.dataType;
9231 if(type1._class.registered.dataType)
9232 type1._class.registered.dataType.refCount++;
9233 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
9234 exp.expType = type1._class.registered.dataType; //type1;
9235 if(type1) type1.refCount++;
9239 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
9241 if(exp.expType) FreeType(exp.expType);
9242 exp.expType = exp.op.exp2.destType;
9243 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
9245 else if(type1 && type2)
9247 char expString1[10240];
9248 char expString2[10240];
9249 char type1String[1024];
9250 char type2String[1024];
9251 expString1[0] = '\0';
9252 expString2[0] = '\0';
9253 type1String[0] = '\0';
9254 type2String[0] = '\0';
9257 PrintExpression(exp.op.exp1, expString1);
9258 ChangeCh(expString1, '\n', ' ');
9259 PrintExpression(exp.op.exp2, expString2);
9260 ChangeCh(expString2, '\n', ' ');
9261 PrintType(exp.op.exp1.expType, type1String, false, true);
9262 PrintType(exp.op.exp2.expType, type2String, false, true);
9265 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9267 if(c1 && c1.type == enumClass)
9269 exp.expType = exp.op.exp1.expType;
9270 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9272 else if(c2 && c2.type == enumClass)
9274 exp.expType = exp.op.exp2.expType;
9275 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9283 // Maybe this was meant to be an enum...
9284 if(c2 && c2.type == enumClass)
9286 Type oldType = exp.op.exp1.expType;
9287 exp.op.exp1.expType = null;
9288 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9291 exp.op.exp1.expType = oldType;
9294 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9295 exp.op.exp1.destType = type2;
9298 // TESTING THIS HERE... LATEST ADDITION
9299 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9301 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9302 exp.op.exp1.destType = type1._class.registered.dataType;
9303 if(type1._class.registered.dataType)
9304 type1._class.registered.dataType.refCount++;
9307 // TESTING THIS HERE... LATEST ADDITION
9308 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9310 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9311 exp.op.exp2.destType = type2._class.registered.dataType;
9312 if(type2._class.registered.dataType)
9313 type2._class.registered.dataType.refCount++;
9317 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9319 if(exp.expType) FreeType(exp.expType);
9320 exp.expType = exp.op.exp1.destType;
9321 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9325 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9327 if(type1 && c2 && c2.type == unitClass)
9329 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9330 // Convert e.g. / 4 into / 4.0
9331 exp.op.exp1.destType = type2._class.registered.dataType;
9332 if(type2._class.registered.dataType)
9333 type2._class.registered.dataType.refCount++;
9334 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9336 if(exp.op.op == '!')
9338 exp.expType = MkClassType("bool");
9339 exp.expType.truth = true;
9343 exp.expType = type2;
9344 if(type2) type2.refCount++;
9347 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9349 if(c2 && c2.type == unitClass)
9351 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9352 // Convert e.g. / 4 into / 4.0
9353 exp.op.exp2.destType = type1._class.registered.dataType;
9354 if(type1._class.registered.dataType)
9355 type1._class.registered.dataType.refCount++;
9356 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9358 exp.expType = type1;
9359 if(type1) type1.refCount++;
9364 if(exp.op.exp1 && !exp.op.exp1.expType)
9366 char expString[10000];
9367 expString[0] = '\0';
9370 PrintExpression(exp.op.exp1, expString);
9371 ChangeCh(expString, '\n', ' ');
9374 Compiler_Error($"couldn't determine type of %s\n", expString);
9376 if(exp.op.exp2 && !exp.op.exp2.expType)
9378 char expString[10240];
9379 expString[0] = '\0';
9382 PrintExpression(exp.op.exp2, expString);
9383 ChangeCh(expString, '\n', ' ');
9386 Compiler_Error($"couldn't determine type of %s\n", expString);
9391 FreeType(exp.expType);
9392 exp.expType = MkClassType("bool");
9393 exp.expType.truth = true;
9396 if(exp.op.op != SIZEOF)
9397 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9398 (!exp.op.exp2 || exp.op.exp2.isConstant);
9400 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9402 DeclareType(curExternal, exp.op.exp2.expType, true, false);
9405 if(exp.op.op == DELETE && exp.op.exp2 && exp.op.exp2.expType && exp.op.exp2.expType.specConst)
9406 Compiler_Warning($"deleting const qualified object\n");
9416 case extensionExpressionExp:
9419 exp.isConstant = true;
9420 for(e = exp.list->first; e; e = e.next)
9422 //bool inced = false;
9425 FreeType(e.destType);
9426 e.opDestType = exp.opDestType;
9427 e.usedInComparison = exp.usedInComparison;
9428 e.parentOpDestType = exp.parentOpDestType;
9429 e.destType = exp.destType;
9430 if(e.destType) { exp.destType.refCount++; /*e.destType.count++; inced = true;*/ }
9432 ProcessExpressionType(e);
9433 if(e.ambiguousUnits)
9434 exp.ambiguousUnits = true;
9436 exp.destType.count--;*/
9437 if(!exp.expType && !e.next)
9439 exp.expType = e.expType;
9440 if(e.expType) e.expType.refCount++;
9441 exp.needCast = e.needCast;
9444 exp.isConstant = false;
9447 // In case a cast became a member...
9448 e = exp.list->first;
9449 if(!e.next && e.type == memberExp)
9451 // Preserve prev, next
9452 Expression next = exp.next, prev = exp.prev;
9455 FreeType(exp.expType);
9456 FreeType(exp.destType);
9466 ProcessExpressionType(exp);
9473 exp.isConstant = true;
9475 ProcessExpressionType(exp.index.exp);
9476 if(!exp.index.exp.isConstant)
9477 exp.isConstant = false;
9479 if(exp.index.exp.expType)
9481 Type source = exp.index.exp.expType;
9482 if(source.kind == classType && source._class && source._class.registered)
9484 Class _class = source._class.registered;
9485 Class c = _class.templateClass ? _class.templateClass : _class;
9486 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9488 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9490 if(exp.index.index && exp.index.index->last)
9492 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9494 if(type.kind == classType) type.constant = true;
9495 else if(type.kind == pointerType)
9498 while(t.kind == pointerType) t = t.type;
9502 ((Expression)exp.index.index->last).destType = type;
9508 for(e = exp.index.index->first; e; e = e.next)
9510 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9512 if(e.destType) FreeType(e.destType);
9513 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9515 ProcessExpressionType(e);
9518 // Check if this type is int
9521 exp.isConstant = false;
9525 exp.expType = Dereference(exp.index.exp.expType);
9527 DeclareType(curExternal, exp.expType, true, false);
9534 Type methodType = null;
9540 PrintExpression(exp.call.exp, name);
9541 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9543 //exp.call.exp.expType = null;
9544 PrintExpression(exp.call.exp, name);
9547 if(exp.call.exp.type == identifierExp)
9549 Expression idExp = exp.call.exp;
9550 Identifier id = idExp.identifier;
9551 if(!strcmp(id.string, "__builtin_frame_address"))
9553 exp.expType = ProcessTypeString("void *", true);
9554 if(exp.call.arguments && exp.call.arguments->first)
9555 ProcessExpressionType(exp.call.arguments->first);
9558 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9560 exp.expType = ProcessTypeString("int", true);
9561 if(exp.call.arguments && exp.call.arguments->first)
9562 ProcessExpressionType(exp.call.arguments->first);
9565 else if(!strcmp(id.string, "Max") ||
9566 !strcmp(id.string, "Min") ||
9567 !strcmp(id.string, "Sgn") ||
9568 !strcmp(id.string, "Abs"))
9570 Expression a = null;
9571 Expression b = null;
9572 Expression tempExp1 = null, tempExp2 = null;
9573 if((!strcmp(id.string, "Max") ||
9574 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9576 a = exp.call.arguments->first;
9577 b = exp.call.arguments->last;
9581 else if(exp.call.arguments->count == 1)
9583 a = exp.call.arguments->first;
9589 exp.call.arguments->Clear();
9590 idExp.identifier = null;
9592 FreeExpContents(exp);
9594 ProcessExpressionType(a);
9596 ProcessExpressionType(b);
9598 exp.type = bracketsExp;
9599 exp.list = MkList();
9601 if(a.expType && (!b || b.expType))
9603 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9605 // Use the simpleStruct name/ids for now...
9608 OldList * specs = MkList();
9609 OldList * decls = MkList();
9611 char temp1[1024], temp2[1024];
9613 GetTypeSpecs(a.expType, specs);
9615 if(a && !a.isConstant && a.type != identifierExp)
9617 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9618 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9619 tempExp1 = QMkExpId(temp1);
9620 tempExp1.expType = a.expType;
9622 a.expType.refCount++;
9623 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9625 if(b && !b.isConstant && b.type != identifierExp)
9627 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9628 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9629 tempExp2 = QMkExpId(temp2);
9630 tempExp2.expType = b.expType;
9632 b.expType.refCount++;
9633 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9636 decl = MkDeclaration(specs, decls);
9637 if(!curCompound.compound.declarations)
9638 curCompound.compound.declarations = MkList();
9639 curCompound.compound.declarations->Insert(null, decl);
9644 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9646 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9648 MkExpCondition(MkExpBrackets(MkListOne(
9649 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9650 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9651 exp.expType = a.expType;
9653 a.expType.refCount++;
9655 else if(!strcmp(id.string, "Abs"))
9658 MkExpCondition(MkExpBrackets(MkListOne(
9659 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9660 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9661 exp.expType = a.expType;
9663 a.expType.refCount++;
9665 else if(!strcmp(id.string, "Sgn"))
9667 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9669 MkExpCondition(MkExpBrackets(MkListOne(
9670 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9671 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9672 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9673 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9674 exp.expType = ProcessTypeString("int", false);
9677 FreeExpression(tempExp1);
9678 if(tempExp2) FreeExpression(tempExp2);
9692 if(!exp.call.exp.destType)
9694 exp.call.exp.destType = dummy;
9697 ProcessExpressionType(exp.call.exp);
9698 if(exp.call.exp.destType == dummy)
9701 exp.call.exp.destType = null;
9706 // Check argument types against parameter types
9707 functionType = exp.call.exp.expType;
9709 if(functionType && functionType.kind == TypeKind::methodType)
9711 methodType = functionType;
9712 functionType = methodType.method.dataType;
9714 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9715 // TOCHECK: Instead of doing this here could this be done per param?
9716 if(exp.call.exp.expType.usedClass)
9718 char typeString[1024];
9719 typeString[0] = '\0';
9721 Symbol back = functionType.thisClass;
9722 // Do not output class specifier here (thisclass was added to this)
9723 functionType.thisClass = null;
9724 PrintType(functionType, typeString, true, true);
9725 functionType.thisClass = back;
9727 if(strstr(typeString, "thisclass"))
9729 OldList * specs = MkList();
9732 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9734 decl = SpecDeclFromString(typeString, specs, null);
9736 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9737 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9738 exp.call.exp.expType.usedClass))
9739 thisClassParams = false;
9741 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9743 Class backupThisClass = thisClass;
9744 thisClass = exp.call.exp.expType.usedClass;
9745 ProcessDeclarator(decl, true);
9746 thisClass = backupThisClass;
9749 thisClassParams = true;
9751 functionType = ProcessType(specs, decl);
9752 functionType.refCount = 0;
9753 FinishTemplatesContext(context);
9755 // Mark parameters that were 'thisclass'
9758 for(p = functionType.params.first, op = methodType.method.dataType.params.first; p && op; p = p.next, op = op.next)
9760 //p.wasThisClass = op.kind == thisClassType;
9761 if(op.kind == thisClassType)
9762 p.thisClassFrom = methodType.method._class;
9765 if(methodType.method.dataType.returnType.kind == thisClassType)
9767 // functionType.returnType.wasThisClass = true;
9768 functionType.returnType.thisClassFrom = methodType.method._class;
9772 FreeList(specs, FreeSpecifier);
9773 FreeDeclarator(decl);
9777 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9779 Type type = functionType.type;
9780 if(!functionType.refCount)
9782 functionType.type = null;
9783 FreeType(functionType);
9785 //methodType = functionType;
9786 functionType = type;
9788 if(functionType && functionType.kind != TypeKind::functionType)
9790 Compiler_Error($"called object %s is not a function\n", name);
9792 else if(functionType)
9794 bool emptyParams = false, noParams = false;
9795 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9796 Type type = functionType.params.first;
9797 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9799 Location oldyylloc = yylloc;
9801 if(!type) emptyParams = true;
9804 if(functionType.extraParam && e && functionType.thisClass)
9806 e.destType = MkClassType(functionType.thisClass.string);
9810 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9811 // Fixed #141 by adding '&& !functionType.extraParam'
9812 if(!functionType.staticMethod && !functionType.extraParam)
9814 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9815 memberExp.member.exp.expType._class)
9817 type = MkClassType(memberExp.member.exp.expType._class.string);
9822 type = functionType.params.first;
9827 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9829 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9830 type.byReference = functionType.byReference;
9831 type.typedByReference = functionType.typedByReference;
9834 // Allow manually passing a class for typed object
9835 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9839 type = functionType.params.first;
9847 if(type && type.kind == voidType)
9850 if(!type.refCount) FreeType(type);
9854 for( ; e; e = e.next)
9856 if(!type && !emptyParams)
9859 if(methodType && methodType.methodClass)
9860 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9861 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9862 noParams ? 0 : functionType.params.count);
9864 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9865 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9866 noParams ? 0 : functionType.params.count);
9870 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9872 Type templatedType = null;
9873 Class _class = methodType.usedClass;
9874 ClassTemplateParameter curParam = null;
9876 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9879 for(sClass = _class; sClass; sClass = sClass.base)
9881 if(sClass.templateClass) sClass = sClass.templateClass;
9883 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9885 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9888 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9890 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9891 id += nextClass.templateParams.count;
9900 if(curParam && _class.templateArgs[id].dataTypeString)
9902 bool constant = type.constant;
9903 ClassTemplateArgument arg = _class.templateArgs[id];
9905 Context context = SetupTemplatesContext(_class);
9908 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9909 templatedType = ProcessTypeString(arg.dataTypeString, false);
9910 FinishTemplatesContext(context);
9913 if(templatedType.kind == classType && constant) templatedType.constant = true;
9914 else if(templatedType.kind == pointerType)
9916 Type t = templatedType.type;
9917 while(t.kind == pointerType) t = t.type;
9918 if(constant) t.constant = constant;
9921 e.destType = templatedType;
9924 templatedType.passAsTemplate = true;
9925 // templatedType.refCount++;
9931 if(type) type.refCount++;
9936 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9938 e.destType = type.prev;
9939 e.destType.refCount++;
9944 if(type) type.refCount++;
9947 // Don't reach the end for the ellipsis
9948 if(type && type.kind != ellipsisType)
9950 Type next = type.next;
9951 if(!type.refCount) FreeType(type);
9956 if(type && type.kind != ellipsisType)
9958 if(methodType && methodType.methodClass)
9959 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9960 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9961 functionType.params.count + extra);
9963 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9964 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9965 functionType.params.count + extra);
9968 if(type && !type.refCount) FreeType(type);
9975 kind = TypeKind::functionType;
9978 if(exp.call.exp.type == identifierExp)
9980 char * string = exp.call.exp.identifier.string;
9984 Location oldyylloc = yylloc;
9986 yylloc = exp.call.exp.identifier.loc;
9987 if(strstr(string, "__builtin_") == string)
9991 functionType.returnType = exp.destType;
9992 exp.destType.refCount++;
9996 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9997 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9998 globalContext.symbols.Add((BTNode)symbol);
9999 if(strstr(symbol.string, "::"))
10000 globalContext.hasNameSpace = true;
10002 yylloc = oldyylloc;
10005 else if(exp.call.exp.type == memberExp)
10007 /*Compiler_Warning($"%s undefined; assuming returning int\n",
10008 exp.call.exp.member.member.string);*/
10011 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
10013 if(!functionType.returnType)
10015 functionType.returnType = Type
10022 if(functionType && functionType.kind == TypeKind::functionType)
10024 exp.expType = functionType.returnType;
10026 if(functionType.returnType)
10027 functionType.returnType.refCount++;
10029 if(!functionType.refCount)
10030 FreeType(functionType);
10033 if(exp.call.arguments)
10035 for(e = exp.call.arguments->first; e; e = e.next)
10036 ProcessExpressionType(e);
10043 Location oldyylloc = yylloc;
10045 Expression checkExp = exp.member.exp;
10048 if(checkExp.type == castExp)
10049 checkExp = checkExp.cast.exp;
10050 else if(checkExp.type == bracketsExp)
10051 checkExp = checkExp.list ? checkExp.list->first : null;
10056 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
10057 exp.thisPtr = thisPtr;
10059 // DOING THIS LATER NOW...
10060 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10062 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10063 /* TODO: Name Space Fix ups
10064 if(!exp.member.member.classSym)
10065 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
10069 ProcessExpressionType(exp.member.exp);
10070 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
10071 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
10073 exp.isConstant = false;
10076 exp.isConstant = exp.member.exp.isConstant;
10077 type = exp.member.exp.expType;
10081 if(type && (type.kind == templateType))
10083 Class _class = thisClass ? thisClass : currentClass;
10084 ClassTemplateParameter param = null;
10087 for(param = _class.templateParams.first; param; param = param.next)
10089 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
10093 if(param && param.defaultArg.member)
10095 Expression argExp = GetTemplateArgExpByName(param.name, null, thisClass, TemplateParameterType::identifier);
10098 Expression expMember = exp.member.exp;
10100 OldList * specs = MkList();
10101 char thisClassTypeString[1024];
10103 FreeIdentifier(exp.member.member);
10105 ProcessExpressionType(argExp);
10108 char * colon = strstr(param.defaultArg.memberString, "::");
10111 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
10112 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
10115 strcpy(thisClassTypeString, _class.fullName);
10118 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
10120 exp.expType = ProcessType(specs, decl);
10121 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
10123 Class expClass = exp.expType._class.registered;
10124 Class cClass = null;
10125 int paramCount = 0;
10126 int lastParam = -1;
10128 char templateString[1024];
10129 ClassTemplateParameter param;
10130 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10131 for(cClass = expClass; cClass; cClass = cClass.base)
10134 for(param = cClass.templateParams.first; param; param = param.next)
10138 ClassTemplateArgument arg;
10139 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
10140 arg = expClass.templateArgs[id];
10142 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
10144 ClassTemplateParameter cParam;
10145 //int p = numParams - sClass.templateParams.count;
10148 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
10150 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
10152 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
10154 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10156 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
10157 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
10165 char argument[256];
10166 argument[0] = '\0';
10169 strcat(argument, arg.name.string);
10170 strcat(argument, " = ");
10176 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10177 char expString[1024];
10178 OldList * specs = MkList();
10179 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10181 char * string = PrintHexUInt64(arg.expression.ui64);
10182 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10185 ProcessExpressionType(exp);
10186 ComputeExpression(exp);
10187 expString[0] = '\0';
10188 PrintExpression(exp, expString);
10189 strcat(argument, expString);
10191 FreeExpression(exp);
10196 strcat(argument, arg.member.name);
10199 case TemplateParameterType::type:
10201 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10203 if(!strcmp(arg.dataTypeString, "thisclass"))
10204 strcat(argument, thisClassTypeString);
10206 strcat(argument, arg.dataTypeString);
10213 if(paramCount) strcat(templateString, ", ");
10214 if(lastParam != p - 1)
10216 strcat(templateString, param.name);
10217 strcat(templateString, " = ");
10219 strcat(templateString, argument);
10228 int len = strlen(templateString);
10229 if(templateString[len-1] == '>') templateString[len++] = ' ';
10230 templateString[len++] = '>';
10231 templateString[len++] = '\0';
10234 Context context = SetupTemplatesContext(_class);
10235 FreeType(exp.expType);
10236 exp.expType = ProcessTypeString(templateString, false);
10237 FinishTemplatesContext(context);
10241 if(!expMember.expType.isPointerType)
10242 expMember = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), expMember);
10243 // *([expType] *)(((byte *)(uintptr)[exp.member.exp]) + [argExp].member.offset)
10244 exp.type = bracketsExp;
10245 exp.list = MkListOne(MkExpOp(null, '*',
10248 exp.op.exp1 = null;
10250 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
10251 MkExpBrackets(MkListOne(
10252 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
10255 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
10257 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
10262 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
10263 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
10265 type = ProcessTemplateParameterType(type.templateParameter);
10268 // TODO: *** This seems to be where we should add method support for all basic types ***
10269 if(type && (type.kind == templateType));
10270 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
10271 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
10272 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
10273 (type.kind == pointerType && type.type.kind == charType)))
10275 Identifier id = exp.member.member;
10276 TypeKind typeKind = type.kind;
10277 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10278 if(typeKind == subClassType && exp.member.exp.type == classExp)
10280 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10281 typeKind = classType;
10286 if(typeKind == intType || typeKind == enumType)
10287 _class = eSystem_FindClass(privateModule, "int");
10290 if(type.kind == classType && type._class && type._class.registered)
10292 _class = type._class.registered;
10294 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10296 _class = FindClass("char *").registered;
10298 else if(type.kind == pointerType)
10300 _class = eSystem_FindClass(privateModule, "uintptr");
10301 FreeType(exp.expType);
10302 exp.expType = ProcessTypeString("uintptr", false);
10303 exp.byReference = true;
10307 char string[1024] = "";
10309 PrintTypeNoConst(type, string, false, true);
10310 classSym = FindClass(string);
10311 if(classSym) _class = classSym.registered;
10319 (exp.member.exp.type == identifierExp &&
10320 !strcmp(exp.member.exp.identifier.string, "this"));*/
10321 Property prop = null;
10322 Method method = null;
10323 DataMember member = null;
10324 Property revConvert = null;
10325 ClassProperty classProp = null;
10327 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10328 exp.member.memberType = propertyMember;
10330 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10331 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10333 if(typeKind != subClassType)
10335 // Prioritize data members over properties for "this"
10336 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10338 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10339 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10341 prop = eClass_FindProperty(_class, id.string, privateModule);
10345 if(!member && !prop)
10346 prop = eClass_FindProperty(_class, id.string, privateModule);
10347 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10348 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10349 exp.member.thisPtr = true;
10351 // Prioritize properties over data members otherwise
10354 bool useMemberForNonConst = false;
10355 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10358 prop = eClass_FindProperty(_class, id.string, null);
10360 useMemberForNonConst = prop && exp.destType &&
10361 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10362 !strncmp(prop.dataTypeString, "const ", 6);
10364 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10365 member = eClass_FindDataMember(_class, id.string, null, null, null);
10368 if((!prop || useMemberForNonConst) && !member)
10370 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10373 prop = eClass_FindProperty(_class, id.string, privateModule);
10375 useMemberForNonConst |= prop && exp.destType &&
10376 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10377 !strncmp(prop.dataTypeString, "const ", 6);
10379 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10380 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10386 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10393 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10394 method = eClass_FindMethod(_class, id.string, privateModule);
10395 if(!prop && !member && !method)
10397 if(typeKind == subClassType)
10399 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10402 exp.member.memberType = classPropertyMember;
10403 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10407 // Assume this is a class_data member
10408 char structName[1024];
10409 Identifier id = exp.member.member;
10410 Expression classExp = exp.member.exp;
10413 FreeType(classExp.expType);
10414 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10416 strcpy(structName, "__ecereClassData_");
10417 FullClassNameCat(structName, type._class.string, false);
10418 exp.type = pointerExp;
10419 exp.member.member = id;
10421 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10422 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10423 MkExpBrackets(MkListOne(MkExpOp(
10424 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10425 MkExpMember(classExp, MkIdentifier("data"))), '+',
10426 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10431 ProcessExpressionType(exp);
10437 // Check for reverse conversion
10438 // (Convert in an instantiation later, so that we can use
10439 // deep properties system)
10440 Symbol classSym = FindClass(id.string);
10443 Class convertClass = classSym.registered;
10445 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10450 //if(!exp.member.exp.destType)
10451 if(exp.member.exp.destType)
10452 FreeType(exp.member.exp.destType);
10454 if(method && !method._class.symbol)
10455 method._class.symbol = FindClass(method._class.fullName);
10456 if(prop && !prop._class.symbol)
10457 prop._class.symbol = FindClass(prop._class.fullName);
10459 exp.member.exp.destType = Type
10463 _class = prop ? prop._class.symbol : method ? method._class.symbol : _class.symbol;
10464 // wasThisClass = type ? type.wasThisClass : false;
10465 thisClassFrom = type ? type.thisClassFrom : null;
10471 exp.member.memberType = propertyMember;
10473 ProcessPropertyType(prop);
10474 exp.expType = prop.dataType;
10475 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10478 CopyTypeInto(type, exp.expType);
10480 type.constant = true;
10481 exp.expType = type;
10483 else if(prop.dataType)
10484 prop.dataType.refCount++;
10488 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10490 FreeExpContents(exp);
10491 exp.type = identifierExp;
10492 exp.identifier = MkIdentifier("class");
10493 ProcessExpressionType(exp);
10497 exp.member.memberType = dataMember;
10498 DeclareStruct(curExternal, _class.fullName, false, true);
10499 if(member._class != _class)
10500 DeclareStruct(curExternal, member._class.fullName, false, true);
10502 if(!member.dataType)
10504 Context context = SetupTemplatesContext(_class);
10505 member.dataType = ProcessTypeString(member.dataTypeString, false);
10506 FinishTemplatesContext(context);
10508 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)
10509 member.dataType.bitMemberSize = ((BitMember)member).size;
10510 exp.expType = member.dataType;
10511 if(member.dataType) member.dataType.refCount++;
10513 else if(revConvert)
10515 exp.member.memberType = reverseConversionMember;
10516 exp.expType = MkClassType(revConvert._class.fullName);
10524 exp.type = identifierExp;
10525 exp.identifier = exp.member.member;
10528 exp.member.memberType = methodMember;
10530 if(!method.dataType)
10531 ProcessMethodType(method);
10539 // Tricky spot here... To use instance versus class virtual table
10540 // Put it back to what it was... What did we break?
10542 // Had to put it back for overriding Main of Thread global instance
10544 //exp.expType.methodClass = _class;
10545 exp.expType.methodClass = (id && id._class) ? _class : null;
10547 // Need the actual class used for templated classes
10548 exp.expType.usedClass = _class;
10550 else if(!classProp)
10552 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10554 FreeExpContents(exp);
10555 exp.type = identifierExp;
10556 exp.identifier = MkIdentifier("class");
10557 FreeType(exp.expType);
10558 exp.expType = MkClassType("ecere::com::Class");
10561 yylloc = exp.member.member.loc;
10562 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10564 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10567 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10571 tClass = type._class && type._class.registered ? type._class.registered : _class;
10572 while(tClass && !tClass.templateClass) tClass = tClass.base;
10574 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10577 ClassTemplateParameter curParam = null;
10580 for(sClass = tClass; sClass; sClass = sClass.base)
10583 if(sClass.templateClass) sClass = sClass.templateClass;
10584 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10586 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10588 for(sClass = sClass.base; sClass; sClass = sClass.base)
10589 id += sClass.templateParams.count;
10594 if(curParam) break;
10597 if(curParam && tClass.templateArgs[id].dataTypeString)
10599 ClassTemplateArgument arg = tClass.templateArgs[id];
10600 Context context = SetupTemplatesContext(tClass);
10601 bool constant = exp.expType.constant;
10602 bool passAsTemplate = false;
10603 Class thisClassFrom = null;
10604 Type t = exp.expType.templateParameter.dataTypeString ? ProcessTypeString(exp.expType.templateParameter.dataTypeString, false) : null;
10605 if(t && t.kind == classType && t._class)
10606 thisClassFrom = t._class.registered;
10607 else if(exp.expType.thisClassFrom)
10608 thisClassFrom = thisClass;
10610 // Mark that 'thisClassFrom' was set to something
10611 thisClassFrom = eSystem_FindClass(GetPrivateModule(), "class");
10615 passAsTemplate = tClass.templateClass && (exp.expType.kind != templateType ||
10616 (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType)));
10618 /*if(!arg.dataType)
10619 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10620 FreeType(exp.expType);
10622 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10623 exp.expType.thisClassFrom = thisClassFrom;
10624 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10625 else if(exp.expType.kind == pointerType)
10627 Type t = exp.expType.type;
10628 while(t.kind == pointerType) t = t.type;
10629 if(constant) t.constant = constant;
10633 if(exp.expType.kind == thisClassType)
10635 FreeType(exp.expType);
10636 exp.expType = ReplaceThisClassType(_class);
10640 exp.expType.passAsTemplate = true;
10641 //exp.expType.refCount++;
10644 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10645 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10646 else if(exp.destType.kind == pointerType)
10648 Type t = exp.destType.type;
10649 while(t.kind == pointerType) t = t.type;
10650 if(constant) t.constant = constant;
10653 //exp.destType.refCount++;
10655 if(exp.destType.kind == thisClassType)
10657 FreeType(exp.destType);
10658 exp.destType = ReplaceThisClassType(_class);
10662 FinishTemplatesContext(context);
10665 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10666 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10669 ClassTemplateParameter curParam = null;
10672 for(sClass = tClass; sClass; sClass = sClass.base)
10675 if(sClass.templateClass) sClass = sClass.templateClass;
10676 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10678 if(curParam.type == TemplateParameterType::type &&
10679 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10681 for(sClass = sClass.base; sClass; sClass = sClass.base)
10682 id += sClass.templateParams.count;
10687 if(curParam) break;
10692 ClassTemplateArgument arg = tClass.templateArgs[id];
10693 Context context = SetupTemplatesContext(tClass);
10695 /*if(!arg.dataType)
10696 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10698 basicType = ProcessTypeString(arg.dataTypeString, false);
10701 if(basicType.kind == thisClassType)
10703 FreeType(basicType);
10704 basicType = ReplaceThisClassType(_class);
10707 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10708 if(tClass.templateClass)
10709 basicType.passAsTemplate = true;
10712 FreeType(exp.expType);
10714 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10715 //exp.expType.refCount++;
10718 exp.destType = exp.expType;
10719 exp.destType.refCount++;
10723 Expression newExp { };
10724 OldList * specs = MkList();
10726 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10728 if(exp.destType) exp.destType.refCount++;
10729 if(exp.expType) exp.expType.refCount++;
10730 exp.type = bracketsExp;
10731 exp.list = MkListOne(MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), newExp));
10732 //FreeType(exp.expType);
10733 //exp.expType = null;
10734 //ProcessExpressionType(sourceExp);
10737 FinishTemplatesContext(context);
10740 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10742 Class expClass = exp.expType._class.registered;
10745 Class cClass = null;
10747 int paramCount = 0;
10748 int lastParam = -1;
10749 char templateString[1024];
10750 ClassTemplateParameter param;
10751 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10752 while(cClass != expClass)
10755 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10758 for(param = cClass.templateParams.first; param; param = param.next)
10760 Class cClassCur = null;
10762 ClassTemplateParameter paramCur = null;
10763 ClassTemplateArgument arg;
10764 while(cClassCur != tClass && !paramCur)
10767 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10768 cClassCur = sClassCur;
10770 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10772 if(!strcmp(paramCur.name, param.name))
10780 if(paramCur && paramCur.type == TemplateParameterType::type)
10781 arg = tClass.templateArgs[cp];
10783 arg = expClass.templateArgs[p];
10786 char argument[256];
10787 argument[0] = '\0';
10790 strcat(argument, arg.name.string);
10791 strcat(argument, " = ");
10797 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10798 char expString[1024];
10799 OldList * specs = MkList();
10800 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10802 char * string = PrintHexUInt64(arg.expression.ui64);
10803 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10806 ProcessExpressionType(exp);
10807 ComputeExpression(exp);
10808 expString[0] = '\0';
10809 PrintExpression(exp, expString);
10810 strcat(argument, expString);
10812 FreeExpression(exp);
10817 strcat(argument, arg.member.name);
10820 case TemplateParameterType::type:
10822 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10823 strcat(argument, arg.dataTypeString);
10829 if(paramCount) strcat(templateString, ", ");
10830 if(lastParam != p - 1)
10832 strcat(templateString, param.name);
10833 strcat(templateString, " = ");
10835 strcat(templateString, argument);
10844 int len = strlen(templateString);
10845 if(templateString[len-1] == '>') templateString[len++] = ' ';
10846 templateString[len++] = '>';
10847 templateString[len++] = '\0';
10850 FreeType(exp.expType);
10852 Context context = SetupTemplatesContext(tClass);
10853 exp.expType = ProcessTypeString(templateString, false);
10854 FinishTemplatesContext(context);
10861 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10863 else if(type && (type.kind == structType || type.kind == unionType))
10865 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10868 exp.expType = memberType;
10870 memberType.refCount++;
10875 char expString[10240];
10876 expString[0] = '\0';
10877 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10878 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10881 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10883 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10885 Identifier id = exp.member.member;
10886 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10889 FreeType(exp.expType);
10890 exp.expType = ReplaceThisClassType(_class);
10894 yylloc = oldyylloc;
10897 // Convert x->y into (*x).y
10900 Type destType = exp.destType;
10902 // DOING THIS LATER NOW...
10903 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10905 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10906 /* TODO: Name Space Fix ups
10907 if(!exp.member.member.classSym)
10908 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10912 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10913 exp.type = memberExp;
10916 ProcessExpressionType(exp);
10923 //ComputeExpression(exp);
10925 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10926 if(classSym && classSym.registered)
10928 if(classSym.registered.type == noHeadClass || (classSym.registered.fixed && classSym.registered.structSize))
10931 Class b = classSym.registered;
10933 DeclareStruct(curExternal, classSym.string, false, true);
10934 FreeSpecifier(exp._class);
10935 FullClassNameCat(name, classSym.string, false);
10939 exp.type = typeSizeExp;
10940 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10946 if(b.structSize == b.offset)
10947 exp.op.exp1 = MkExpConstant("0");
10949 exp.op.exp1 = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10952 while(b.offset != 0)
10955 Expression typeSize;
10958 sym = FindClass(b.fullName);
10961 DeclareStruct(curExternal, sym.string, false, true);
10962 FullClassNameCat(name, sym.string, false);
10964 if(b.structSize == b.offset)
10965 typeSize = MkExpConstant("0");
10967 typeSize = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10968 e.op.exp2 = b.offset ? MkExpOp(typeSize, '+', null) : typeSize;
10975 if(classSym.registered.fixed && !classSym.registered.structSize)
10977 FreeSpecifier(exp._class);
10978 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10979 exp.type = constantExp;
10983 char className[1024];
10984 strcpy(className, "__ecereClass_");
10985 FullClassNameCat(className, classSym.string, true);
10987 DeclareClass(curExternal, classSym, className);
10989 FreeExpContents(exp);
10990 exp.type = pointerExp;
10991 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10992 exp.member.member = MkIdentifier("structSize");
11000 kind = intSizeType;
11002 // exp.isConstant = true;
11007 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
11012 kind = intSizeType;
11014 exp.isConstant = true;
11016 DeclareType(curExternal, type, true, false);
11022 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
11024 FreeType(exp.cast.exp.destType);
11025 exp.cast.exp.destType = type;
11027 type.casted = true;
11028 ProcessExpressionType(exp.cast.exp);
11029 type.casted = false;
11031 exp.expType = type;
11034 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
11035 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
11037 void * prev = exp.prev, * next = exp.next;
11038 Type expType = exp.cast.exp.destType;
11039 Expression castExp = exp.cast.exp;
11040 Type destType = exp.destType;
11042 if(expType) expType.refCount++;
11044 //FreeType(exp.destType);
11045 FreeType(exp.expType);
11046 FreeTypeName(exp.cast.typeName);
11049 FreeType(exp.expType);
11050 FreeType(exp.destType);
11052 exp.expType = expType;
11053 exp.destType = destType;
11063 exp.isConstant = exp.cast.exp.isConstant;
11068 case extensionInitializerExp:
11070 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
11071 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
11072 // ProcessInitializer(exp.initializer.initializer, type);
11073 exp.expType = type;
11078 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
11079 ProcessExpressionType(exp.vaArg.exp);
11080 exp.expType = type;
11086 Type t = exp.destType;
11087 if(t && !exp.destType.casted)
11090 CopyTypeInto(t, exp.destType);
11096 exp.isConstant = true;
11098 FreeType(exp.cond.cond.destType);
11099 exp.cond.cond.destType = MkClassType("bool");
11100 exp.cond.cond.destType.truth = true;
11101 ProcessExpressionType(exp.cond.cond);
11102 if(!exp.cond.cond.isConstant)
11103 exp.isConstant = false;
11104 for(e = exp.cond.exp->first; e; e = e.next)
11108 FreeType(e.destType);
11110 if(e.destType) e.destType.refCount++;
11112 ProcessExpressionType(e);
11115 exp.expType = e.expType;
11116 if(e.expType) e.expType.refCount++;
11119 exp.isConstant = false;
11122 FreeType(exp.cond.elseExp.destType);
11123 // Added this check if we failed to find an expType
11124 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
11127 exp.cond.elseExp.destType = t ? t : exp.expType;
11129 if(exp.cond.elseExp.destType)
11130 exp.cond.elseExp.destType.refCount++;
11131 ProcessExpressionType(exp.cond.elseExp);
11133 // FIXED THIS: Was done before calling process on elseExp
11134 if(!exp.cond.elseExp.isConstant)
11135 exp.isConstant = false;
11140 case extensionCompoundExp:
11142 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
11144 Statement last = exp.compound.compound.statements->last;
11145 if(last.type == expressionStmt && last.expressions && last.expressions->last)
11147 ((Expression)last.expressions->last).destType = exp.destType;
11149 exp.destType.refCount++;
11151 ProcessStatement(exp.compound);
11152 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
11154 exp.expType.refCount++;
11160 Specifier spec = exp._classExp.specifiers->first;
11161 if(spec && spec.type == nameSpecifier)
11163 exp.expType = MkClassType(spec.name);
11164 exp.expType.kind = subClassType;
11165 exp.byReference = true;
11169 exp.expType = MkClassType("ecere::com::Class");
11170 exp.byReference = true;
11176 Class _class = thisClass ? thisClass : currentClass;
11179 Identifier id = exp.classData.id;
11180 char structName[1024];
11181 Expression classExp;
11182 strcpy(structName, "__ecereClassData_");
11183 FullClassNameCat(structName, _class.fullName, false);
11184 exp.type = pointerExp;
11185 exp.member.member = id;
11186 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
11187 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
11189 classExp = MkExpIdentifier(MkIdentifier("class"));
11191 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
11192 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
11193 MkExpBrackets(MkListOne(MkExpOp(
11194 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
11195 MkExpMember(classExp, MkIdentifier("data"))), '+',
11196 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
11199 ProcessExpressionType(exp);
11207 const char * typeString = null;
11208 char typeStringBuf[1024];
11209 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
11210 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
11212 Class templateClass = exp.destType._class.registered;
11213 typeString = templateClass.templateArgs[2].dataTypeString;
11217 // Guess type from expressions in the array
11219 for(e = exp.list->first; e; e = e.next)
11221 ProcessExpressionType(e);
11224 if(!type) { type = e.expType; type.refCount++; }
11227 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11228 if(!MatchTypeExpression(e, type, null, false, true))
11234 e = exp.list->first;
11235 ProcessExpressionType(e);
11238 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
11239 if(!MatchTypeExpression(e, type, null, false, true))
11241 FreeType(e.expType);
11252 FreeType(e.expType);
11259 typeStringBuf[0] = '\0';
11260 PrintTypeNoConst(type, typeStringBuf, false, true);
11261 typeString = typeStringBuf;
11269 (Container)& (struct BuiltInContainer)
11271 ._vTbl = class(BuiltInContainer)._vTbl,
11272 ._class = class(BuiltInContainer),
11274 .data = (int[]){ 1, 7, 3, 4, 5 },
11276 .type = class(int),
11279 char templateString[1024];
11280 OldList * initializers = MkList();
11281 OldList * structInitializers = MkList();
11282 OldList * specs = MkList();
11284 Declarator decl = SpecDeclFromString(typeString, specs, null);
11285 sprintf(templateString, "Container<%s>", typeString);
11290 type = ProcessTypeString(typeString, false);
11291 while((e = exp.list->first))
11293 exp.list->Remove(e);
11296 ProcessExpressionType(e);
11297 ListAdd(initializers, MkInitializerAssignment(e));
11303 DeclareStruct(curExternal, "ecere::com::BuiltInContainer", false, true);
11305 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
11306 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11307 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
11308 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11309 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
11310 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11311 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
11312 MkTypeName(specs, MkDeclaratorArray(decl, null)),
11313 MkInitializerList(initializers))));
11314 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11315 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
11316 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11317 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
11318 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11319 exp.expType = ProcessTypeString(templateString, false);
11320 exp.type = bracketsExp;
11321 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
11323 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
11324 MkInitializerList(structInitializers)))));
11325 ProcessExpressionType(expExt);
11329 exp.expType = ProcessTypeString("Container", false);
11330 Compiler_Error($"Couldn't determine type of array elements\n");
11336 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
11338 FreeType(exp.expType);
11339 exp.expType = ReplaceThisClassType(thisClass);
11342 // Resolve structures here
11343 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
11345 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
11346 // TODO: Fix members reference...
11349 if(exp.expType.kind != enumType)
11352 String enumName = CopyString(exp.expType.enumName);
11354 // Fixed a memory leak on self-referencing C structs typedefs
11355 // by instantiating a new type rather than simply copying members
11356 // into exp.expType
11357 FreeType(exp.expType);
11358 exp.expType = Type { };
11359 exp.expType.kind = symbol.type.kind;
11360 exp.expType.refCount++;
11361 exp.expType.enumName = enumName;
11363 exp.expType.members = symbol.type.members;
11364 for(member = symbol.type.members.first; member; member = member.next)
11369 NamedLink64 member;
11370 for(member = symbol.type.members.first; member; member = member.next)
11372 NamedLink64 value { name = CopyString(member.name) };
11373 exp.expType.members.Add(value);
11379 // Trying to do this here before conversion properties kick in and this becomes a new expression... (Fixing Class c; const char * a = c;)
11380 // Mark nohead classes as by reference, unless we're casting them to an integral type
11381 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11382 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11383 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11384 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11386 exp.byReference = true;
11390 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11391 else if(exp.destType && !exp.destType.keepCast)
11393 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11394 exp.needTemplateCast = 1;
11396 if(exp.destType.kind == voidType);
11397 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11399 // Warn for casting unrelated types to/from struct classes
11400 bool invalidCast = false;
11401 if(inCompiler && exp.destType.count && exp.expType)
11403 Class c1 = (exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
11404 Class c2 = (exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
11405 if(c1 && c1.type != structClass) c1 = null;
11406 if(c2 && c2.type != structClass) c2 = null;
11407 if((c1 && !exp.expType.byReference && !c2 && !exp.destType.isPointerType) || (c2 && !exp.destType.byReference && !c1 && !exp.expType.isPointerType))
11408 invalidCast = true;
11410 if(!exp.destType.count || unresolved || invalidCast)
11415 if(exp.destType.kind != ellipsisType)
11421 char expString[10240];
11422 expString[0] = '\0';
11424 PrintType(exp.destType, type2, false, true);
11426 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11428 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11429 else if(exp.type != dummyExp)
11430 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11435 char expString[10240] ;
11436 expString[0] = '\0';
11437 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11440 Compiler_Error($"unresolved identifier %s\n", expString);
11441 else if(exp.type != dummyExp)
11442 Compiler_Error($"couldn't determine type of %s\n", expString);
11453 PrintType(exp.expType, type1, false, true);
11454 PrintType(exp.destType, type2, false, true);
11457 //CheckExpressionType(exp, exp.destType, false);
11459 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11460 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11461 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11464 Expression nbExp = GetNonBracketsExp(exp);
11465 bool skipWarning = false;
11466 TypeKind kind = exp.destType.kind;
11467 if(nbExp.type == conditionExp && nbExp.destType && !nbExp.destType.casted && nbExp.destType.kind == exp.destType.kind)
11468 // The if/else operands have already been checked / warned about
11469 skipWarning = true;
11470 if((kind == charType || kind == shortType) && exp.destType.isSigned == exp.expType.signedBeforePromotion && nbExp.type == opExp && nbExp.op.exp1 && nbExp.op.exp2)
11472 int op = nbExp.op.op;
11473 Expression nbExp1, nbExp2;
11478 case '%': case '/':
11479 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11480 from = nbExp1.expType.promotedFrom;
11481 // Division and Modulo will not take more room than type before promotion
11482 if(from == charType || (kind == shortType && from == shortType))
11483 skipWarning = true;
11486 case LEFT_OP: case RIGHT_OP:
11487 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11488 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11489 from = nbExp1.expType.promotedFrom;
11490 // Right shift will not take more room than type before promotion
11491 if(op == RIGHT_OP && (from == charType || (kind == shortType && from == shortType)))
11492 skipWarning = true;
11493 else if(nbExp2.isConstant && nbExp2.type == constantExp && (nbExp.op.op == RIGHT_OP || nbExp1.expType.bitMemberSize))
11495 int n = (int)strtol(nbExp2.constant, null, 0);
11496 int s = from == charType ? 8 : 16;
11497 // Left shifting a bit member constrained in size may still fit in type before promotion
11498 if(nbExp1.expType.bitMemberSize && nbExp1.expType.bitMemberSize < s)
11499 s = nbExp1.expType.bitMemberSize;
11501 // If right shifted enough things will fit in smaller type
11502 if(nbExp.op.op == RIGHT_OP)
11506 if(s <= (kind == charType ? 8 : 16))
11507 skipWarning = true;
11511 if(!exp.destType.isSigned)
11513 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11514 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11515 from = nbExp2.expType.promotedFrom;
11516 // Max value of unsigned type before promotion minus the same will always fit
11517 if((from == charType || from == shortType) && nbExp1.isConstant && nbExp1.type == constantExp)
11519 int n = (int)strtol(nbExp1.constant, null, 0);
11520 if(n == (from == charType ? 255 : 65535))
11521 skipWarning = true;
11527 TypeKind kind1, kind2;
11528 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11529 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11530 kind1 = nbExp1.expType.promotedFrom ? nbExp1.expType.promotedFrom : nbExp1.expType.kind;
11531 kind2 = nbExp2.expType.promotedFrom ? nbExp2.expType.promotedFrom : nbExp2.expType.kind;
11532 if(((kind1 == charType || (kind1 == shortType && kind == shortType)) || MatchTypeExpression(nbExp1, exp.destType, null, false, false)) &&
11533 ((kind2 == charType || (kind2 == shortType && kind == shortType)) || MatchTypeExpression(nbExp2, exp.destType, null, false, false)))
11534 skipWarning = true;
11539 TypeKind kind1, kind2;
11540 nbExp1 = GetNonBracketsExp(nbExp.op.exp1);
11541 nbExp2 = GetNonBracketsExp(nbExp.op.exp2);
11542 kind1 = nbExp1.expType.promotedFrom ? nbExp1.expType.promotedFrom : nbExp1.expType.kind;
11543 kind2 = nbExp2.expType.promotedFrom ? nbExp2.expType.promotedFrom : nbExp2.expType.kind;
11544 if(((kind1 == charType || (kind1 == shortType && kind == shortType)) || MatchTypeExpression(nbExp1, exp.destType, null, false, false)) ||
11545 ((kind2 == charType || (kind2 == shortType && kind == shortType)) || MatchTypeExpression(nbExp2, exp.destType, null, false, false)))
11546 skipWarning = true;
11554 char expString[10240];
11555 expString[0] = '\0';
11556 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11559 CheckExpressionType(exp, exp.destType, false, true);
11562 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11563 if(!sourceFile || (!strstr(sourceFile, "src\\lexer.ec") && !strstr(sourceFile, "src/lexer.ec") &&
11564 !strstr(sourceFile, "src\\grammar.ec") && !strstr(sourceFile, "src/grammar.ec") &&
11565 !strstr(sourceFile, "src\\type.ec") && !strstr(sourceFile, "src/type.ec") &&
11566 !strstr(sourceFile, "src\\expression.ec") && !strstr(sourceFile, "src/expression.ec")))
11569 Compiler_Error($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11571 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11575 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11578 FreeType(exp.expType);
11579 exp.destType.refCount++;
11580 exp.expType = exp.destType;
11586 // Cast function pointers to void * as eC already checked compatibility
11587 else if(exp.destType && exp.destType.kind == pointerType && exp.destType.type && exp.destType.type.kind == functionType &&
11588 exp.expType && (exp.expType.kind == functionType || exp.expType.kind == methodType))
11590 Expression nbExp = GetNonBracketsExp(exp);
11591 if(nbExp.type != castExp || !IsVoidPtrCast(nbExp.cast.typeName))
11593 Expression e = MoveExpContents(exp);
11594 exp.cast.exp = MkExpBrackets(MkListOne(e));
11595 exp.type = castExp;
11596 exp.cast.exp.destType = exp.destType;
11597 if(exp.destType) exp.destType.refCount++;
11598 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
11602 else if(unresolved)
11604 if(exp.identifier._class && exp.identifier._class.name)
11605 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11606 else if(exp.identifier.string && exp.identifier.string[0])
11607 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11609 else if(!exp.expType && exp.type != dummyExp)
11611 char expString[10240];
11612 expString[0] = '\0';
11613 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11614 Compiler_Error($"couldn't determine type of %s\n", expString);
11617 // Let's try to support any_object & typed_object here:
11619 ApplyAnyObjectLogic(exp);
11621 // Mark nohead classes as by reference, unless we're casting them to an integral type
11622 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11623 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11624 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11625 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11627 exp.byReference = true;
11629 yylloc = oldyylloc;
11632 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11634 // THIS CODE WILL FIND NEXT MEMBER...
11637 *curMember = (*curMember).next;
11639 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11641 *curMember = subMemberStack[--(*subMemberStackPos)];
11642 *curMember = (*curMember).next;
11645 // SKIP ALL PROPERTIES HERE...
11646 while((*curMember) && (*curMember).isProperty)
11647 *curMember = (*curMember).next;
11649 if(subMemberStackPos)
11651 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11653 subMemberStack[(*subMemberStackPos)++] = *curMember;
11655 *curMember = (*curMember).members.first;
11656 while(*curMember && (*curMember).isProperty)
11657 *curMember = (*curMember).next;
11665 if(subMemberStackPos && *subMemberStackPos)
11667 *curMember = subMemberStack[--(*subMemberStackPos)];
11668 *curMember = (*curMember).next;
11672 Class lastCurClass = *curClass;
11674 if(*curClass == _class) break; // REACHED THE END
11676 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11677 *curMember = (*curClass).membersAndProperties.first;
11680 while((*curMember) && (*curMember).isProperty)
11681 *curMember = (*curMember).next;
11682 if(subMemberStackPos)
11684 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11686 subMemberStack[(*subMemberStackPos)++] = *curMember;
11688 *curMember = (*curMember).members.first;
11689 while(*curMember && (*curMember).isProperty)
11690 *curMember = (*curMember).next;
11698 static void ProcessInitializer(Initializer init, Type type)
11702 case expInitializer:
11703 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11705 // TESTING THIS FOR SHUTTING = 0 WARNING
11706 if(init.exp && !init.exp.destType)
11708 FreeType(init.exp.destType);
11709 init.exp.destType = type;
11710 if(type) type.refCount++;
11714 ProcessExpressionType(init.exp);
11715 init.isConstant = init.exp.isConstant;
11721 Expression exp = init.exp;
11722 Instantiation inst = exp.instance;
11723 MembersInit members;
11725 init.type = listInitializer;
11726 init.list = MkList();
11730 for(members = inst.members->first; members; members = members.next)
11732 if(members.type == dataMembersInit)
11735 for(member = members.dataMembers->first; member; member = member.next)
11737 ListAdd(init.list, member.initializer);
11738 member.initializer = null;
11741 // Discard all MembersInitMethod
11744 FreeExpression(exp);
11746 case listInitializer:
11749 Type initializerType = null;
11750 Class curClass = null;
11751 DataMember curMember = null;
11752 DataMember subMemberStack[256];
11753 int subMemberStackPos = 0;
11755 if(type && type.kind == arrayType)
11756 initializerType = Dereference(type);
11757 else if(type && (type.kind == structType || type.kind == unionType))
11758 initializerType = type.members.first;
11760 for(i = init.list->first; i; i = i.next)
11762 if(type && type.kind == classType && type._class && type._class.registered)
11764 // 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)
11765 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11766 // TODO: Generate error on initializing a private data member this way from another module...
11769 if(!curMember.dataType)
11770 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11771 initializerType = curMember.dataType;
11774 ProcessInitializer(i, initializerType);
11775 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11776 initializerType = initializerType.next;
11778 init.isConstant = false;
11781 if(type && type.kind == arrayType)
11782 FreeType(initializerType);
11784 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11786 Compiler_Error($"Assigning list initializer to non list\n");
11793 static void ProcessSpecifier(Specifier spec, bool declareStruct, bool warnClasses)
11797 case baseSpecifier:
11799 if(spec.specifier == THISCLASS)
11803 spec.type = nameSpecifier;
11804 spec.name = ReplaceThisClass(thisClass);
11805 spec.symbol = FindClass(spec.name);
11806 ProcessSpecifier(spec, declareStruct, false);
11811 case nameSpecifier:
11813 Symbol symbol = FindType(curContext, spec.name);
11815 DeclareType(curExternal, symbol.type, true, true);
11816 else if(spec.symbol /*&& declareStruct*/)
11818 Class c = spec.symbol.registered;
11819 if(warnClasses && !c)
11820 Compiler_Warning("Undeclared class %s\n", spec.name);
11821 DeclareStruct(curExternal, spec.name, c && c.type == noHeadClass, declareStruct && c && c.type == structClass);
11825 case enumSpecifier:
11830 for(e = spec.list->first; e; e = e.next)
11833 ProcessExpressionType(e.exp);
11836 // Fall through for IDE type processing
11840 case structSpecifier:
11841 case unionSpecifier:
11843 if(spec.definitions)
11846 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11848 ProcessClass(spec.definitions, symbol);
11851 for(def = spec.definitions->first; def; def = def.next)
11853 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11854 ProcessDeclaration(def.decl);
11861 case classSpecifier:
11863 Symbol classSym = FindClass(spec.name);
11864 if(classSym && classSym.registered && classSym.registered.type == structClass)
11865 DeclareStruct(spec.name, false, true);
11873 static void ProcessDeclarator(Declarator decl, bool isFunction)
11877 case identifierDeclarator:
11878 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11880 FreeSpecifier(decl.identifier._class);
11881 decl.identifier._class = null;
11884 case arrayDeclarator:
11886 ProcessExpressionType(decl.array.exp);
11887 case structDeclarator:
11888 case bracketsDeclarator:
11889 case functionDeclarator:
11890 case pointerDeclarator:
11891 case extendedDeclarator:
11892 case extendedDeclaratorEnd:
11894 Identifier id = null;
11895 Specifier classSpec = null;
11896 if(decl.type == functionDeclarator)
11898 id = GetDeclId(decl);
11899 if(id && id._class)
11901 classSpec = id._class;
11905 if(decl.declarator)
11906 ProcessDeclarator(decl.declarator, isFunction);
11907 if(decl.type == functionDeclarator)
11913 qualifiers = MkListOne(classSpec);
11916 if(!decl.function.parameters)
11917 decl.function.parameters = MkList();
11918 decl.function.parameters->Insert(null, param);
11920 if(decl.function.parameters)
11924 for(param = decl.function.parameters->first; param; param = param.next)
11926 if(param.qualifiers)
11929 for(spec = param.qualifiers->first; spec; spec = spec.next)
11931 if(spec.type == baseSpecifier)
11933 if(spec.specifier == TYPED_OBJECT)
11935 Declarator d = param.declarator;
11938 qualifiers = MkListOne(MkSpecifier(VOID));
11939 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11941 if(!d || d.type != pointerDeclarator)
11942 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11944 FreeList(param.qualifiers, FreeSpecifier);
11946 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11947 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11949 DeclareStruct(curExternal, "ecere::com::Class", false, true);
11951 decl.function.parameters->Insert(param, newParam);
11955 else if(spec.specifier == ANY_OBJECT)
11957 Declarator d = param.declarator;
11959 FreeList(param.qualifiers, FreeSpecifier);
11961 param.qualifiers = MkListOne(MkSpecifier(VOID));
11962 if(!d || d.type != pointerDeclarator)
11963 param.qualifiers->Insert(null, MkSpecifier(CONST));
11964 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11967 else if(spec.specifier == THISCLASS)
11971 spec.type = nameSpecifier;
11972 spec.name = ReplaceThisClass(thisClass);
11973 spec.symbol = FindClass(spec.name);
11974 ProcessSpecifier(spec, false, false);
11979 else if(spec.type == nameSpecifier)
11981 ProcessSpecifier(spec, isFunction, true);
11983 else if((spec.type == structSpecifier || spec.type == unionSpecifier) && !spec.definitions && spec.id && spec.id.string)
11985 Declarator d = param.declarator;
11986 if(!d || d.type != pointerDeclarator)
11987 DeclareStruct(curExternal, spec.id.string, false, true);
11992 if(param.declarator)
11993 ProcessDeclarator(param.declarator, false);
12002 static void ProcessDeclaration(Declaration decl, bool warnClasses)
12007 case initDeclaration:
12009 bool declareStruct = false;
12011 lineNum = decl.pos.line;
12012 column = decl.pos.col;
12015 if(decl.declarators)
12019 for(d = decl.declarators->first; d; d = d.next)
12021 Type type, subType;
12022 ProcessDeclarator(d.declarator, false);
12024 type = ProcessType(decl.specifiers, d.declarator);
12028 ProcessInitializer(d.initializer, type);
12030 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
12032 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
12033 d.initializer.exp.type == instanceExp)
12035 if(type.kind == classType && type._class ==
12036 d.initializer.exp.expType._class)
12038 Instantiation inst = d.initializer.exp.instance;
12039 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
12041 d.initializer.exp.instance = null;
12042 if(decl.specifiers)
12043 FreeList(decl.specifiers, FreeSpecifier);
12044 FreeList(decl.declarators, FreeInitDeclarator);
12048 decl.type = instDeclaration;
12053 for(subType = type; subType;)
12055 if(subType.kind == classType)
12057 declareStruct = true;
12060 else if(subType.kind == pointerType)
12062 else if(subType.kind == arrayType)
12063 subType = subType.arrayType;
12073 if(decl.specifiers)
12076 for(s = decl.specifiers->first; s; s = s.next)
12078 ProcessSpecifier(s, declareStruct, true);
12083 case instDeclaration:
12085 ProcessInstantiationType(decl.inst);
12088 case structDeclaration:
12092 bool declareStruct = false;
12094 if(decl.declarators)
12096 for(d = decl.declarators->first; d; d = d.next)
12098 Type type = ProcessType(decl.specifiers, d.declarator);
12100 ProcessDeclarator(d, false);
12101 for(subType = type; subType;)
12103 if(subType.kind == classType)
12105 declareStruct = true;
12108 else if(subType.kind == pointerType)
12110 else if(subType.kind == arrayType)
12111 subType = subType.arrayType;
12118 if(decl.specifiers)
12120 for(spec = decl.specifiers->first; spec; spec = spec.next)
12121 ProcessSpecifier(spec, declareStruct, warnClasses);
12128 static FunctionDefinition curFunction;
12130 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
12132 char propName[1024], propNameM[1024];
12133 char getName[1024], setName[1024];
12136 DeclareProperty(curExternal, prop, setName, getName);
12138 // eInstance_FireWatchers(object, prop);
12139 strcpy(propName, "__ecereProp_");
12140 FullClassNameCat(propName, prop._class.fullName, false);
12141 strcat(propName, "_");
12142 FullClassNameCat(propName, prop.name, true);
12144 strcpy(propNameM, "__ecerePropM_");
12145 FullClassNameCat(propNameM, prop._class.fullName, false);
12146 strcat(propNameM, "_");
12147 FullClassNameCat(propNameM, prop.name, true);
12149 if(prop.isWatchable)
12152 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
12153 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12154 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
12157 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
12158 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
12159 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
12161 DeclareFunctionUtil(curExternal, "eInstance_FireWatchers");
12166 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
12167 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12168 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
12171 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
12172 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
12173 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
12175 DeclareFunctionUtil(curExternal, "eInstance_FireSelfWatchers");
12178 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
12179 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12180 curFunction.propSet.fireWatchersDone = true;
12183 static void ProcessStatement(Statement stmt)
12187 lineNum = stmt.pos.line;
12188 column = stmt.pos.col;
12193 ProcessStatement(stmt.labeled.stmt);
12196 // This expression should be constant...
12197 if(stmt.caseStmt.exp)
12199 FreeType(stmt.caseStmt.exp.destType);
12200 stmt.caseStmt.exp.destType = curSwitchType;
12201 if(curSwitchType) curSwitchType.refCount++;
12202 ProcessExpressionType(stmt.caseStmt.exp);
12203 ComputeExpression(stmt.caseStmt.exp);
12205 if(stmt.caseStmt.stmt)
12206 ProcessStatement(stmt.caseStmt.stmt);
12210 if(stmt.compound.context)
12215 Statement prevCompound = curCompound;
12216 Context prevContext = curContext;
12218 if(!stmt.compound.isSwitch)
12219 curCompound = stmt;
12220 curContext = stmt.compound.context;
12222 if(stmt.compound.declarations)
12224 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
12225 ProcessDeclaration(decl, true);
12227 if(stmt.compound.statements)
12229 for(s = stmt.compound.statements->first; s; s = s.next)
12230 ProcessStatement(s);
12233 curContext = prevContext;
12234 curCompound = prevCompound;
12238 case expressionStmt:
12241 if(stmt.expressions)
12243 for(exp = stmt.expressions->first; exp; exp = exp.next)
12244 ProcessExpressionType(exp);
12252 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
12253 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
12254 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
12255 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
12257 ProcessExpressionType(exp);
12259 if(stmt.ifStmt.stmt)
12260 ProcessStatement(stmt.ifStmt.stmt);
12261 if(stmt.ifStmt.elseStmt)
12262 ProcessStatement(stmt.ifStmt.elseStmt);
12267 Type oldSwitchType = curSwitchType;
12268 if(stmt.switchStmt.exp)
12271 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
12281 e.exp.destType = destType;
12284 ProcessExpressionType(exp);
12287 curSwitchType = exp.expType;
12290 ProcessStatement(stmt.switchStmt.stmt);
12291 curSwitchType = oldSwitchType;
12296 if(stmt.whileStmt.exp)
12300 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
12301 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
12302 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
12303 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
12305 ProcessExpressionType(exp);
12308 if(stmt.whileStmt.stmt)
12309 ProcessStatement(stmt.whileStmt.stmt);
12314 if(stmt.doWhile.exp)
12318 if(stmt.doWhile.exp->last)
12320 FreeType(((Expression)stmt.doWhile.exp->last).destType);
12321 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
12322 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
12324 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
12326 ProcessExpressionType(exp);
12329 if(stmt.doWhile.stmt)
12330 ProcessStatement(stmt.doWhile.stmt);
12336 if(stmt.forStmt.init)
12337 ProcessStatement(stmt.forStmt.init);
12339 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
12341 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
12342 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
12343 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
12346 if(stmt.forStmt.check)
12347 ProcessStatement(stmt.forStmt.check);
12348 if(stmt.forStmt.increment)
12350 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
12351 ProcessExpressionType(exp);
12354 if(stmt.forStmt.stmt)
12355 ProcessStatement(stmt.forStmt.stmt);
12360 Identifier id = stmt.forEachStmt.id;
12361 OldList * exp = stmt.forEachStmt.exp;
12362 OldList * filter = stmt.forEachStmt.filter;
12363 Statement block = stmt.forEachStmt.stmt;
12364 char iteratorType[1024];
12367 bool isBuiltin = exp && exp->last &&
12368 (((Expression)exp->last).type == ExpressionType::arrayExp ||
12369 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
12370 Expression arrayExp;
12371 const char * typeString = null;
12372 int builtinCount = 0;
12374 for(e = exp ? exp->first : null; e; e = e.next)
12378 FreeType(e.destType);
12379 e.destType = ProcessTypeString("Container", false);
12381 if(!isBuiltin || e.next)
12382 ProcessExpressionType(e);
12385 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
12386 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
12387 eClass_IsDerived(source._class.registered, containerClass)))
12389 Class _class = source ? source._class.registered : null;
12391 Expression expIt = null;
12392 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
12393 // TODO: Find these once on loadup
12394 Class arrayClass = eSystem_FindClass(privateModule, "Array");
12395 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
12396 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
12400 stmt.type = compoundStmt;
12402 stmt.compound.context = Context { };
12403 stmt.compound.context.parent = curContext;
12404 curContext = stmt.compound.context;
12407 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
12409 Class mapClass = eSystem_FindClass(privateModule, "Map");
12410 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
12411 isCustomAVLTree = true;
12412 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
12414 else */if(eClass_IsDerived(source._class.registered, mapClass))
12417 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
12418 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
12420 Class listClass = eSystem_FindClass(privateModule, "List");
12422 isList = eClass_IsDerived(source._class.registered, listClass);
12425 if(inCompiler && isArray)
12428 OldList * specs = MkList();
12429 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12430 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12431 stmt.compound.declarations = MkListOne(
12432 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12433 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12434 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
12435 MkInitializerAssignment(MkExpBrackets(exp))))));
12440 char typeStringBuf[1024];
12442 // TODO: Merge this code?
12443 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
12444 if(((Expression)exp->last).type == castExp)
12446 TypeName typeName = ((Expression)exp->last).cast.typeName;
12448 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
12451 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
12452 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
12453 arrayExp.destType._class.registered.templateArgs)
12455 Class templateClass = arrayExp.destType._class.registered;
12456 typeString = templateClass.templateArgs[2].dataTypeString;
12458 else if(arrayExp.list)
12460 // Guess type from expressions in the array
12462 for(e = arrayExp.list->first; e; e = e.next)
12464 ProcessExpressionType(e);
12467 if(!type) { type = e.expType; type.refCount++; }
12470 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
12471 if(!MatchTypeExpression(e, type, null, false, true))
12477 e = arrayExp.list->first;
12478 ProcessExpressionType(e);
12481 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
12482 if(!MatchTypeExpression(e, type, null, false, true))
12484 FreeType(e.expType);
12495 FreeType(e.expType);
12502 typeStringBuf[0] = '\0';
12503 PrintType(type, typeStringBuf, false, true);
12504 typeString = typeStringBuf;
12512 OldList * initializers = MkList();
12514 OldList * specs = MkList();
12519 builtinCount = arrayExp.list->count;
12520 type = ProcessTypeString(typeString, false);
12521 while((e = arrayExp.list->first))
12523 arrayExp.list->Remove(e);
12526 ProcessExpressionType(e);
12528 ListAdd(initializers, MkInitializerAssignment(e));
12531 delete arrayExp.list;
12533 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12535 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12536 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12538 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12540 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12541 ), MkInitializerList(initializers)))));
12542 FreeList(exp, FreeExpression);
12544 else if(arrayExp.list)
12547 type = ProcessTypeString(typeString, false);
12548 for(e = arrayExp.list->first; e; e = e.next)
12552 ProcessExpressionType(e);
12559 arrayExp.expType = ProcessTypeString("Container", false);
12560 Compiler_Error($"Couldn't determine type of array elements\n");
12565 OldList * specs = MkList();
12567 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12568 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12569 stmt.compound.declarations = MkListOne(
12570 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12571 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12572 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12573 MkInitializerAssignment(MkExpBrackets(exp))))));
12576 else if(inCompiler && isLinkList && !isList)
12579 OldList * specs = MkList();
12580 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12581 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12582 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12583 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12584 MkInitializerAssignment(MkExpBrackets(exp))))));
12586 /*else if(isCustomAVLTree)
12589 OldList * specs = MkList();
12590 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12591 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12592 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12593 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12594 MkInitializerAssignment(MkExpBrackets(exp))))));
12596 else if(inCompiler && _class.templateArgs)
12599 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12601 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12603 stmt.compound.declarations = MkListOne(
12604 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12605 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12606 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12610 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12614 // Reparent sub-contexts in this statement
12618 if(block.compound.context)
12619 block.compound.context.parent = stmt.compound.context;
12622 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12623 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12624 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12625 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12628 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12629 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12632 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12633 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12636 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12637 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12640 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12641 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12644 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12645 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12647 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12650 case expressionStmt:
12656 case badDeclarationStmt:
12657 case fireWatchersStmt:
12658 case stopWatchingStmt:
12666 block = MkIfStmt(filter, block, null);
12670 stmt.compound.statements = MkListOne(MkForStmt(
12671 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12672 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12673 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12674 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12676 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12677 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12678 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12683 //OldList * specs = MkList();
12684 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12686 sprintf(count, "%d", builtinCount);
12688 stmt.compound.statements = MkListOne(MkForStmt(
12689 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12690 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12691 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12692 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12696 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12697 stmt.compound.statements = MkListOne(MkForStmt(
12698 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12699 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12700 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12701 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12704 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12705 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12706 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12708 else if(isLinkList && !isList)
12710 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12711 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12712 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12713 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12715 stmt.compound.statements = MkListOne(MkForStmt(
12716 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12717 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12718 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12723 OldList * specs = MkList();
12724 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12725 stmt.compound.statements = MkListOne(MkForStmt(
12726 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12727 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12728 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12729 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12730 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12733 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12734 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12735 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12737 /*else if(isCustomAVLTree)
12739 stmt.compound.statements = MkListOne(MkForStmt(
12740 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12741 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12742 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12743 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12746 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12747 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12748 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12752 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12753 MkIdentifier("Next")), null)), block));
12755 ProcessExpressionType(expIt);
12756 if(stmt.compound.declarations->first)
12757 ProcessDeclaration(stmt.compound.declarations->first, true);
12760 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12762 ProcessStatement(stmt);
12765 ProcessStatement(stmt.forEachStmt.stmt);
12767 curContext = stmt.compound.context.parent;
12772 Compiler_Error($"Expression is not a container\n");
12785 if(stmt.expressions)
12787 for(exp = stmt.expressions->first; exp; exp = exp.next)
12791 if(curFunction && !curFunction.type)
12792 curFunction.type = ProcessType(
12793 curFunction.specifiers, curFunction.declarator);
12794 FreeType(exp.destType);
12795 // TODO: current property if not compiling
12796 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12797 if(exp.destType) exp.destType.refCount++;
12799 ProcessExpressionType(exp);
12804 case badDeclarationStmt:
12806 ProcessDeclaration(stmt.decl, true);
12812 if(stmt.asmStmt.inputFields)
12814 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12815 if(field.expression)
12816 ProcessExpressionType(field.expression);
12818 if(stmt.asmStmt.outputFields)
12820 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12821 if(field.expression)
12822 ProcessExpressionType(field.expression);
12824 if(stmt.asmStmt.clobberedFields)
12826 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12828 if(field.expression)
12829 ProcessExpressionType(field.expression);
12836 PropertyWatch propWatch;
12837 OldList * watches = stmt._watch.watches;
12838 Expression object = stmt._watch.object;
12839 Expression watcher = stmt._watch.watcher;
12841 ProcessExpressionType(watcher);
12843 ProcessExpressionType(object);
12847 if(watcher || thisClass)
12849 External external = curExternal;
12850 Context context = curContext;
12852 stmt.type = expressionStmt;
12853 stmt.expressions = MkList();
12855 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12857 ClassFunction func;
12858 char watcherName[1024];
12859 Class watcherClass = watcher ?
12860 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12861 External createdExternal;
12863 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12864 if(propWatch.deleteWatch)
12865 strcat(watcherName, "_delete");
12869 for(propID = propWatch.properties->first; propID; propID = propID.next)
12871 strcat(watcherName, "_");
12872 strcat(watcherName, propID.string);
12876 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12878 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12879 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12880 ProcessClassFunctionBody(func, propWatch.compound);
12881 propWatch.compound = null;
12883 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12885 FreeClassFunction(func);
12887 curExternal = createdExternal;
12888 ProcessFunction(createdExternal.function);
12890 if(propWatch.deleteWatch)
12892 OldList * args = MkList();
12893 ListAdd(args, CopyExpression(object));
12894 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12895 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12896 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12900 Class _class = object.expType._class.registered;
12903 for(propID = propWatch.properties->first; propID; propID = propID.next)
12905 char propName[1024];
12906 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12909 char getName[1024], setName[1024];
12910 OldList * args = MkList();
12912 DeclareProperty(createdExternal, prop, setName, getName);
12914 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12915 strcpy(propName, "__ecereProp_");
12916 FullClassNameCat(propName, prop._class.fullName, false);
12917 strcat(propName, "_");
12918 FullClassNameCat(propName, prop.name, true);
12920 ListAdd(args, CopyExpression(object));
12921 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12922 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12923 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpIdentifier(MkIdentifier(watcherName))));
12925 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12927 external.CreateUniqueEdge(createdExternal, true);
12930 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12935 Compiler_Error($"Invalid watched object\n");
12938 curExternal = external;
12939 curContext = context;
12942 FreeExpression(watcher);
12944 FreeExpression(object);
12945 FreeList(watches, FreePropertyWatch);
12948 Compiler_Error($"No observer specified and not inside a class\n");
12952 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12954 ProcessStatement(propWatch.compound);
12960 case fireWatchersStmt:
12962 OldList * watches = stmt._watch.watches;
12963 Expression object = stmt._watch.object;
12965 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12966 // printf("%X\n", watches);
12967 // printf("%X\n", stmt._watch.watches);
12969 ProcessExpressionType(object);
12974 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12980 stmt.type = expressionStmt;
12981 stmt.expressions = MkList();
12983 // Check if we're inside a property set
12984 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12986 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12990 //Compiler_Error($"No property specified and not inside a property set\n");
12994 for(propID = watches->first; propID; propID = propID.next)
12996 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12999 CreateFireWatcher(prop, object, stmt);
13002 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
13007 // Fire all properties!
13010 for(base = _class; base; base = base.base)
13012 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
13014 if(prop.isProperty && prop.isWatchable)
13016 CreateFireWatcher(prop, object, stmt);
13023 FreeExpression(object);
13024 FreeList(watches, FreeIdentifier);
13027 Compiler_Error($"Invalid object specified and not inside a class\n");
13031 case stopWatchingStmt:
13033 OldList * watches = stmt._watch.watches;
13034 Expression object = stmt._watch.object;
13035 Expression watcher = stmt._watch.watcher;
13038 ProcessExpressionType(object);
13040 ProcessExpressionType(watcher);
13043 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
13045 if(watcher || thisClass)
13051 stmt.type = expressionStmt;
13052 stmt.expressions = MkList();
13057 // eInstance_StopWatching(object, null, watcher);
13059 ListAdd(args, CopyExpression(object));
13060 ListAdd(args, MkExpConstant("0"));
13061 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
13062 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
13066 for(propID = watches->first; propID; propID = propID.next)
13068 char propName[1024];
13069 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
13072 char getName[1024], setName[1024];
13073 OldList * args = MkList();
13075 DeclareProperty(curExternal, prop, setName, getName);
13077 // eInstance_StopWatching(object, prop, watcher);
13078 strcpy(propName, "__ecereProp_");
13079 FullClassNameCat(propName, prop._class.fullName, false);
13080 strcat(propName, "_");
13081 FullClassNameCat(propName, prop.name, true);
13083 ListAdd(args, CopyExpression(object));
13084 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
13085 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
13086 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
13089 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
13094 FreeExpression(object);
13096 FreeExpression(watcher);
13097 FreeList(watches, FreeIdentifier);
13100 Compiler_Error($"Invalid object specified and not inside a class\n");
13103 Compiler_Error($"No observer specified and not inside a class\n");
13110 static void ProcessFunction(FunctionDefinition function)
13112 Identifier id = GetDeclId(function.declarator);
13113 Symbol symbol = function.declarator ? function.declarator.symbol : null;
13114 Type type = symbol ? symbol.type : null;
13115 Class oldThisClass = thisClass;
13116 Context oldTopContext = topContext;
13118 yylloc = function.loc;
13119 // Process thisClass
13121 if(type && type.thisClass)
13123 Symbol classSym = type.thisClass;
13124 Class _class = type.thisClass.registered;
13125 char className[1024];
13126 char structName[1024];
13127 Declarator funcDecl;
13130 bool typedObject = false;
13132 if(_class && !_class.base)
13134 _class = currentClass;
13135 if(_class && !_class.symbol)
13136 _class.symbol = FindClass(_class.fullName);
13137 classSym = _class ? _class.symbol : null;
13138 typedObject = true;
13141 thisClass = _class;
13143 if(inCompiler && _class)
13145 if(type.kind == functionType)
13147 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
13149 //TypeName param = symbol.type.params.first;
13150 Type param = symbol.type.params.first;
13151 symbol.type.params.Remove(param);
13152 //FreeTypeName(param);
13155 if(type.classObjectType != classPointer)
13157 symbol.type.params.Insert(null, MkClassType(_class.fullName));
13158 symbol.type.staticMethod = true;
13159 symbol.type.thisClass = null;
13161 // HIGH DANGER: VERIFYING THIS...
13162 symbol.type.extraParam = false;
13166 strcpy(className, "__ecereClass_");
13167 FullClassNameCat(className, _class.fullName, true);
13170 FullClassNameCat(structName, _class.fullName, false);
13173 funcDecl = GetFuncDecl(function.declarator);
13176 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
13178 TypeName param = funcDecl.function.parameters->first;
13179 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
13181 funcDecl.function.parameters->Remove(param);
13182 FreeTypeName(param);
13186 if(!function.propertyNoThis)
13188 TypeName thisParam = null;
13190 if(type.classObjectType != classPointer)
13192 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
13193 if(!funcDecl.function.parameters)
13194 funcDecl.function.parameters = MkList();
13195 funcDecl.function.parameters->Insert(null, thisParam);
13200 if(type.classObjectType != classPointer)
13202 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
13203 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
13206 thisParam = TypeName
13208 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
13209 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
13211 DeclareStruct(curExternal, "ecere::com::Class", false, true);
13212 funcDecl.function.parameters->Insert(null, thisParam);
13217 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13219 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13220 funcDecl = GetFuncDecl(initDecl.declarator);
13223 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
13225 TypeName param = funcDecl.function.parameters->first;
13226 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
13228 funcDecl.function.parameters->Remove(param);
13229 FreeTypeName(param);
13233 if(type.classObjectType != classPointer)
13235 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
13237 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
13239 if(!funcDecl.function.parameters)
13240 funcDecl.function.parameters = MkList();
13241 funcDecl.function.parameters->Insert(null, thisParam);
13248 // Add this to the context
13251 if(type.classObjectType != classPointer)
13253 thisSymbol = Symbol
13255 string = CopyString("this");
13256 type = classSym ? MkClassType(classSym.string) : null;
13258 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
13260 if(typedObject && thisSymbol.type)
13262 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
13263 thisSymbol.type.byReference = type.byReference;
13264 thisSymbol.type.typedByReference = type.byReference;
13269 // Pointer to class data
13270 if(inCompiler && _class && _class.type == normalClass && type.classObjectType != classPointer)
13272 DataMember member = null;
13275 for(base = _class; base && base.type != systemClass; base = base.next)
13277 for(member = base.membersAndProperties.first; member; member = member.next)
13278 if(!member.isProperty)
13284 for(member = _class.membersAndProperties.first; member; member = member.next)
13285 if(!member.isProperty)
13289 char pointerName[1024];
13292 Initializer initializer;
13293 Expression exp, bytePtr;
13295 strcpy(pointerName, "__ecerePointer_");
13296 FullClassNameCat(pointerName, _class.fullName, false);
13298 char className[1024];
13299 strcpy(className, "__ecereClass_");
13300 FullClassNameCat(className, classSym.string, true);
13302 DeclareClass(curExternal, classSym, className);
13306 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
13311 if(_class.offset && _class.offset == (_class.base.type == noHeadClass ? _class.base.memberOffset : _class.base.structSize))
13313 e = MkExpClassSize(MkSpecifierName(_class.base.fullName));
13314 ProcessExpressionType(e);
13319 sprintf(string, "%d", _class.offset); // Need Bootstrap Fix
13320 e = MkExpConstant(string);
13322 exp = QBrackets(MkExpOp(bytePtr, '+', e));
13326 // ([bytePtr] + [className]->offset)
13327 exp = QBrackets(MkExpOp(bytePtr, '+',
13328 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
13331 // (this ? [exp] : 0)
13332 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
13336 kind = pointerType;
13337 type = Type { refCount = 1, kind = voidType };
13342 yylloc = function.body.loc;
13343 // ([structName] *) [exp]
13344 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
13345 initializer = MkInitializerAssignment(
13346 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
13348 // [structName] * [pointerName] = [initializer];
13349 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
13352 Context prevContext = curContext;
13354 curContext = function.body.compound.context;
13356 decl = MkDeclaration((list = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null))),
13357 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
13358 list->Insert(null, MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
13360 curContext = prevContext;
13364 decl.symbol = null;
13366 if(!function.body.compound.declarations)
13367 function.body.compound.declarations = MkList();
13368 function.body.compound.declarations->Insert(null, decl);
13374 // Loop through the function and replace undeclared identifiers
13375 // which are a member of the class (methods, properties or data)
13376 // by "this.[member]"
13383 FreeSpecifier(id._class);
13386 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
13388 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
13389 id = GetDeclId(initDecl.declarator);
13391 FreeSpecifier(id._class);
13396 topContext = function.body.compound.context;
13398 FunctionDefinition oldFunction = curFunction;
13399 curFunction = function;
13401 ProcessStatement(function.body);
13403 // If this is a property set and no firewatchers has been done yet, add one here
13404 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
13406 Statement prevCompound = curCompound;
13407 Context prevContext = curContext;
13409 Statement fireWatchers = MkFireWatchersStmt(null, null);
13410 if(!function.body.compound.statements) function.body.compound.statements = MkList();
13411 ListAdd(function.body.compound.statements, fireWatchers);
13413 curCompound = function.body;
13414 curContext = function.body.compound.context;
13416 ProcessStatement(fireWatchers);
13418 curContext = prevContext;
13419 curCompound = prevCompound;
13423 curFunction = oldFunction;
13426 if(function.declarator)
13428 ProcessDeclarator(function.declarator, true);
13431 topContext = oldTopContext;
13432 thisClass = oldThisClass;
13435 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
13436 static void ProcessClass(OldList definitions, Symbol symbol)
13439 External external = curExternal;
13440 Class regClass = symbol ? symbol.registered : null;
13442 // Process all functions
13443 for(def = definitions.first; def; def = def.next)
13445 if(def.type == functionClassDef)
13447 if(def.function.declarator)
13448 curExternal = def.function.declarator.symbol.pointerExternal;
13450 curExternal = external;
13452 ProcessFunction((FunctionDefinition)def.function);
13454 else if(def.type == declarationClassDef)
13456 if(def.decl.type == instDeclaration)
13458 thisClass = regClass;
13459 ProcessInstantiationType(def.decl.inst);
13465 Class backThisClass = thisClass;
13466 if(regClass) thisClass = regClass;
13467 ProcessDeclaration(def.decl, symbol ? true : false);
13468 thisClass = backThisClass;
13471 else if(def.type == defaultPropertiesClassDef && def.defProperties)
13473 MemberInit defProperty;
13475 // Add this to the context
13476 Symbol thisSymbol = Symbol
13478 string = CopyString("this");
13479 type = regClass ? MkClassType(regClass.fullName) : null;
13481 globalContext.symbols.Add((BTNode)thisSymbol);
13483 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
13485 thisClass = regClass;
13486 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
13490 globalContext.symbols.Remove((BTNode)thisSymbol);
13491 FreeSymbol(thisSymbol);
13493 else if(def.type == propertyClassDef && def.propertyDef)
13495 PropertyDef prop = def.propertyDef;
13497 // Add this to the context
13498 thisClass = regClass;
13505 string = CopyString("this");
13506 type = MkClassType(regClass.fullName);
13508 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13511 curExternal = prop.symbol ? prop.symbol.externalSet : null;
13512 ProcessStatement(prop.setStmt);
13520 string = CopyString("this");
13521 type = MkClassType(regClass.fullName);
13523 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13526 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13527 ProcessStatement(prop.getStmt);
13535 string = CopyString("this");
13536 type = MkClassType(regClass.fullName);
13538 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13541 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13542 ProcessStatement(prop.issetStmt);
13547 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13549 PropertyWatch propertyWatch = def.propertyWatch;
13551 thisClass = regClass;
13552 if(propertyWatch.compound)
13556 string = CopyString("this");
13557 type = regClass ? MkClassType(regClass.fullName) : null;
13560 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13562 curExternal = null;
13563 ProcessStatement(propertyWatch.compound);
13570 void DeclareFunctionUtil(External neededBy, const String s)
13572 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13577 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13578 strcpy(name, "__ecereFunction_");
13579 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13580 DeclareFunction(neededBy, function, name);
13583 FindSymbol(s, globalContext, globalContext, false, false);
13586 bool reachedPass15;
13588 void ComputeDataTypes()
13592 currentClass = null;
13594 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13596 DeclareStruct(null, "ecere::com::Class", false, true);
13597 DeclareStruct(null, "ecere::com::Instance", false, true);
13598 DeclareStruct(null, "ecere::com::Property", false, true);
13599 DeclareStruct(null, "ecere::com::DataMember", false, true);
13600 DeclareStruct(null, "ecere::com::Method", false, true);
13601 DeclareStruct(null, "ecere::com::SerialBuffer", false, true);
13602 DeclareStruct(null, "ecere::com::ClassTemplateArgument", false, true);
13604 DeclareFunctionUtil(null, "eSystem_New");
13605 DeclareFunctionUtil(null, "eSystem_New0");
13606 DeclareFunctionUtil(null, "eSystem_Renew");
13607 DeclareFunctionUtil(null, "eSystem_Renew0");
13608 DeclareFunctionUtil(null, "eSystem_Delete");
13609 DeclareFunctionUtil(null, "eClass_GetProperty");
13610 DeclareFunctionUtil(null, "eClass_SetProperty");
13611 DeclareFunctionUtil(null, "eInstance_FireSelfWatchers");
13612 DeclareFunctionUtil(null, "eInstance_SetMethod");
13613 DeclareFunctionUtil(null, "eInstance_IncRef");
13614 DeclareFunctionUtil(null, "eInstance_StopWatching");
13615 DeclareFunctionUtil(null, "eInstance_Watch");
13616 DeclareFunctionUtil(null, "eInstance_FireWatchers");
13617 reachedPass15 = true;
13619 for(external = ast->first; external; external = external.next)
13621 afterExternal = curExternal = external;
13622 if(external.type == functionExternal)
13626 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13627 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13630 currentClass = external.function._class;
13631 ProcessFunction(external.function);
13633 // There shouldn't be any _class member access here anyways...
13634 else if(external.type == declarationExternal)
13636 if(memoryGuard && external.declaration && external.declaration.type == instDeclaration)
13638 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13639 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13642 currentClass = null;
13643 if(external.declaration)
13644 ProcessDeclaration(external.declaration, true);
13646 else if(external.type == classExternal)
13648 ClassDefinition _class = external._class;
13649 currentClass = external.symbol.registered;
13652 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13653 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13655 if(_class.definitions)
13657 ProcessClass(_class.definitions, _class.symbol);
13661 // Free class data...
13662 ast->Remove(external);
13666 else if(external.type == nameSpaceExternal)
13668 thisNameSpace = external.id.string;
13671 currentClass = null;
13672 thisNameSpace = null;
13673 curExternal = null;