4 #include <stdlib.h> // For strtoll
7 // UNTIL IMPLEMENTED IN GRAMMAR
8 #define ACCESS_CLASSDATA(_class, baseClass) \
9 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
11 #define YYLTYPE Location
15 extern int returnCode;
16 extern Expression parsedExpression;
18 public void SetYydebug(bool b) { yydebug = b; }
23 // TODO: Reset this to 0 on reinitialization
26 int expression_yyparse();
27 static Statement curCompound;
28 External curExternal, afterExternal;
29 static Type curSwitchType;
30 static Class currentClass;
32 public void SetThisClass(Class c) { thisClass = c; } public Class GetThisClass() { return thisClass; }
33 static char * thisNameSpace;
34 /*static */Class containerClass;
35 bool thisClassParams = true;
37 uint internalValueCounter;
40 Time findSymbolTotalTime;
43 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
44 /*static */public void PrintExpression(Expression exp, char * string)
50 bool backOutputLineNumbers = outputLineNumbers;
51 outputLineNumbers = false;
54 OutputExpression(exp, f);
56 count = strlen(string);
57 count += f.Read(string + count, 1, 1023);
61 outputLineNumbers = backOutputLineNumbers;
65 Type ProcessTemplateParameterType(TemplateParameter param)
67 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
69 // TOFIX: Will need to free this Type
72 if(param.dataTypeString)
73 param.baseType = ProcessTypeString(param.dataTypeString, false);
75 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
77 return param.baseType;
82 bool NeedCast(Type type1, Type type2)
84 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
86 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
91 if(type1.kind == type2.kind)
102 if(type1.passAsTemplate && !type2.passAsTemplate)
104 return type1.isSigned != type2.isSigned;
106 return type1._class != type2._class;
108 return NeedCast(type1.type, type2.type);
110 return true; //false; ????
116 static void ReplaceClassMembers(Expression exp, Class _class)
118 if(exp.type == identifierExp && exp.identifier)
120 Identifier id = exp.identifier;
122 Symbol symbol = null;
123 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
125 // First, check if the identifier is declared inside the function
126 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
128 symbol = (Symbol)ctx.symbols.FindString(id.string);
133 // If it is not, check if it is a member of the _class
134 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
136 Property prop = eClass_FindProperty(_class, id.string, privateModule);
137 Method method = null;
138 DataMember member = null;
139 ClassProperty classProp = null;
142 method = eClass_FindMethod(_class, id.string, privateModule);
145 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
146 if(!prop && !method && !member)
148 classProp = eClass_FindClassProperty(_class, id.string);
150 if(prop || method || member || classProp)
152 // Replace by this.[member]
153 exp.type = memberExp;
154 exp.member.member = id;
155 exp.member.memberType = unresolvedMember;
156 exp.member.exp = QMkExpId("this");
157 //exp.member.exp.loc = exp.loc;
158 exp.addedThis = true;
160 else if(_class && _class.templateParams.first)
163 for(sClass = _class; sClass; sClass = sClass.base)
165 if(sClass.templateParams.first)
167 ClassTemplateParameter param;
168 for(param = sClass.templateParams.first; param; param = param.next)
170 if(param.type == expression && !strcmp(param.name, id.string))
172 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
177 OldList * specs = MkList();
179 FreeIdentifier(exp.member.member);
181 ProcessExpressionType(argExp);
183 decl = SpecDeclFromString(param.dataTypeString, specs, null);
185 exp.expType = ProcessType(specs, decl);
187 // *[expType] *[argExp]
188 exp.type = bracketsExp;
189 exp.list = MkListOne(MkExpOp(null, '*',
190 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
201 ////////////////////////////////////////////////////////////////////////
202 // PRINTING ////////////////////////////////////////////////////////////
203 ////////////////////////////////////////////////////////////////////////
205 public char * PrintInt(int64 result)
209 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
211 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
212 if(result > MAXINT || result < MININT)
214 return CopyString(temp);
217 public char * PrintUInt(uint64 result)
220 if(result > MAXDWORD)
221 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
222 else if(result > MAXINT)
223 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
225 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
226 return CopyString(temp);
229 public char * PrintInt64(int64 result)
232 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
233 return CopyString(temp);
236 public char * PrintUInt64(uint64 result)
239 if(result > MAXINT64)
240 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
242 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
243 return CopyString(temp);
246 public char * PrintHexUInt(uint64 result)
249 if(result > MAXDWORD)
250 sprintf(temp, FORMAT64HEX /*"0x%I64xLL"*/, result);
252 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
253 if(result > MAXDWORD)
255 return CopyString(temp);
258 public char * PrintHexUInt64(uint64 result)
261 if(result > MAXDWORD)
262 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
264 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
265 return CopyString(temp);
268 public char * PrintShort(short result)
271 sprintf(temp, "%d", (unsigned short)result);
272 return CopyString(temp);
275 public char * PrintUShort(unsigned short result)
279 sprintf(temp, "0x%X", (int)result);
281 sprintf(temp, "%d", (int)result);
282 return CopyString(temp);
285 public char * PrintChar(char result)
288 if(result > 0 && isprint(result))
289 sprintf(temp, "'%c'", result);
291 sprintf(temp, "%d", (int)result);
293 //sprintf(temp, "%#X", result);
294 sprintf(temp, "0x%X", (unsigned char)result);
295 return CopyString(temp);
298 public char * PrintUChar(unsigned char result)
301 sprintf(temp, "0x%X", result);
302 return CopyString(temp);
305 public char * PrintFloat(float result)
311 strcpy(temp, "-inf");
315 else if(result.isNan)
318 strcpy(temp, "-nan");
323 sprintf(temp, "%.16ff", result);
324 return CopyString(temp);
327 public char * PrintDouble(double result)
333 strcpy(temp, "-inf");
337 else if(result.isNan)
340 strcpy(temp, "-nan");
345 sprintf(temp, "%.16f", result);
346 return CopyString(temp);
349 ////////////////////////////////////////////////////////////////////////
350 ////////////////////////////////////////////////////////////////////////
352 //public Operand GetOperand(Expression exp);
354 #define GETVALUE(name, t) \
355 public bool GetOp##name(Operand op2, t * value2) \
357 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
358 else if(op2.kind == intType) *value2 = (t) op2.ui; \
359 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
360 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
361 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
362 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
363 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
364 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
365 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
366 else if(op2.kind == shortType) *value2 = (t) op2.us; \
367 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
368 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
369 else if(op2.kind == floatType) *value2 = (t) op2.f; \
370 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
371 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
376 public bool Get##name(Expression exp, t * value2) \
378 Operand op2 = GetOperand(exp); \
379 return GetOp##name(op2, value2); \
382 // To help the deubugger currently not preprocessing...
385 GETVALUE(Int, HELP(int));
386 GETVALUE(UInt, HELP(unsigned int));
387 GETVALUE(Int64, HELP(int64));
388 GETVALUE(UInt64, HELP(uint64));
389 GETVALUE(IntPtr, HELP(intptr));
390 GETVALUE(UIntPtr, HELP(uintptr));
391 GETVALUE(IntSize, HELP(intsize));
392 GETVALUE(UIntSize, HELP(uintsize));
393 GETVALUE(Short, HELP(short));
394 GETVALUE(UShort, HELP(unsigned short));
395 GETVALUE(Char, HELP(char));
396 GETVALUE(UChar, HELP(unsigned char));
397 GETVALUE(Float, HELP(float));
398 GETVALUE(Double, HELP(double));
400 void ComputeExpression(Expression exp);
402 void ComputeClassMembers(Class _class, bool isMember)
404 DataMember member = isMember ? (DataMember) _class : null;
405 Context context = isMember ? null : SetupTemplatesContext(_class);
406 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
407 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
410 int unionMemberOffset = 0;
414 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
415 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
420 member.memberOffset = 0;
421 if(targetBits < sizeof(void *) * 8)
422 member.structAlignment = 0;
424 else if(targetBits < sizeof(void *) * 8)
425 _class.structAlignment = 0;
427 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
428 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
429 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
431 if(!member && _class.destructionWatchOffset)
432 _class.memberOffset += sizeof(OldList);
434 // To avoid reentrancy...
435 //_class.structSize = -1;
438 DataMember dataMember;
439 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
441 if(!dataMember.isProperty)
443 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
445 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
446 /*if(!dataMember.dataType)
447 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
455 DataMember dataMember;
456 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
458 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
460 if(!isMember && _class.type == bitClass && dataMember.dataType)
462 BitMember bitMember = (BitMember) dataMember;
466 ComputeTypeSize(dataMember.dataType);
468 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
469 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
471 _class.memberOffset = bitMember.pos + bitMember.size;
472 for(d = 0; d<bitMember.size; d++)
478 bitMember.mask = mask << bitMember.pos;
480 else if(dataMember.type == normalMember && dataMember.dataType)
485 // Prevent infinite recursion
486 if(dataMember.dataType.kind != classType ||
487 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
488 _class.type != structClass)))
489 ComputeTypeSize(dataMember.dataType);
491 if(dataMember.dataType.bitFieldCount)
493 bitFields += dataMember.dataType.bitFieldCount;
500 int size = (bitFields + 7) / 8;
504 // TESTING THIS PADDING CODE
507 member.structAlignment = Max(member.structAlignment, alignment);
509 if(member.memberOffset % alignment)
510 member.memberOffset += alignment - (member.memberOffset % alignment);
513 dataMember.offset = member.memberOffset;
514 if(member.type == unionMember)
515 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
518 member.memberOffset += size;
523 // TESTING THIS PADDING CODE
526 _class.structAlignment = Max(_class.structAlignment, alignment);
528 if(_class.memberOffset % alignment)
529 _class.memberOffset += alignment - (_class.memberOffset % alignment);
532 dataMember.offset = _class.memberOffset;
533 _class.memberOffset += size;
537 size = dataMember.dataType.size;
538 alignment = dataMember.dataType.alignment;
543 // TESTING THIS PADDING CODE
546 member.structAlignment = Max(member.structAlignment, alignment);
548 if(member.memberOffset % alignment)
549 member.memberOffset += alignment - (member.memberOffset % alignment);
552 dataMember.offset = member.memberOffset;
553 if(member.type == unionMember)
554 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
557 member.memberOffset += size;
562 // TESTING THIS PADDING CODE
565 _class.structAlignment = Max(_class.structAlignment, alignment);
567 if(_class.memberOffset % alignment)
568 _class.memberOffset += alignment - (_class.memberOffset % alignment);
571 dataMember.offset = _class.memberOffset;
572 _class.memberOffset += size;
579 ComputeClassMembers((Class)dataMember, true);
580 alignment = dataMember.structAlignment;
586 if(member.memberOffset % alignment)
587 member.memberOffset += alignment - (member.memberOffset % alignment);
589 member.structAlignment = Max(member.structAlignment, alignment);
591 dataMember.offset = member.memberOffset;
592 if(member.type == unionMember)
593 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
595 member.memberOffset += dataMember.memberOffset;
601 if(_class.memberOffset % alignment)
602 _class.memberOffset += alignment - (_class.memberOffset % alignment);
603 _class.structAlignment = Max(_class.structAlignment, alignment);
605 dataMember.offset = _class.memberOffset;
606 _class.memberOffset += dataMember.memberOffset;
614 int size = (bitFields + 7) / 8;
618 // TESTING THIS PADDING CODE
621 member.structAlignment = Max(member.structAlignment, alignment);
623 if(member.memberOffset % alignment)
624 member.memberOffset += alignment - (member.memberOffset % alignment);
627 if(member.type == unionMember)
628 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
631 member.memberOffset += size;
636 // TESTING THIS PADDING CODE
639 _class.structAlignment = Max(_class.structAlignment, alignment);
641 if(_class.memberOffset % alignment)
642 _class.memberOffset += alignment - (_class.memberOffset % alignment);
644 _class.memberOffset += size;
649 if(member && member.type == unionMember)
651 member.memberOffset = unionMemberOffset;
656 /*if(_class.type == structClass)
657 _class.size = _class.memberOffset;
661 if(_class.type != bitClass)
664 if(_class.structAlignment)
666 if(_class.memberOffset % _class.structAlignment)
667 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
669 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
673 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
675 if(prop.isProperty && prop.isWatchable)
677 prop.watcherOffset = _class.structSize;
678 _class.structSize += sizeof(OldList);
686 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
688 Class deriv = derivative.data;
690 if(deriv.computeSize)
692 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
693 deriv.offset = /*_class.offset + */_class.structSize;
694 deriv.memberOffset = 0;
695 // ----------------------
697 deriv.structSize = deriv.offset;
699 ComputeClassMembers(deriv, false);
707 FinishTemplatesContext(context);
710 public void ComputeModuleClasses(Module module)
715 for(subModule = module.modules.first; subModule; subModule = subModule.next)
716 ComputeModuleClasses(subModule.data);
717 for(_class = module.classes.first; _class; _class = _class.next)
718 ComputeClassMembers(_class, false);
722 public int ComputeTypeSize(Type type)
724 uint size = type ? type.size : 0;
725 if(!size && type && !type.computing)
727 type.computing = true;
730 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
731 case charType: type.alignment = size = sizeof(char); break;
732 case intType: type.alignment = size = sizeof(int); break;
733 case int64Type: type.alignment = size = sizeof(int64); break;
734 case intPtrType: type.alignment = size = targetBits / 8; break;
735 case intSizeType: type.alignment = size = targetBits / 8; break;
736 case longType: type.alignment = size = sizeof(long); break;
737 case shortType: type.alignment = size = sizeof(short); break;
738 case floatType: type.alignment = size = sizeof(float); break;
739 case doubleType: type.alignment = size = sizeof(double); break;
742 Class _class = type._class ? type._class.registered : null;
744 if(_class && _class.type == structClass)
746 // Ensure all members are properly registered
747 ComputeClassMembers(_class, false);
748 type.alignment = _class.structAlignment;
749 size = _class.structSize;
750 if(type.alignment && size % type.alignment)
751 size += type.alignment - (size % type.alignment);
754 else if(_class && (_class.type == unitClass ||
755 _class.type == enumClass ||
756 _class.type == bitClass))
759 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
760 size = type.alignment = ComputeTypeSize(_class.dataType);
763 size = type.alignment = targetBits / 8; // sizeof(Instance *);
766 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
768 if(type.arraySizeExp)
770 ProcessExpressionType(type.arraySizeExp);
771 ComputeExpression(type.arraySizeExp);
772 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType && type.arraySizeExp.expType.kind != enumType &&
773 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
775 Location oldLoc = yylloc;
776 // bool isConstant = type.arraySizeExp.isConstant;
777 char expression[10240];
778 expression[0] = '\0';
779 type.arraySizeExp.expType = null;
780 yylloc = type.arraySizeExp.loc;
782 PrintExpression(type.arraySizeExp, expression);
783 Compiler_Error($"Array size not constant int (%s)\n", expression);
786 GetInt(type.arraySizeExp, &type.arraySize);
788 else if(type.enumClass)
790 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
792 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
799 // Unimplemented auto size
803 size = ComputeTypeSize(type.type) * type.arraySize;
805 type.alignment = type.type.alignment;
811 for(member = type.members.first; member; member = member.next)
813 uint addSize = ComputeTypeSize(member);
815 member.offset = size;
816 if(member.alignment && size % member.alignment)
817 member.offset += member.alignment - (size % member.alignment);
818 size = member.offset;
820 type.alignment = Max(type.alignment, member.alignment);
823 if(type.alignment && size % type.alignment)
824 size += type.alignment - (size % type.alignment);
830 for(member = type.members.first; member; member = member.next)
832 uint addSize = ComputeTypeSize(member);
834 member.offset = size;
835 if(member.alignment && size % member.alignment)
836 member.offset += member.alignment - (size % member.alignment);
837 size = member.offset;
839 type.alignment = Max(type.alignment, member.alignment);
840 size = Max(size, addSize);
842 if(type.alignment && size % type.alignment)
843 size += type.alignment - (size % type.alignment);
848 TemplateParameter param = type.templateParameter;
849 Type baseType = ProcessTemplateParameterType(param);
852 size = ComputeTypeSize(baseType);
853 type.alignment = baseType.alignment;
856 type.alignment = size = sizeof(uint64);
861 type.alignment = size = sizeof(enum { test });
866 type.alignment = size = targetBits / 8; //sizeof(void *);
871 type.computing = false;
877 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
879 // This function is in need of a major review when implementing private members etc.
880 DataMember topMember = isMember ? (DataMember) _class : null;
885 Context context = isMember ? null : SetupTemplatesContext(_class);
887 *addedPadding = false;
889 if(!isMember && _class.base)
891 maxSize = _class.structSize;
892 //if(_class.base.type != systemClass) // Commented out with new Instance _class
894 // DANGER: Testing this noHeadClass here...
895 if(_class.type == structClass || _class.type == noHeadClass)
896 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
899 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
900 if(maxSize > baseSize)
908 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
910 if(!member.isProperty)
916 if(member.dataTypeString)
918 OldList * specs = MkList(), * decls = MkList();
921 decl = SpecDeclFromString(member.dataTypeString, specs,
922 MkDeclaratorIdentifier(MkIdentifier(member.name)));
923 ListAdd(decls, MkStructDeclarator(decl, null));
924 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
927 member.dataType = ProcessType(specs, decl);
929 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
932 Type type = ProcessType(specs, decl);
933 DeclareType(member.dataType, false, false);
937 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
938 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
939 DeclareStruct(member.dataType._class.string, false);
942 ComputeTypeSize(member.dataType);
943 size = member.dataType.size;
944 alignment = member.dataType.alignment;
948 if(totalSize % alignment)
949 totalSize += alignment - (totalSize % alignment);
958 OldList * specs = MkList(), * list = MkList();
961 AddMembers(list, (Class)member, true, &size, topClass, null);
963 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
964 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
965 alignment = member.structAlignment;
969 if(totalSize % alignment)
970 totalSize += alignment - (totalSize % alignment);
980 if(topMember && topMember.type == unionMember)
981 *retSize = Max(*retSize, totalSize);
983 *retSize += totalSize;
985 else if(totalSize < maxSize && _class.type != systemClass)
988 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
989 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
990 if(totalSize + autoPadding < maxSize)
993 sprintf(sizeString, "%d", maxSize - totalSize);
994 ListAdd(declarations,
995 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
996 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
998 *addedPadding = true;
1002 FinishTemplatesContext(context);
1003 return topMember ? topMember.memberID : _class.memberID;
1006 static int DeclareMembers(Class _class, bool isMember)
1008 DataMember topMember = isMember ? (DataMember) _class : null;
1011 Context context = isMember ? null : SetupTemplatesContext(_class);
1013 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1014 DeclareMembers(_class.base, false);
1016 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1018 if(!member.isProperty)
1025 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1026 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1027 DeclareStruct(member.dataType._class.string, false);
1029 if(!member.dataType && member.dataTypeString)
1030 member.dataType = ProcessTypeString(member.dataTypeString, false);
1032 DeclareType(member.dataType, false, false);
1038 DeclareMembers((Class)member, true);
1045 FinishTemplatesContext(context);
1047 return topMember ? topMember.memberID : _class.memberID;
1050 void DeclareStruct(char * name, bool skipNoHead)
1052 External external = null;
1053 Symbol classSym = FindClass(name);
1055 if(!inCompiler || !classSym) return;
1057 // We don't need any declaration for bit classes...
1058 if(classSym.registered &&
1059 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1062 /*if(classSym.registered.templateClass)
1063 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1066 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1068 // Add typedef struct
1070 OldList * specifiers, * declarators;
1071 OldList * declarations = null;
1072 char structName[1024];
1073 Specifier spec = null;
1074 external = (classSym.registered && classSym.registered.type == structClass) ?
1075 classSym.pointerExternal : classSym.structExternal;
1077 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1078 // Moved this one up because DeclareClass done later will need it
1080 classSym.declaring++;
1082 if(strchr(classSym.string, '<'))
1084 if(classSym.registered.templateClass)
1086 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1087 classSym.declaring--;
1093 DeclareMembers(classSym.registered, false);
1096 FullClassNameCat(structName, name, false);
1098 if(external && external.declaration && external.declaration.specifiers)
1100 for(spec = external.declaration.specifiers->first; spec; spec = spec.next)
1102 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1108 external = MkExternalDeclaration(null);*/
1110 if(!skipNoHead && (!spec || !spec.definitions))
1112 bool addedPadding = false;
1113 classSym.declaredStructSym = true;
1115 declarations = MkList();
1117 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1119 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1120 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1122 if(!declarations->count || (declarations->count == 1 && addedPadding))
1124 FreeList(declarations, FreeClassDef);
1125 declarations = null;
1128 if(skipNoHead || declarations)
1133 spec.definitions = declarations;
1135 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1138 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1141 if(classSym.structExternal)
1142 ast->Move(classSym.structExternal, curExternal.prev);
1143 ast->Move(classSym.pointerExternal, curExternal.prev);
1145 classSym.id = curExternal.symbol.idCode;
1146 classSym.idCode = curExternal.symbol.idCode;
1147 // external = classSym.pointerExternal;
1148 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1154 external = MkExternalDeclaration(null);
1156 specifiers = MkList();
1157 declarators = MkList();
1158 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1161 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1162 ListAdd(declarators, MkInitDeclarator(d, null));
1164 external.declaration = decl = MkDeclaration(specifiers, declarators);
1165 if(decl.symbol && !decl.symbol.pointerExternal)
1166 decl.symbol.pointerExternal = external;
1168 // For simple classes, keep the declaration as the external to move around
1169 if(classSym.registered && classSym.registered.type == structClass)
1171 char className[1024];
1172 strcpy(className, "__ecereClass_");
1173 FullClassNameCat(className, classSym.string, true);
1174 MangleClassName(className);
1177 DeclareClass(classSym, className);
1179 external.symbol = classSym;
1180 classSym.pointerExternal = external;
1181 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1182 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1186 char className[1024];
1187 strcpy(className, "__ecereClass_");
1188 FullClassNameCat(className, classSym.string, true);
1189 MangleClassName(className);
1191 // TOFIX: TESTING THIS...
1192 classSym.structExternal = external;
1193 DeclareClass(classSym, className);
1194 external.symbol = classSym;
1198 ast->Insert(curExternal ? curExternal.prev : null, external);
1202 classSym.declaring--;
1204 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1206 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1207 // Moved this one up because DeclareClass done later will need it
1210 classSym.declaring++;
1214 if(classSym.registered)
1215 DeclareMembers(classSym.registered, false);
1218 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1221 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1224 if(classSym.structExternal)
1225 ast->Move(classSym.structExternal, curExternal.prev);
1226 ast->Move(classSym.pointerExternal, curExternal.prev);
1228 classSym.id = curExternal.symbol.idCode;
1229 classSym.idCode = curExternal.symbol.idCode;
1230 // external = classSym.pointerExternal;
1231 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1234 classSym.declaring--;
1239 void DeclareProperty(Property prop, char * setName, char * getName)
1241 Symbol symbol = prop.symbol;
1242 char propName[1024];
1244 strcpy(setName, "__ecereProp_");
1245 FullClassNameCat(setName, prop._class.fullName, false);
1246 strcat(setName, "_Set_");
1247 // strcat(setName, prop.name);
1248 FullClassNameCat(setName, prop.name, true);
1250 strcpy(getName, "__ecereProp_");
1251 FullClassNameCat(getName, prop._class.fullName, false);
1252 strcat(getName, "_Get_");
1253 FullClassNameCat(getName, prop.name, true);
1254 // strcat(getName, prop.name);
1256 strcpy(propName, "__ecereProp_");
1257 FullClassNameCat(propName, prop._class.fullName, false);
1258 strcat(propName, "_");
1259 FullClassNameCat(propName, prop.name, true);
1260 // strcat(propName, prop.name);
1262 // To support "char *" property
1263 MangleClassName(getName);
1264 MangleClassName(setName);
1265 MangleClassName(propName);
1267 if(prop._class.type == structClass)
1268 DeclareStruct(prop._class.fullName, false);
1270 if(!symbol || curExternal.symbol.idCode < symbol.id)
1272 bool imported = false;
1273 bool dllImport = false;
1274 if(!symbol || symbol._import)
1279 if(!prop._class.symbol)
1280 prop._class.symbol = FindClass(prop._class.fullName);
1281 classSym = prop._class.symbol;
1282 if(classSym && !classSym._import)
1284 ModuleImport module;
1286 if(prop._class.module)
1287 module = FindModule(prop._class.module);
1289 module = mainModule;
1291 classSym._import = ClassImport
1293 name = CopyString(prop._class.fullName);
1294 isRemote = prop._class.isRemote;
1296 module.classes.Add(classSym._import);
1298 symbol = prop.symbol = Symbol { };
1299 symbol._import = (ClassImport)PropertyImport
1301 name = CopyString(prop.name);
1302 isVirtual = false; //prop.isVirtual;
1303 hasSet = prop.Set ? true : false;
1304 hasGet = prop.Get ? true : false;
1307 classSym._import.properties.Add(symbol._import);
1310 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1311 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1312 prop._class.module.importType != staticImport)
1318 Context context = SetupTemplatesContext(prop._class);
1319 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1320 FinishTemplatesContext(context);
1326 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1329 OldList * specifiers, * declarators;
1334 Declarator typeDecl;
1335 bool simple = false;
1337 specifiers = MkList();
1338 declarators = MkList();
1341 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1342 MkDeclaratorIdentifier(MkIdentifier("this"))));
1344 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1347 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1350 Context context = SetupTemplatesContext(prop._class);
1351 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1352 FinishTemplatesContext(context);
1355 // Make sure the simple _class's type is declared
1356 for(spec = specifiers->first; spec; spec = spec.next)
1358 if(spec.type == nameSpecifier /*SpecifierClass*/)
1360 if((!typeDecl || typeDecl.type == identifierDeclarator))
1362 Symbol classSym = spec.symbol; // FindClass(spec.name);
1363 symbol._class = classSym.registered;
1364 if(classSym.registered && classSym.registered.type == structClass)
1366 DeclareStruct(spec.name, false);
1374 d = PlugDeclarator(typeDecl, d);
1377 ListAdd(params, MkTypeName(specifiers,
1378 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1379 specifiers = MkList();
1382 d = MkDeclaratorFunction(d, params);
1386 specifiers->Insert(null, MkSpecifier(EXTERN));
1387 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1388 specifiers->Insert(null, MkSpecifier(STATIC));
1390 ListAdd(specifiers, MkSpecifier(VOID));
1392 ListAdd(declarators, MkInitDeclarator(d, null));
1394 decl = MkDeclaration(specifiers, declarators);
1396 external = MkExternalDeclaration(decl);
1397 ast->Insert(curExternal.prev, external);
1398 external.symbol = symbol;
1399 symbol.externalGet = external;
1401 ReplaceThisClassSpecifiers(specifiers, prop._class);
1404 FreeDeclarator(typeDecl);
1408 // Move declaration higher...
1409 ast->Move(symbol.externalGet, curExternal.prev);
1416 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1419 OldList * specifiers, * declarators;
1424 Declarator typeDecl;
1426 declarators = MkList();
1429 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1430 if(!prop.conversion || prop._class.type == structClass)
1432 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1433 MkDeclaratorIdentifier(MkIdentifier("this"))));
1436 specifiers = MkList();
1439 Context context = SetupTemplatesContext(prop._class);
1440 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1441 MkDeclaratorIdentifier(MkIdentifier("value")));
1442 FinishTemplatesContext(context);
1444 ListAdd(params, MkTypeName(specifiers, d));
1446 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1449 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1450 d = MkDeclaratorFunction(d, params);
1452 // Make sure the simple _class's type is declared
1453 for(spec = specifiers->first; spec; spec = spec.next)
1455 if(spec.type == nameSpecifier /*SpecifierClass*/)
1457 if((!typeDecl || typeDecl.type == identifierDeclarator))
1459 Symbol classSym = spec.symbol; // FindClass(spec.name);
1460 symbol._class = classSym.registered;
1461 if(classSym.registered && classSym.registered.type == structClass)
1462 DeclareStruct(spec.name, false);
1467 ListAdd(declarators, MkInitDeclarator(d, null));
1469 specifiers = MkList();
1472 specifiers->Insert(null, MkSpecifier(EXTERN));
1473 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1474 specifiers->Insert(null, MkSpecifier(STATIC));
1476 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1477 if(!prop.conversion || prop._class.type == structClass)
1478 ListAdd(specifiers, MkSpecifier(VOID));
1480 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1482 decl = MkDeclaration(specifiers, declarators);
1484 external = MkExternalDeclaration(decl);
1485 ast->Insert(curExternal.prev, external);
1486 external.symbol = symbol;
1487 symbol.externalSet = external;
1489 ReplaceThisClassSpecifiers(specifiers, prop._class);
1493 // Move declaration higher...
1494 ast->Move(symbol.externalSet, curExternal.prev);
1498 // Property (for Watchers)
1499 if(!symbol.externalPtr)
1503 OldList * specifiers = MkList();
1506 specifiers->Insert(null, MkSpecifier(EXTERN));
1508 specifiers->Insert(null, MkSpecifier(STATIC));
1510 ListAdd(specifiers, MkSpecifierName("Property"));
1513 OldList * list = MkList();
1514 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1515 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1519 strcpy(propName, "__ecerePropM_");
1520 FullClassNameCat(propName, prop._class.fullName, false);
1521 strcat(propName, "_");
1522 // strcat(propName, prop.name);
1523 FullClassNameCat(propName, prop.name, true);
1525 MangleClassName(propName);
1527 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1528 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1530 decl = MkDeclaration(specifiers, list);
1533 external = MkExternalDeclaration(decl);
1534 ast->Insert(curExternal.prev, external);
1535 external.symbol = symbol;
1536 symbol.externalPtr = external;
1540 // Move declaration higher...
1541 ast->Move(symbol.externalPtr, curExternal.prev);
1544 symbol.id = curExternal.symbol.idCode;
1548 // ***************** EXPRESSION PROCESSING ***************************
1549 public Type Dereference(Type source)
1554 if(source.kind == pointerType || source.kind == arrayType)
1557 source.type.refCount++;
1559 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1567 // Support dereferencing of no head classes for now...
1568 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1574 Compiler_Error($"cannot dereference type\n");
1579 static Type Reference(Type source)
1595 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1597 Identifier ident = member.identifiers ? member.identifiers->first : null;
1599 DataMember dataMember = null;
1600 Method method = null;
1601 bool freeType = false;
1603 yylloc = member.loc;
1609 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1613 dataMember = *curMember;
1619 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1620 DataMember _subMemberStack[256];
1621 int _subMemberStackPos = 0;
1623 // FILL MEMBER STACK
1625 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1628 dataMember = thisMember;
1629 if(curMember && thisMember.memberAccess == publicAccess)
1631 *curMember = thisMember;
1632 *curClass = thisMember._class;
1633 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1634 *subMemberStackPos = _subMemberStackPos;
1641 method = eClass_FindMethod(_class, ident.string, privateModule);
1642 if(method && method.type == virtualMethod)
1654 if(!dataMember.dataType && dataMember.dataTypeString)
1656 //Context context = SetupTemplatesContext(dataMember._class);
1657 Context context = SetupTemplatesContext(_class);
1658 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1659 FinishTemplatesContext(context);
1661 type = dataMember.dataType;
1665 // This is for destination type...
1666 if(!method.dataType)
1667 ProcessMethodType(method);
1668 //DeclareMethod(method);
1669 // method.dataType = ((Symbol)method.symbol)->type;
1670 type = method.dataType;
1673 if(ident && ident.next)
1675 for(ident = ident.next; ident && type; ident = ident.next)
1677 if(type.kind == classType)
1679 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1681 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1683 type = dataMember.dataType;
1685 else if(type.kind == structType || type.kind == unionType)
1688 for(memberType = type.members.first; memberType; memberType = memberType.next)
1690 if(!strcmp(memberType.name, ident.string))
1700 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1701 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1704 ClassTemplateParameter curParam = null;
1706 for(sClass = _class; sClass; sClass = sClass.base)
1709 if(sClass.templateClass) sClass = sClass.templateClass;
1710 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1712 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1714 for(sClass = sClass.base; sClass; sClass = sClass.base)
1716 if(sClass.templateClass) sClass = sClass.templateClass;
1717 id += sClass.templateParams.count;
1728 ClassTemplateArgument arg = _class.templateArgs[id];
1729 if(arg.dataTypeString)
1732 type = ProcessTypeString(arg.dataTypeString, false);
1734 if(type && _class.templateClass)
1735 type.passAsTemplate = true;
1741 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1742 exp.destType.refCount++;
1748 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1750 Class expClass = type._class.registered;
1751 Class cClass = null;
1756 char templateString[1024];
1757 ClassTemplateParameter param;
1758 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1759 for(cClass = expClass; cClass; cClass = cClass.base)
1762 if(cClass.templateClass) cClass = cClass.templateClass;
1763 for(param = cClass.templateParams.first; param; param = param.next)
1767 ClassTemplateArgument arg;
1768 for(sClass = cClass.base; sClass; sClass = sClass.base)
1770 if(sClass.templateClass) sClass = sClass.templateClass;
1771 id += sClass.templateParams.count;
1773 arg = expClass.templateArgs[id];
1775 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1777 ClassTemplateParameter cParam;
1778 //int p = numParams - sClass.templateParams.count;
1781 if(sClass.templateClass) sClass = sClass.templateClass;
1783 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1785 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1786 p += nextClass.templateParams.count;
1789 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1791 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1793 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1795 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1796 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1808 strcat(argument, arg.name.string);
1809 strcat(argument, " = ");
1815 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1816 char expString[1024];
1817 OldList * specs = MkList();
1818 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1820 char * string = PrintHexUInt64(arg.expression.ui64);
1821 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1824 ProcessExpressionType(exp);
1825 ComputeExpression(exp);
1826 expString[0] = '\0';
1827 PrintExpression(exp, expString);
1828 strcat(argument, expString);
1830 FreeExpression(exp);
1835 strcat(argument, arg.member.name);
1838 case TemplateParameterType::type:
1840 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1841 strcat(argument, arg.dataTypeString);
1847 if(paramCount) strcat(templateString, ", ");
1848 if(lastParam != p - 1)
1850 strcat(templateString, param.name);
1851 strcat(templateString, " = ");
1853 strcat(templateString, argument);
1862 int len = strlen(templateString);
1863 if(templateString[len-1] == '<')
1867 if(templateString[len-1] == '>')
1868 templateString[len++] = ' ';
1869 templateString[len++] = '>';
1871 templateString[len++] = '\0';
1874 Context context = SetupTemplatesContext(_class);
1875 if(freeType) FreeType(type);
1876 type = ProcessTypeString(templateString, false);
1878 FinishTemplatesContext(context);
1882 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1884 ProcessExpressionType(member.initializer.exp);
1885 if(!member.initializer.exp.expType)
1889 char expString[10240];
1890 expString[0] = '\0';
1891 PrintExpression(member.initializer.exp, expString);
1892 ChangeCh(expString, '\n', ' ');
1893 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1896 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1897 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1899 Compiler_Error($"incompatible instance method %s\n", ident.string);
1902 else if(member.initializer)
1905 FreeType(member.exp.destType);
1906 member.exp.destType = type;
1907 if(member.exp.destType)
1908 member.exp.destType.refCount++;
1909 ProcessExpressionType(member.exp);
1912 ProcessInitializer(member.initializer, type);
1914 if(freeType) FreeType(type);
1918 if(_class && _class.type == unitClass)
1920 if(member.initializer)
1923 FreeType(member.exp.destType);
1924 member.exp.destType = MkClassType(_class.fullName);
1925 ProcessExpressionType(member.initializer, type);
1927 Type type = MkClassType(_class.fullName);
1928 ProcessInitializer(member.initializer, type);
1934 if(member.initializer)
1936 //ProcessExpressionType(member.exp);
1937 ProcessInitializer(member.initializer, null);
1943 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1947 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1949 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1953 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1958 void ProcessInstantiationType(Instantiation inst)
1963 MembersInit members;
1964 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1967 /*if(!inst._class.symbol)
1968 inst._class.symbol = FindClass(inst._class.name);*/
1969 classSym = inst._class.symbol;
1970 _class = classSym ? classSym.registered : null;
1972 // DANGER: Patch for mutex not declaring its struct when not needed
1973 if(!_class || _class.type != noHeadClass)
1974 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1976 afterExternal = afterExternal ? afterExternal : curExternal;
1979 ProcessExpressionType(inst.exp);
1981 inst.isConstant = true;
1984 DataMember curMember = null;
1985 Class curClass = null;
1986 DataMember subMemberStack[256];
1987 int subMemberStackPos = 0;
1989 for(members = inst.members->first; members; members = members.next)
1991 switch(members.type)
1993 case methodMembersInit:
1996 static uint instMethodID = 0;
1997 External external = curExternal;
1998 Context context = curContext;
1999 Declarator declarator = members.function.declarator;
2000 Identifier nameID = GetDeclId(declarator);
2001 char * unmangled = nameID ? nameID.string : null;
2003 External createdExternal = null;
2008 //members.function.dontMangle = true;
2009 strcpy(name, "__ecereInstMeth_");
2010 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2012 strcat(name, nameID.string);
2014 sprintf(number, "_%08d", instMethodID++);
2015 strcat(name, number);
2016 nameID.string = CopyString(name);
2019 // Do modifications here...
2022 Symbol symbol = declarator.symbol;
2023 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2025 if(method && method.type == virtualMethod)
2027 symbol.method = method;
2028 ProcessMethodType(method);
2030 if(!symbol.type.thisClass)
2032 if(method.dataType.thisClass && currentClass &&
2033 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2035 if(!currentClass.symbol)
2036 currentClass.symbol = FindClass(currentClass.fullName);
2037 symbol.type.thisClass = currentClass.symbol;
2042 _class.symbol = FindClass(_class.fullName);
2043 symbol.type.thisClass = _class.symbol;
2046 // TESTING THIS HERE:
2047 DeclareType(symbol.type, true, true);
2052 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2053 unmangled, classSym.string);
2057 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2058 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2062 FreeSpecifier(nameID._class);
2063 nameID._class = null;
2069 Type type = declarator.symbol.type;
2070 External oldExternal = curExternal;
2072 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2073 // *** It was commented out for problems such as
2075 class VirtualDesktop : Window
2077 clientSize = Size { };
2088 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2090 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2093 if(strcmp(declarator.symbol.string, name))
2095 printf("TOCHECK: Look out for this\n");
2096 delete declarator.symbol.string;
2097 declarator.symbol.string = CopyString(name);
2100 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2102 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2103 excludedSymbols->Remove(declarator.symbol);
2104 globalContext.symbols.Add((BTNode)declarator.symbol);
2105 if(strstr(declarator.symbol.string), "::")
2106 globalContext.hasNameSpace = true;
2111 //curExternal = curExternal.prev;
2112 //afterExternal = afterExternal->next;
2114 //ProcessFunction(afterExternal->function);
2116 //curExternal = afterExternal;
2118 External externalDecl;
2119 externalDecl = MkExternalDeclaration(null);
2120 ast->Insert(oldExternal.prev, externalDecl);
2122 // Which function does this process?
2123 if(createdExternal.function)
2125 ProcessFunction(createdExternal.function);
2127 //curExternal = oldExternal;
2130 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2132 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2133 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2135 //externalDecl = MkExternalDeclaration(decl);
2137 //***** ast->Insert(external.prev, externalDecl);
2138 //ast->Insert(curExternal.prev, externalDecl);
2139 externalDecl.declaration = decl;
2140 if(decl.symbol && !decl.symbol.pointerExternal)
2141 decl.symbol.pointerExternal = externalDecl;
2143 // Trying this out...
2144 declarator.symbol.pointerExternal = externalDecl;
2151 curExternal = declarator.symbol.pointerExternal;
2152 ProcessFunction((FunctionDefinition)members.function);
2154 curExternal = external;
2155 curContext = context;
2159 FreeClassFunction(members.function);
2161 // In this pass, turn this into a MemberInitData
2162 exp = QMkExpId(name);
2163 members.type = dataMembersInit;
2164 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2170 case dataMembersInit:
2172 if(members.dataMembers && classSym)
2175 Location oldyyloc = yylloc;
2176 for(member = members.dataMembers->first; member; member = member.next)
2178 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2179 if(member.initializer && !member.initializer.isConstant)
2180 inst.isConstant = false;
2192 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2194 // OPTIMIZATIONS: TESTING THIS...
2197 if(type.kind == functionType)
2202 for(param = type.params.first; param; param = param.next)
2203 DeclareType(param, declarePointers, true);
2205 DeclareType(type.returnType, declarePointers, true);
2207 else if(type.kind == pointerType && declarePointers)
2208 DeclareType(type.type, declarePointers, false);
2209 else if(type.kind == classType)
2211 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2212 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2214 else if(type.kind == structType || type.kind == unionType)
2217 for(member = type.members.first; member; member = member.next)
2218 DeclareType(member, false, false);
2220 else if(type.kind == arrayType)
2221 DeclareType(type.arrayType, declarePointers, false);
2225 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2227 ClassTemplateArgument * arg = null;
2229 ClassTemplateParameter curParam = null;
2231 for(sClass = _class; sClass; sClass = sClass.base)
2234 if(sClass.templateClass) sClass = sClass.templateClass;
2235 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2237 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2239 for(sClass = sClass.base; sClass; sClass = sClass.base)
2241 if(sClass.templateClass) sClass = sClass.templateClass;
2242 id += sClass.templateParams.count;
2252 arg = &_class.templateArgs[id];
2253 if(arg && param.type == type)
2254 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2259 public Context SetupTemplatesContext(Class _class)
2261 Context context = PushContext();
2262 context.templateTypesOnly = true;
2263 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2265 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2266 for(; param; param = param.next)
2268 if(param.type == type && param.identifier)
2270 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2271 curContext.templateTypes.Add((BTNode)type);
2278 for(sClass = _class; sClass; sClass = sClass.base)
2280 ClassTemplateParameter p;
2281 for(p = sClass.templateParams.first; p; p = p.next)
2283 //OldList * specs = MkList();
2284 //Declarator decl = null;
2285 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2288 TemplateParameter param = p.param;
2292 // ADD DATA TYPE HERE...
2293 p.param = param = TemplateParameter
2295 identifier = MkIdentifier(p.name), type = p.type,
2296 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2299 type = TemplatedType { key = (uintptr)p.name, param = param };
2300 curContext.templateTypes.Add((BTNode)type);
2308 public void FinishTemplatesContext(Context context)
2310 PopContext(context);
2311 FreeContext(context);
2315 public void ProcessMethodType(Method method)
2317 if(!method.dataType)
2319 Context context = SetupTemplatesContext(method._class);
2321 method.dataType = ProcessTypeString(method.dataTypeString, false);
2323 FinishTemplatesContext(context);
2325 if(method.type != virtualMethod && method.dataType)
2327 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2329 if(!method._class.symbol)
2330 method._class.symbol = FindClass(method._class.fullName);
2331 method.dataType.thisClass = method._class.symbol;
2335 // Why was this commented out? Working fine without now...
2338 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2339 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2346 char * par = strstr(type, "(");
2347 char * classOp = null;
2352 for(c = par-type-1; c >= 0; c++)
2354 if(type[c] == ':' && type[c+1] == ':')
2356 classOp = type + c - 1;
2357 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2364 else if(!isspace(type[c]))
2371 int typeLen = strlen(type);
2372 memcpy(temp, classOp, classOpLen);
2373 temp[classOpLen] = '\0';
2375 _class = eSystem_FindClass(module, temp);
2378 method.dataTypeString = new char[typeLen - classOpLen + 1];
2379 memcpy(method.dataTypeString, type, classOp - type);
2380 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2383 method.dataTypeString = type;
2389 public void ProcessPropertyType(Property prop)
2393 Context context = SetupTemplatesContext(prop._class);
2394 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2395 FinishTemplatesContext(context);
2399 public void DeclareMethod(Method method, char * name)
2401 Symbol symbol = method.symbol;
2402 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2404 bool imported = false;
2405 bool dllImport = false;
2407 if(!method.dataType)
2408 method.dataType = ProcessTypeString(method.dataTypeString, false);
2410 if(!symbol || symbol._import || method.type == virtualMethod)
2412 if(!symbol || method.type == virtualMethod)
2415 if(!method._class.symbol)
2416 method._class.symbol = FindClass(method._class.fullName);
2417 classSym = method._class.symbol;
2418 if(!classSym._import)
2420 ModuleImport module;
2422 if(method._class.module && method._class.module.name)
2423 module = FindModule(method._class.module);
2425 module = mainModule;
2426 classSym._import = ClassImport
2428 name = CopyString(method._class.fullName);
2429 isRemote = method._class.isRemote;
2431 module.classes.Add(classSym._import);
2435 symbol = method.symbol = Symbol { };
2439 symbol._import = (ClassImport)MethodImport
2441 name = CopyString(method.name);
2442 isVirtual = method.type == virtualMethod;
2444 classSym._import.methods.Add(symbol._import);
2448 // Set the symbol type
2452 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2454 else if(type.thisClass == (void *)-1)
2456 type.thisClass = null;
2459 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2460 symbol.type = method.dataType;
2461 if(symbol.type) symbol.type.refCount++;
2464 if(!method.thisClass || strcmp(method.thisClass, "void"))
2465 symbol.type.params.Insert(null,
2466 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2469 if(!method.dataType.dllExport)
2472 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2478 if(!method.dataType)
2479 method.dataType = ((Symbol)method.symbol).type;
2480 //ProcessMethodType(method);
2483 if(method.type != virtualMethod && method.dataType)
2484 DeclareType(method.dataType, true, true);
2486 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2488 // We need a declaration here :)
2490 OldList * specifiers, * declarators;
2492 Declarator funcDecl;
2495 specifiers = MkList();
2496 declarators = MkList();
2500 ListAdd(specifiers, MkSpecifier(EXTERN));
2501 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2502 ListAdd(specifiers, MkSpecifier(STATIC));
2504 if(method.type == virtualMethod)
2506 ListAdd(specifiers, MkSpecifier(INT));
2507 d = MkDeclaratorIdentifier(MkIdentifier(name));
2511 d = MkDeclaratorIdentifier(MkIdentifier(name));
2514 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2516 Context context = SetupTemplatesContext(method._class);
2517 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2518 FinishTemplatesContext(context);
2520 funcDecl = GetFuncDecl(d);
2524 Specifier spec, next;
2525 for(spec = specifiers->first; spec; spec = next)
2528 if(spec.type == extendedSpecifier)
2530 specifiers->Remove(spec);
2531 FreeSpecifier(spec);
2536 // Add this parameter if not a static method
2537 if(method.dataType && !method.dataType.staticMethod)
2539 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2541 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2542 TypeName thisParam = MkTypeName(MkListOne(
2543 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2544 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2545 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2546 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2548 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2550 TypeName param = funcDecl.function.parameters->first;
2551 funcDecl.function.parameters->Remove(param);
2552 FreeTypeName(param);
2555 if(!funcDecl.function.parameters)
2556 funcDecl.function.parameters = MkList();
2557 funcDecl.function.parameters->Insert(null, thisParam);
2560 // Make sure we don't have empty parameter declarations for static methods...
2562 else if(!funcDecl.function.parameters)
2564 funcDecl.function.parameters = MkList();
2565 funcDecl.function.parameters->Insert(null,
2566 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2570 ProcessDeclarator(d);
2572 ListAdd(declarators, MkInitDeclarator(d, null));
2574 decl = MkDeclaration(specifiers, declarators);
2576 ReplaceThisClassSpecifiers(specifiers, method._class);
2578 // Keep a different symbol for the function definition than the declaration...
2579 if(symbol.pointerExternal)
2581 Symbol functionSymbol { };
2585 *functionSymbol = *symbol;
2586 functionSymbol.string = CopyString(symbol.string);
2587 if(functionSymbol.type)
2588 functionSymbol.type.refCount++;
2591 excludedSymbols->Add(functionSymbol);
2592 symbol.pointerExternal.symbol = functionSymbol;
2594 external = MkExternalDeclaration(decl);
2596 ast->Insert(curExternal ? curExternal.prev : null, external);
2597 external.symbol = symbol;
2598 symbol.pointerExternal = external;
2602 // Move declaration higher...
2603 ast->Move(symbol.pointerExternal, curExternal.prev);
2606 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2610 char * ReplaceThisClass(Class _class)
2612 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2616 ClassTemplateParameter param;
2619 char className[1024];
2620 strcpy(className, _class.fullName);
2621 for(param = _class.templateParams.first; param; param = param.next)
2623 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2625 if(first) strcat(className, "<");
2626 if(!first) strcat(className, ", ");
2627 if(lastParam + 1 != p)
2629 strcat(className, param.name);
2630 strcat(className, " = ");
2632 strcat(className, param.name);
2640 int len = strlen(className);
2641 if(className[len-1] == '>') className[len++] = ' ';
2642 className[len++] = '>';
2643 className[len++] = '\0';
2645 return CopyString(className);
2648 return CopyString(_class.fullName);
2651 Type ReplaceThisClassType(Class _class)
2653 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2657 ClassTemplateParameter param;
2659 char className[1024];
2660 strcpy(className, _class.fullName);
2662 for(param = _class.templateParams.first; param; param = param.next)
2664 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2666 if(first) strcat(className, "<");
2667 if(!first) strcat(className, ", ");
2668 if(lastParam + 1 != p)
2670 strcat(className, param.name);
2671 strcat(className, " = ");
2673 strcat(className, param.name);
2681 int len = strlen(className);
2682 if(className[len-1] == '>') className[len++] = ' ';
2683 className[len++] = '>';
2684 className[len++] = '\0';
2686 return MkClassType(className);
2687 //return ProcessTypeString(className, false);
2691 return MkClassType(_class.fullName);
2692 //return ProcessTypeString(_class.fullName, false);
2696 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2698 if(specs != null && _class)
2701 for(spec = specs.first; spec; spec = spec.next)
2703 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2705 spec.type = nameSpecifier;
2706 spec.name = ReplaceThisClass(_class);
2707 spec.symbol = FindClass(spec.name); //_class.symbol;
2713 // Returns imported or not
2714 bool DeclareFunction(GlobalFunction function, char * name)
2716 Symbol symbol = function.symbol;
2717 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2719 bool imported = false;
2720 bool dllImport = false;
2722 if(!function.dataType)
2724 function.dataType = ProcessTypeString(function.dataTypeString, false);
2725 if(!function.dataType.thisClass)
2726 function.dataType.staticMethod = true;
2733 ModuleImport module = FindModule(function.module);
2734 // WARNING: This is not added anywhere...
2735 symbol = function.symbol = Symbol { };
2739 if(!function.dataType.dllExport)
2741 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2742 module.functions.Add(symbol._import);
2745 // Set the symbol type
2747 symbol.type = ProcessTypeString(function.dataTypeString, false);
2748 if(!symbol.type.thisClass)
2749 symbol.type.staticMethod = true;
2752 imported = symbol._import ? true : false;
2753 if(imported && function.module != privateModule && function.module.importType != staticImport)
2757 DeclareType(function.dataType, true, true);
2761 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2763 // We need a declaration here :)
2765 OldList * specifiers, * declarators;
2767 Declarator funcDecl;
2770 specifiers = MkList();
2771 declarators = MkList();
2774 ListAdd(specifiers, MkSpecifier(EXTERN));
2777 ListAdd(specifiers, MkSpecifier(STATIC));
2780 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2783 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2785 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2786 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2787 if(function.module.importType == staticImport)
2790 for(spec = specifiers->first; spec; spec = spec.next)
2791 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2793 specifiers->Remove(spec);
2794 FreeSpecifier(spec);
2799 funcDecl = GetFuncDecl(d);
2801 // Make sure we don't have empty parameter declarations for static methods...
2802 if(funcDecl && !funcDecl.function.parameters)
2804 funcDecl.function.parameters = MkList();
2805 funcDecl.function.parameters->Insert(null,
2806 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2809 ListAdd(declarators, MkInitDeclarator(d, null));
2812 Context oldCtx = curContext;
2813 curContext = globalContext;
2814 decl = MkDeclaration(specifiers, declarators);
2815 curContext = oldCtx;
2818 // Keep a different symbol for the function definition than the declaration...
2819 if(symbol.pointerExternal)
2821 Symbol functionSymbol { };
2824 *functionSymbol = *symbol;
2825 functionSymbol.string = CopyString(symbol.string);
2826 if(functionSymbol.type)
2827 functionSymbol.type.refCount++;
2830 excludedSymbols->Add(functionSymbol);
2832 symbol.pointerExternal.symbol = functionSymbol;
2834 external = MkExternalDeclaration(decl);
2836 ast->Insert(curExternal.prev, external);
2837 external.symbol = symbol;
2838 symbol.pointerExternal = external;
2842 // Move declaration higher...
2843 ast->Move(symbol.pointerExternal, curExternal.prev);
2847 symbol.id = curExternal.symbol.idCode;
2850 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2853 void DeclareGlobalData(GlobalData data)
2855 Symbol symbol = data.symbol;
2856 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2861 symbol = data.symbol = Symbol { };
2864 data.dataType = ProcessTypeString(data.dataTypeString, false);
2865 DeclareType(data.dataType, true, true);
2868 if(!symbol.pointerExternal)
2870 // We need a declaration here :)
2872 OldList * specifiers, * declarators;
2876 specifiers = MkList();
2877 declarators = MkList();
2879 ListAdd(specifiers, MkSpecifier(EXTERN));
2880 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2881 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2883 ListAdd(declarators, MkInitDeclarator(d, null));
2885 decl = MkDeclaration(specifiers, declarators);
2886 external = MkExternalDeclaration(decl);
2888 ast->Insert(curExternal.prev, external);
2889 external.symbol = symbol;
2890 symbol.pointerExternal = external;
2894 // Move declaration higher...
2895 ast->Move(symbol.pointerExternal, curExternal.prev);
2899 symbol.id = curExternal.symbol.idCode;
2904 class Conversion : struct
2906 Conversion prev, next;
2912 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2916 // Property convert;
2918 if(source.kind == templateType && dest.kind != templateType)
2920 Type type = ProcessTemplateParameterType(source.templateParameter);
2921 if(type) source = type;
2924 if(dest.kind == templateType && source.kind != templateType)
2926 Type type = ProcessTemplateParameterType(dest.templateParameter);
2927 if(type) dest = type;
2930 if(dest.classObjectType == typedObject)
2932 if(source.classObjectType != anyObject)
2936 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2937 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2945 if(source.classObjectType == anyObject)
2947 if(dest.classObjectType == anyObject && source.classObjectType != typedObject)
2951 if((dest.kind == structType && source.kind == structType) ||
2952 (dest.kind == unionType && source.kind == unionType))
2954 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2955 (source.members.first && source.members.first == dest.members.first))
2959 if(dest.kind == ellipsisType && source.kind != voidType)
2962 if(dest.kind == pointerType && dest.type.kind == voidType &&
2963 ((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))
2964 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2966 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2968 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2970 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2971 ((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))
2972 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2974 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2976 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2979 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2981 if(source._class.registered && source._class.registered.type == unitClass)
2983 if(conversions != null)
2985 if(source._class.registered == dest._class.registered)
2990 Class sourceBase, destBase;
2991 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2992 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2993 if(sourceBase == destBase)
2997 // Don't match enum inheriting from other enum if resolving enumeration values
2998 // TESTING: !dest.classObjectType
2999 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
3001 (!source._class.registered || source._class.registered.type != enumClass) ||
3002 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
3006 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
3008 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
3009 ((source._class && source._class.registered && source._class.registered.type != enumClass) || source.kind == classType)) // Added this here for a base enum to be acceptable for a derived enum (#139)
3011 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3019 // JUST ADDED THIS...
3020 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3025 // Just added this for Straight conversion of ColorAlpha => Color
3026 if(source.kind == classType)
3029 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3032 for(convert = _class.conversions.first; convert; convert = convert.next)
3034 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3036 Conversion after = (conversions != null) ? conversions.last : null;
3038 if(!convert.dataType)
3039 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3040 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3041 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3042 MatchTypes(convert.dataType, dest, conversions, null, null,
3043 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3044 convert.dataType.kind == classType, false, true))
3046 if(!conversions && !convert.Get)
3048 else if(conversions != null)
3050 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3051 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3052 (dest.kind != classType || dest._class.registered != _class.base))
3056 Conversion conv { convert = convert, isGet = true };
3057 // conversions.Add(conv);
3058 conversions.Insert(after, conv);
3070 if(dest.kind == classType)
3073 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3076 for(convert = _class.conversions.first; convert; convert = convert.next)
3078 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3080 // Conversion after = (conversions != null) ? conversions.last : null;
3082 if(!convert.dataType)
3083 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3084 // Just added this equality check to prevent recursion.... Make it safer?
3085 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3086 if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
3088 if(!conversions && !convert.Set)
3090 else if(conversions != null)
3092 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3093 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3094 (source.kind != classType || source._class.registered != _class.base))
3098 // *** Testing this! ***
3099 Conversion conv { convert = convert };
3100 conversions.Add(conv);
3101 //conversions.Insert(after, conv);
3109 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3111 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3112 (source.kind != classType || source._class.registered.type != structClass))
3116 // TESTING THIS... IS THIS OK??
3117 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3119 if(!dest._class.registered.dataType)
3120 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3121 // Only support this for classes...
3122 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3123 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3125 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false))
3134 if(source.kind == classType)
3137 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3140 for(convert = _class.conversions.first; convert; convert = convert.next)
3142 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3144 Conversion after = (conversions != null) ? conversions.last : null;
3146 if(!convert.dataType)
3147 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3148 if(convert.dataType != source &&
3149 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3150 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true))
3152 if(!conversions && !convert.Get)
3154 else if(conversions != null)
3156 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3157 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3158 (dest.kind != classType || dest._class.registered != _class.base))
3162 Conversion conv { convert = convert, isGet = true };
3164 // conversions.Add(conv);
3165 conversions.Insert(after, conv);
3174 // TESTING THIS... IS THIS OK??
3175 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3177 if(!source._class.registered.dataType)
3178 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3179 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3181 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, source._class.registered.dataType.kind == classType, source._class.registered.dataType.kind == classType, false, false))
3183 // For bool to be accepted by byte, short, etc.
3184 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false))
3191 if(source.kind == classType || source.kind == subClassType)
3193 else if(dest.kind == source.kind &&
3194 (dest.kind != structType && dest.kind != unionType &&
3195 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3197 // RECENTLY ADDED THESE
3198 else if(dest.kind == doubleType && source.kind == floatType)
3200 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3202 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3204 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3206 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3208 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3210 else if(source.kind == enumType &&
3211 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3213 else if(dest.kind == enumType && !isConversionExploration &&
3214 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3216 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3217 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3219 Type paramSource, paramDest;
3221 if(dest.kind == methodType)
3222 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3223 if(source.kind == methodType)
3224 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3226 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3227 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3228 if(dest.kind == methodType)
3229 dest = dest.method.dataType;
3230 if(source.kind == methodType)
3231 source = source.method.dataType;
3233 paramSource = source.params.first;
3234 if(paramSource && paramSource.kind == voidType) paramSource = null;
3235 paramDest = dest.params.first;
3236 if(paramDest && paramDest.kind == voidType) paramDest = null;
3239 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3240 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3242 // Source thisClass must be derived from destination thisClass
3243 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3244 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3246 if(paramDest && paramDest.kind == classType)
3247 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3249 Compiler_Error($"method class should not take an object\n");
3252 paramDest = paramDest.next;
3254 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3256 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3260 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3262 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3268 // THIS WAS BACKWARDS:
3269 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3270 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3273 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3275 Compiler_Error($"overriding class expected to be derived from method class\n");
3279 paramSource = paramSource.next;
3285 // Source thisClass must be derived from destination thisClass
3286 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3288 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3294 // THIS WAS BACKWARDS TOO??
3295 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3296 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3299 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3301 //Compiler_Error($"overriding class expected to be derived from method class\n");
3309 // Source return type must be derived from destination return type
3310 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3312 Compiler_Warning($"incompatible return type for function\n");
3318 for(; paramDest; paramDest = paramDest.next)
3322 //Compiler_Warning($"not enough parameters\n");
3323 Compiler_Error($"not enough parameters\n");
3327 Type paramDestType = paramDest;
3328 Type paramSourceType = paramSource;
3329 Type type = paramDestType;
3331 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3332 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3333 paramSource.kind != templateType)
3336 ClassTemplateParameter curParam = null;
3338 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3341 if(sClass.templateClass) sClass = sClass.templateClass;
3342 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3344 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3346 for(sClass = sClass.base; sClass; sClass = sClass.base)
3348 if(sClass.templateClass) sClass = sClass.templateClass;
3349 id += sClass.templateParams.count;
3360 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3361 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3365 // paramDest must be derived from paramSource
3366 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3367 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3371 PrintType(paramDest, type, false, true);
3372 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3374 if(paramDestType != paramDest)
3375 FreeType(paramDestType);
3378 if(paramDestType != paramDest)
3379 FreeType(paramDestType);
3382 paramSource = paramSource.next;
3386 Compiler_Error($"too many parameters\n");
3391 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3395 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3396 (source.kind == arrayType || source.kind == pointerType))
3398 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3405 static void FreeConvert(Conversion convert)
3407 if(convert.resultType)
3408 FreeType(convert.resultType);
3411 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3412 char * string, OldList conversions)
3416 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3418 Class _class = link.data;
3419 if(_class.type == enumClass)
3421 OldList converts { };
3423 type.kind = classType;
3426 _class.symbol = FindClass(_class.fullName);
3427 type._class = _class.symbol;
3429 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3432 Class enumClass = eSystem_FindClass(privateModule, "enum");
3436 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3438 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3439 for(value = e.values.first; value; value = value.next)
3441 if(!strcmp(value.name, string))
3446 FreeExpContents(sourceExp);
3447 FreeType(sourceExp.expType);
3449 sourceExp.isConstant = true;
3450 sourceExp.expType = MkClassType(baseClass.fullName);
3454 sourceExp.type = constantExp;
3455 if(!strcmp(baseClass.dataTypeString, "int"))
3456 sprintf(constant, "%d",(int)value.data);
3458 sprintf(constant, "0x%X",(int)value.data);
3459 sourceExp.constant = CopyString(constant);
3460 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3463 while(converts.first)
3465 Conversion convert = converts.first;
3466 converts.Remove(convert);
3467 conversions.Add(convert);
3476 converts.Free(FreeConvert);
3480 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3481 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3486 public bool ModuleVisibility(Module searchIn, Module searchFor)
3488 SubModule subModule;
3490 if(searchFor == searchIn)
3493 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3495 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3497 if(ModuleVisibility(subModule.module, searchFor))
3504 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3508 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3510 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3512 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3515 for(module = mainModule.application.allModules.first; module; module = module.next)
3517 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3523 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3526 Type realDest = dest;
3527 Type backupSourceExpType = null;
3528 Expression computedExp = sourceExp;
3531 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3532 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3534 computedExp = CopyExpression(sourceExp); // Keep the original expression, but compute for checking enum ranges
3535 ComputeExpression(computedExp /*sourceExp*/);
3538 source = sourceExp.expType;
3540 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3542 if(computedExp != sourceExp)
3544 FreeExpression(computedExp);
3545 computedExp = sourceExp;
3551 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3553 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3555 Class sourceBase, destBase;
3556 for(sourceBase = source._class.registered;
3557 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3558 sourceBase = sourceBase.base);
3559 for(destBase = dest._class.registered;
3560 destBase && destBase.base && destBase.base.type != systemClass;
3561 destBase = destBase.base);
3562 //if(source._class.registered == dest._class.registered)
3563 if(sourceBase == destBase)
3565 if(computedExp != sourceExp)
3567 FreeExpression(computedExp);
3568 computedExp = sourceExp;
3580 int64 value = MAXINT;
3584 if(computedExp.type == constantExp)
3587 value = strtoll(computedExp.constant, null, 0);
3589 value = strtoull(computedExp.constant, null, 0);
3591 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3594 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3596 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3598 if(computedExp != sourceExp)
3600 FreeExpression(computedExp);
3601 computedExp = sourceExp;
3604 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3605 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3608 source = Type { kind = intType, isSigned = false, refCount = 1 };
3611 if(dest.kind == classType)
3613 Class _class = dest._class ? dest._class.registered : null;
3615 if(_class && _class.type == unitClass)
3617 if(source.kind != classType)
3620 Type tempDest, tempSource;
3622 for(; _class.base.type != systemClass; _class = _class.base);
3624 tempDest = tempType;
3626 tempType.kind = classType;
3628 _class.symbol = FindClass(_class.fullName);
3630 tempType._class = _class.symbol;
3631 tempType.truth = dest.truth;
3633 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3635 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3636 backupSourceExpType = sourceExp.expType;
3637 sourceExp.expType = dest; dest.refCount++;
3638 //sourceExp.expType = MkClassType(_class.fullName);
3646 // Why wasn't there something like this?
3647 if(_class && _class.type == bitClass && source.kind != classType)
3649 if(!dest._class.registered.dataType)
3650 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3651 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3654 FreeType(sourceExp.expType);
3655 source = sourceExp.expType = MkClassType(dest._class.string);
3658 //source.kind = classType;
3659 //source._class = dest._class;
3663 // Adding two enumerations
3665 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3667 if(!source._class.registered.dataType)
3668 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3669 if(!dest._class.registered.dataType)
3670 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3672 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3675 source = sourceExp.expType = MkClassType(dest._class.string);
3678 //source.kind = classType;
3679 //source._class = dest._class;
3683 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3685 OldList * specs = MkList();
3689 ReadString(string, sourceExp.string);
3690 decl = SpecDeclFromString(string, specs, null);
3692 FreeExpContents(sourceExp);
3693 FreeType(sourceExp.expType);
3695 sourceExp.type = classExp;
3696 sourceExp._classExp.specifiers = specs;
3697 sourceExp._classExp.decl = decl;
3698 sourceExp.expType = dest;
3703 if(backupSourceExpType) FreeType(backupSourceExpType);
3707 else if(source.kind == classType)
3709 Class _class = source._class ? source._class.registered : null;
3711 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3714 if(dest.kind != classType)
3716 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3717 if(!source._class.registered.dataType)
3718 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3721 dest = MkClassType(source._class.string);
3722 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3723 // dest = MkClassType(source._class.string);
3727 if(dest.kind != classType)
3730 Type tempDest, tempSource;
3732 if(!source._class.registered.dataType)
3733 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3735 for(; _class.base.type != systemClass; _class = _class.base);
3737 tempSource = tempType;
3738 tempType.kind = classType;
3739 tempType._class = FindClass(_class.fullName);
3740 tempType.truth = source.truth;
3741 tempType.classObjectType = source.classObjectType;
3744 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3746 // PUT THIS BACK TESTING UNITS?
3747 if(conversions.last)
3749 ((Conversion)(conversions.last)).resultType = dest;
3753 FreeType(sourceExp.expType);
3754 sourceExp.expType = MkClassType(_class.fullName);
3755 sourceExp.expType.truth = source.truth;
3756 sourceExp.expType.classObjectType = source.classObjectType;
3758 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3760 if(!sourceExp.destType)
3762 FreeType(sourceExp.destType);
3763 sourceExp.destType = sourceExp.expType;
3764 if(sourceExp.expType)
3765 sourceExp.expType.refCount++;
3768 //source = _class.dataType;
3771 // TOCHECK: TESTING THIS NEW CODE
3772 if(!_class.dataType)
3773 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3775 dest = MkClassType(source._class.string);
3776 dest.truth = source.truth;
3777 dest.classObjectType = source.classObjectType;
3780 source = _class.dataType;
3790 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3800 if(source.kind == classType)
3802 Class _class = source._class.registered;
3803 if(_class.type == unitClass)
3805 if(!_class.dataType)
3806 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3807 source = _class.dataType;
3811 if(dest.kind == classType)
3813 Class _class = dest._class ? dest._class.registered : null;
3814 bool fittingValue = false;
3815 if(_class && _class.type == enumClass)
3817 Class enumClass = eSystem_FindClass(privateModule, "enum");
3818 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3819 if(c && value >= 0 && value <= c.largest)
3820 fittingValue = true;
3823 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3824 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3826 if(_class.type == normalClass || _class.type == noHeadClass)
3828 Expression newExp { };
3829 *newExp = *sourceExp;
3830 if(sourceExp.destType) sourceExp.destType.refCount++;
3831 if(sourceExp.expType) sourceExp.expType.refCount++;
3832 sourceExp.type = castExp;
3833 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3834 sourceExp.cast.exp = newExp;
3835 FreeType(sourceExp.expType);
3836 sourceExp.expType = null;
3837 ProcessExpressionType(sourceExp);
3839 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3842 FreeType(sourceExp.expType);
3843 sourceExp.expType = dest;
3847 if(inCompiler) FreeType(dest);
3849 if(backupSourceExpType) FreeType(backupSourceExpType);
3853 if(!_class.dataType)
3854 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3856 dest = _class.dataType;
3860 // Accept lower precision types for units, since we want to keep the unit type
3861 if(dest.kind == doubleType &&
3862 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3863 source.kind == charType || source.kind == _BoolType))
3865 specs = MkListOne(MkSpecifier(DOUBLE));
3867 else if(dest.kind == floatType &&
3868 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3869 source.kind == _BoolType || source.kind == doubleType))
3871 specs = MkListOne(MkSpecifier(FLOAT));
3873 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3874 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3877 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3878 ListAdd(specs, MkSpecifier(INT64));
3880 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3881 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3884 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3885 ListAdd(specs, MkSpecifier(INT));
3887 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3888 source.kind == floatType || source.kind == doubleType))
3891 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3892 ListAdd(specs, MkSpecifier(SHORT));
3894 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3895 source.kind == floatType || source.kind == doubleType))
3898 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3899 ListAdd(specs, MkSpecifier(CHAR));
3905 if(backupSourceExpType)
3907 // Failed to convert: revert previous exp type
3908 if(sourceExp.expType) FreeType(sourceExp.expType);
3909 sourceExp.expType = backupSourceExpType;
3914 else if(dest.kind == doubleType &&
3915 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3916 source.kind == _BoolType || source.kind == charType))
3918 specs = MkListOne(MkSpecifier(DOUBLE));
3920 else if(dest.kind == floatType &&
3921 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3923 specs = MkListOne(MkSpecifier(FLOAT));
3925 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3926 (value == 1 || value == 0))
3929 ListAdd(specs, MkSpecifier(BOOL));
3931 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3932 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3935 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3936 ListAdd(specs, MkSpecifier(CHAR));
3938 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3939 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3942 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3943 ListAdd(specs, MkSpecifier(SHORT));
3945 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3948 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3949 ListAdd(specs, MkSpecifier(INT));
3951 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3954 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3955 ListAdd(specs, MkSpecifier(INT64));
3957 else if(dest.kind == enumType &&
3958 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3960 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3966 if(backupSourceExpType)
3968 // Failed to convert: revert previous exp type
3969 if(sourceExp.expType) FreeType(sourceExp.expType);
3970 sourceExp.expType = backupSourceExpType;
3975 if(!flag && !sourceExp.opDestType)
3977 Expression newExp { };
3978 *newExp = *sourceExp;
3981 if(sourceExp.destType) sourceExp.destType.refCount++;
3982 if(sourceExp.expType) sourceExp.expType.refCount++;
3984 sourceExp.type = castExp;
3985 if(realDest.kind == classType)
3987 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3988 FreeList(specs, FreeSpecifier);
3991 sourceExp.cast.typeName = MkTypeName(specs, null);
3992 if(newExp.type == opExp)
3994 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3997 sourceExp.cast.exp = newExp;
3999 FreeType(sourceExp.expType);
4000 sourceExp.expType = null;
4001 ProcessExpressionType(sourceExp);
4004 FreeList(specs, FreeSpecifier);
4008 if(backupSourceExpType) FreeType(backupSourceExpType);
4014 if(computedExp != sourceExp)
4016 FreeExpression(computedExp);
4017 computedExp = sourceExp;
4020 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4021 if(sourceExp.type == identifierExp)
4023 Identifier id = sourceExp.identifier;
4024 if(dest.kind == classType)
4026 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4028 Class _class = dest._class.registered;
4029 Class enumClass = eSystem_FindClass(privateModule, "enum");
4032 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4035 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4036 for(value = e.values.first; value; value = value.next)
4038 if(!strcmp(value.name, id.string))
4043 FreeExpContents(sourceExp);
4044 FreeType(sourceExp.expType);
4046 sourceExp.isConstant = true;
4047 sourceExp.expType = MkClassType(_class.fullName);
4051 sourceExp.type = constantExp;
4052 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
4053 sprintf(constant, "%d", (int) value.data);
4055 sprintf(constant, "0x%X", (int) value.data);
4056 sourceExp.constant = CopyString(constant);
4057 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4067 // Loop through all enum classes
4068 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4079 #define TERTIARY(o, name, m, t, p) \
4080 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4082 exp.type = constantExp; \
4083 exp.string = p(op1.m ? op2.m : op3.m); \
4085 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4089 #define BINARY(o, name, m, t, p) \
4090 static bool name(Expression exp, Operand op1, Operand op2) \
4093 exp.type = constantExp; \
4094 exp.string = p((t)(op1.m o value2)); \
4096 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4100 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4101 static bool name(Expression exp, Operand op1, Operand op2) \
4104 exp.type = constantExp; \
4105 exp.string = p(value2 ? (op1.m o value2) : 0); \
4107 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4111 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4112 static bool name(Expression exp, Operand op1, Operand op2) \
4115 exp.type = constantExp; \
4116 exp.string = p(op1.m o value2); \
4118 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4122 #define UNARY(o, name, m, t, p) \
4123 static bool name(Expression exp, Operand op1) \
4125 exp.type = constantExp; \
4126 exp.string = p((t)(o op1.m)); \
4128 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4132 #define OPERATOR_ALL(macro, o, name) \
4133 macro(o, Int##name, i, int, PrintInt) \
4134 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4135 macro(o, Int64##name, i64, int64, PrintInt64) \
4136 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4137 macro(o, Short##name, s, short, PrintShort) \
4138 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4139 macro(o, Char##name, c, char, PrintChar) \
4140 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4141 macro(o, Float##name, f, float, PrintFloat) \
4142 macro(o, Double##name, d, double, PrintDouble)
4144 #define OPERATOR_INTTYPES(macro, o, name) \
4145 macro(o, Int##name, i, int, PrintInt) \
4146 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4147 macro(o, Int64##name, i64, int64, PrintInt64) \
4148 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4149 macro(o, Short##name, s, short, PrintShort) \
4150 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4151 macro(o, Char##name, c, char, PrintChar) \
4152 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4154 #define OPERATOR_REALTYPES(macro, o, name) \
4155 macro(o, Float##name, f, float, PrintFloat) \
4156 macro(o, Double##name, d, double, PrintDouble)
4158 // binary arithmetic
4159 OPERATOR_ALL(BINARY, +, Add)
4160 OPERATOR_ALL(BINARY, -, Sub)
4161 OPERATOR_ALL(BINARY, *, Mul)
4162 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4163 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4164 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4167 OPERATOR_ALL(UNARY, -, Neg)
4169 // unary arithmetic increment and decrement
4170 OPERATOR_ALL(UNARY, ++, Inc)
4171 OPERATOR_ALL(UNARY, --, Dec)
4173 // binary arithmetic assignment
4174 OPERATOR_ALL(BINARY, =, Asign)
4175 OPERATOR_ALL(BINARY, +=, AddAsign)
4176 OPERATOR_ALL(BINARY, -=, SubAsign)
4177 OPERATOR_ALL(BINARY, *=, MulAsign)
4178 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4179 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4180 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4183 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4184 OPERATOR_INTTYPES(BINARY, |, BitOr)
4185 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4186 OPERATOR_INTTYPES(BINARY, <<, LShift)
4187 OPERATOR_INTTYPES(BINARY, >>, RShift)
4190 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4192 // binary bitwise assignment
4193 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4194 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4195 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4196 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4197 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4199 // unary logical negation
4200 OPERATOR_INTTYPES(UNARY, !, Not)
4202 // binary logical equality
4203 OPERATOR_ALL(BINARY, ==, Equ)
4204 OPERATOR_ALL(BINARY, !=, Nqu)
4207 OPERATOR_ALL(BINARY, &&, And)
4208 OPERATOR_ALL(BINARY, ||, Or)
4210 // binary logical relational
4211 OPERATOR_ALL(BINARY, >, Grt)
4212 OPERATOR_ALL(BINARY, <, Sma)
4213 OPERATOR_ALL(BINARY, >=, GrtEqu)
4214 OPERATOR_ALL(BINARY, <=, SmaEqu)
4216 // tertiary condition operator
4217 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4219 //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
4220 #define OPERATOR_TABLE_ALL(name, type) \
4221 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4223 type##Inc, type##Dec, \
4224 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4225 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4227 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4229 type##Equ, type##Nqu, \
4230 type##And, type##Or, \
4231 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4234 #define OPERATOR_TABLE_INTTYPES(name, type) \
4235 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4237 type##Inc, type##Dec, \
4238 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4239 null, null, null, null, null, \
4241 null, null, null, null, null, \
4243 type##Equ, type##Nqu, \
4244 type##And, type##Or, \
4245 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4248 OPERATOR_TABLE_ALL(int, Int)
4249 OPERATOR_TABLE_ALL(uint, UInt)
4250 OPERATOR_TABLE_ALL(int64, Int64)
4251 OPERATOR_TABLE_ALL(uint64, UInt64)
4252 OPERATOR_TABLE_ALL(short, Short)
4253 OPERATOR_TABLE_ALL(ushort, UShort)
4254 OPERATOR_TABLE_INTTYPES(float, Float)
4255 OPERATOR_TABLE_INTTYPES(double, Double)
4256 OPERATOR_TABLE_ALL(char, Char)
4257 OPERATOR_TABLE_ALL(uchar, UChar)
4259 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4260 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4261 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4262 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4263 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4264 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4265 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4266 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4268 public void ReadString(char * output, char * string)
4270 int len = strlen(string);
4272 bool quoted = false, escaped = false;
4273 for(c = 0; c<len; c++)
4275 char ch = string[c];
4280 case 'n': output[d] = '\n'; break;
4281 case 't': output[d] = '\t'; break;
4282 case 'a': output[d] = '\a'; break;
4283 case 'b': output[d] = '\b'; break;
4284 case 'f': output[d] = '\f'; break;
4285 case 'r': output[d] = '\r'; break;
4286 case 'v': output[d] = '\v'; break;
4287 case '\\': output[d] = '\\'; break;
4288 case '\"': output[d] = '\"'; break;
4289 case '\'': output[d] = '\''; break;
4290 default: output[d] = ch;
4311 // String Unescape Copy
4313 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4314 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4315 public int UnescapeString(char * d, char * s, int len)
4319 while(j < len && (ch = s[j]))
4324 switch((ch = s[++j]))
4326 case 'n': d[k] = '\n'; break;
4327 case 't': d[k] = '\t'; break;
4328 case 'a': d[k] = '\a'; break;
4329 case 'b': d[k] = '\b'; break;
4330 case 'f': d[k] = '\f'; break;
4331 case 'r': d[k] = '\r'; break;
4332 case 'v': d[k] = '\v'; break;
4333 case '\\': d[k] = '\\'; break;
4334 case '\"': d[k] = '\"'; break;
4335 case '\'': d[k] = '\''; break;
4336 default: d[k] = '\\'; d[k] = ch;
4348 public char * OffsetEscapedString(char * s, int len, int offset)
4352 while(j < len && k < offset && (ch = s[j]))
4357 return (k == offset) ? s + j : null;
4360 public Operand GetOperand(Expression exp)
4363 Type type = exp.expType;
4366 while(type.kind == classType &&
4367 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4369 if(!type._class.registered.dataType)
4370 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4371 type = type._class.registered.dataType;
4374 if(exp.type == stringExp && op.kind == pointerType)
4376 op.ui64 = (uint64)exp.string;
4377 op.kind = pointerType;
4380 else if(exp.isConstant && exp.type == constantExp)
4382 op.kind = type.kind;
4383 op.type = exp.expType;
4390 if(exp.constant[0] == '\'')
4392 op.c = exp.constant[1];
4395 else if(type.isSigned)
4397 op.c = (char)strtol(exp.constant, null, 0);
4402 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4410 op.s = (short)strtol(exp.constant, null, 0);
4415 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4423 op.i = (int)strtol(exp.constant, null, 0);
4428 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4436 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4441 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4444 op.kind = int64Type;
4449 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4454 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4457 op.kind = int64Type;
4462 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4467 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4470 op.kind = int64Type;
4473 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4474 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4475 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4476 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4478 op.f = (float)strtod(exp.constant, null);
4482 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4483 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4484 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4485 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4487 op.d = (double)strtod(exp.constant, null);
4490 //case classType: For when we have operator overloading...
4491 // Pointer additions
4492 //case functionType:
4496 op.ui64 = _strtoui64(exp.constant, null, 0);
4497 op.kind = pointerType;
4507 static void UnusedFunction()
4510 a.OnGetString(0,0,0);
4513 extern int __ecereVMethodID_class_OnGetString;
4516 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4518 DataMember dataMember;
4519 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4521 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4522 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4526 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4528 void * ptr = inst.data + dataMember.offset + offset;
4529 char * result = null;
4530 exp.loc = member.loc = inst.loc;
4531 ((Identifier)member.identifiers->first).loc = inst.loc;
4533 if(!dataMember.dataType)
4534 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4535 type = dataMember.dataType;
4536 if(type.kind == classType)
4538 Class _class = type._class.registered;
4539 if(_class.type == enumClass)
4541 Class enumClass = eSystem_FindClass(privateModule, "enum");
4544 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4546 for(item = e.values.first; item; item = item.next)
4548 if((int)item.data == *(int *)ptr)
4556 exp.identifier = MkIdentifier(result);
4557 exp.type = identifierExp;
4558 exp.destType = MkClassType(_class.fullName);
4559 ProcessExpressionType(exp);
4563 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4565 if(!_class.dataType)
4566 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4567 type = _class.dataType;
4576 FreeExpContents(exp);
4578 exp.constant = PrintFloat(*(float*)ptr);
4579 exp.type = constantExp;
4584 FreeExpContents(exp);
4586 exp.constant = PrintDouble(*(double*)ptr);
4587 exp.type = constantExp;
4592 FreeExpContents(exp);
4594 exp.constant = PrintInt(*(int*)ptr);
4595 exp.type = constantExp;
4600 FreeExpContents(exp);
4602 exp.constant = PrintInt64(*(int64*)ptr);
4603 exp.type = constantExp;
4608 FreeExpContents(exp);
4609 // TODO: This should probably use proper type
4610 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4611 exp.type = constantExp;
4616 FreeExpContents(exp);
4617 // TODO: This should probably use proper type
4618 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4619 exp.type = constantExp;
4623 Compiler_Error($"Unhandled type populating instance\n");
4626 ListAdd(memberList, member);
4629 if(parentDataMember.type == unionMember)
4634 void PopulateInstance(Instantiation inst)
4636 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4637 Class _class = classSym.registered;
4638 DataMember dataMember;
4639 OldList * memberList = MkList();
4640 // Added this check and ->Add to prevent memory leaks on bad code
4642 inst.members = MkListOne(MkMembersInitList(memberList));
4644 inst.members->Add(MkMembersInitList(memberList));
4645 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4647 if(!dataMember.isProperty)
4649 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4650 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4654 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4656 void * ptr = inst.data + dataMember.offset;
4657 char * result = null;
4659 exp.loc = member.loc = inst.loc;
4660 ((Identifier)member.identifiers->first).loc = inst.loc;
4662 if(!dataMember.dataType)
4663 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4664 type = dataMember.dataType;
4665 if(type.kind == classType)
4667 Class _class = type._class.registered;
4668 if(_class.type == enumClass)
4670 Class enumClass = eSystem_FindClass(privateModule, "enum");
4673 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4675 for(item = e.values.first; item; item = item.next)
4677 if((int)item.data == *(int *)ptr)
4686 exp.identifier = MkIdentifier(result);
4687 exp.type = identifierExp;
4688 exp.destType = MkClassType(_class.fullName);
4689 ProcessExpressionType(exp);
4692 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4694 if(!_class.dataType)
4695 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4696 type = _class.dataType;
4705 exp.constant = PrintFloat(*(float*)ptr);
4706 exp.type = constantExp;
4711 exp.constant = PrintDouble(*(double*)ptr);
4712 exp.type = constantExp;
4717 exp.constant = PrintInt(*(int*)ptr);
4718 exp.type = constantExp;
4723 exp.constant = PrintInt64(*(int64*)ptr);
4724 exp.type = constantExp;
4729 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4730 exp.type = constantExp;
4734 Compiler_Error($"Unhandled type populating instance\n");
4737 ListAdd(memberList, member);
4743 void ComputeInstantiation(Expression exp)
4745 Instantiation inst = exp.instance;
4746 MembersInit members;
4747 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4748 Class _class = classSym ? classSym.registered : null;
4749 DataMember curMember = null;
4750 Class curClass = null;
4751 DataMember subMemberStack[256];
4752 int subMemberStackPos = 0;
4755 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4757 // Don't recompute the instantiation...
4758 // Non Simple classes will have become constants by now
4762 if(_class.type == normalClass || _class.type == noHeadClass)
4764 inst.data = (byte *)eInstance_New(_class);
4765 if(_class.type == normalClass)
4766 ((Instance)inst.data)._refCount++;
4769 inst.data = new0 byte[_class.structSize];
4774 for(members = inst.members->first; members; members = members.next)
4776 switch(members.type)
4778 case dataMembersInit:
4780 if(members.dataMembers)
4783 for(member = members.dataMembers->first; member; member = member.next)
4785 Identifier ident = member.identifiers ? member.identifiers->first : null;
4788 Property prop = null;
4789 DataMember dataMember = null;
4790 Method method = null;
4791 uint dataMemberOffset;
4795 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4798 if(curMember.isProperty)
4799 prop = (Property)curMember;
4802 dataMember = curMember;
4804 // CHANGED THIS HERE
4805 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4807 // 2013/17/29 -- It seems that this was missing here!
4808 if(_class.type == normalClass)
4809 dataMemberOffset += _class.base.structSize;
4810 // dataMemberOffset = dataMember.offset;
4817 prop = eClass_FindProperty(_class, ident.string, privateModule);
4821 if(prop.memberAccess == publicAccess)
4823 curMember = (DataMember)prop;
4824 curClass = prop._class;
4829 DataMember _subMemberStack[256];
4830 int _subMemberStackPos = 0;
4832 // FILL MEMBER STACK
4833 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4838 if(dataMember.memberAccess == publicAccess)
4840 curMember = dataMember;
4841 curClass = dataMember._class;
4842 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4843 subMemberStackPos = _subMemberStackPos;
4849 if(found && member.initializer && member.initializer.type == expInitializer)
4851 Expression value = member.initializer.exp;
4853 bool deepMember = false;
4856 type = prop.dataType;
4860 if(!dataMember.dataType)
4861 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4863 type = dataMember.dataType;
4866 if(ident && ident.next)
4870 // for(; ident && type; ident = ident.next)
4871 for(ident = ident.next; ident && type; ident = ident.next)
4873 if(type.kind == classType)
4875 prop = eClass_FindProperty(type._class.registered,
4876 ident.string, privateModule);
4878 type = prop.dataType;
4881 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4882 ident.string, &dataMemberOffset, privateModule, null, null);
4884 type = dataMember.dataType;
4887 else if(type.kind == structType || type.kind == unionType)
4890 for(memberType = type.members.first; memberType; memberType = memberType.next)
4892 if(!strcmp(memberType.name, ident.string))
4903 FreeType(value.destType);
4904 value.destType = type;
4905 if(type) type.refCount++;
4906 ComputeExpression(value);
4908 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4910 if(type.kind == classType)
4912 Class _class = type._class.registered;
4913 if(_class.type == bitClass || _class.type == unitClass ||
4914 _class.type == enumClass)
4916 if(!_class.dataType)
4917 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4918 type = _class.dataType;
4924 void * ptr = inst.data + dataMemberOffset;
4926 if(value.type == constantExp)
4932 GetInt(value, (int*)ptr);
4937 GetInt64(value, (int64*)ptr);
4942 GetIntPtr(value, (intptr*)ptr);
4947 GetIntSize(value, (intsize*)ptr);
4952 GetFloat(value, (float*)ptr);
4957 GetDouble(value, (double *)ptr);
4962 else if(value.type == instanceExp)
4964 if(type.kind == classType)
4966 Class _class = type._class.registered;
4967 if(_class.type == structClass)
4969 ComputeTypeSize(type);
4970 if(value.instance.data)
4971 memcpy(ptr, value.instance.data, type.size);
4978 if(value.type == instanceExp && value.instance.data)
4980 if(type.kind == classType)
4982 Class _class = type._class.registered;
4983 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
4985 void (*Set)(void *, void *) = (void *)prop.Set;
4986 Set(inst.data, value.instance.data);
4987 PopulateInstance(inst);
4991 else if(value.type == constantExp)
4997 void (*Set)(void *, double) = (void *)prop.Set;
4998 Set(inst.data, strtod(value.constant, null) );
5003 void (*Set)(void *, float) = (void *)prop.Set;
5004 Set(inst.data, (float)(strtod(value.constant, null)));
5009 void (*Set)(void *, int) = (void *)prop.Set;
5010 Set(inst.data, (int)strtol(value.constant, null, 0));
5015 void (*Set)(void *, int64) = (void *)prop.Set;
5016 Set(inst.data, _strtoi64(value.constant, null, 0));
5021 void (*Set)(void *, intptr) = (void *)prop.Set;
5022 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5027 void (*Set)(void *, intsize) = (void *)prop.Set;
5028 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5033 else if(value.type == stringExp)
5036 ReadString(temp, value.string);
5037 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5041 else if(!deepMember && type && _class.type == unitClass)
5045 // Only support converting units to units for now...
5046 if(value.type == constantExp)
5048 if(type.kind == classType)
5050 Class _class = type._class.registered;
5051 if(_class.type == unitClass)
5053 if(!_class.dataType)
5054 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5055 type = _class.dataType;
5058 // TODO: Assuming same base type for units...
5064 float (*Set)(float) = (void *)prop.Set;
5065 GetFloat(member.initializer.exp, &fValue);
5066 exp.constant = PrintFloat(Set(fValue));
5067 exp.type = constantExp;
5073 double (*Set)(double) = (void *)prop.Set;
5074 GetDouble(member.initializer.exp, &dValue);
5075 exp.constant = PrintDouble(Set(dValue));
5076 exp.type = constantExp;
5083 else if(!deepMember && type && _class.type == bitClass)
5087 if(value.type == instanceExp && value.instance.data)
5089 unsigned int (*Set)(void *) = (void *)prop.Set;
5090 bits = Set(value.instance.data);
5092 else if(value.type == constantExp)
5098 BitMember bitMember = (BitMember) dataMember;
5101 bits = (bits & ~bitMember.mask);
5102 if(!bitMember.dataType)
5103 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5104 type = bitMember.dataType;
5105 if(type.kind == classType && type._class && type._class.registered)
5107 if(!type._class.registered.dataType)
5108 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5109 type = type._class.registered.dataType;
5114 case charType: { byte v; type.isSigned ? GetChar(value, &v) : GetUChar(value, &v); part = (uint64)v; break; }
5115 case shortType: { uint16 v; type.isSigned ? GetShort(value, &v) : GetUShort(value, &v); part = (uint64)v; break; }
5117 case longType: { uint v; type.isSigned ? GetInt(value, &v) : GetUInt(value, &v); part = (uint64)v; break; }
5118 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, &v) : GetUInt64(value, &v); part = (uint64)v; break; }
5119 case intPtrType: { intptr v; type.isSigned ? GetIntPtr(value, &v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5120 case intSizeType: { intsize v; type.isSigned ? GetIntSize(value, &v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5122 bits |= part << bitMember.pos;
5128 if(_class && _class.type == unitClass)
5130 ComputeExpression(member.initializer.exp);
5131 exp.constant = member.initializer.exp.constant;
5132 exp.type = constantExp;
5134 member.initializer.exp.constant = null;
5144 if(_class && _class.type == bitClass)
5146 exp.constant = PrintHexUInt(bits);
5147 exp.type = constantExp;
5149 if(exp.type != instanceExp)
5155 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5157 bool result = false;
5161 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5162 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5166 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5167 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5170 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5171 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5172 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5175 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5176 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5177 result = GetOpFloat(op, &op.f);
5180 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5181 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5182 result = GetOpDouble(op, &op.d);
5185 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5186 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5187 result = GetOpUIntPtr(op, &op.ui64);
5190 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5191 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5192 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5195 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5196 result = isSigned ? GetOpIntPtr(op, &op.i64) : GetOpUIntPtr(op, &op.i64);
5199 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5200 result = isSigned ? GetOpIntSize(op, &op.ui64) : GetOpUIntSize(op, &op.ui64);
5206 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5208 if(exp.op.op == SIZEOF)
5210 FreeExpContents(exp);
5211 exp.type = constantExp;
5212 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5223 // Provide default unary +
5224 Expression exp2 = exp.op.exp2;
5226 FreeExpContents(exp);
5227 FreeType(exp.expType);
5228 FreeType(exp.destType);
5234 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5236 // unary arithmetic increment and decrement
5237 //OPERATOR_ALL(UNARY, ++, Inc)
5238 //OPERATOR_ALL(UNARY, --, Dec)
5241 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5243 // unary logical negation
5245 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5251 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5253 if(Promote(op2, op1.kind, op1.type.isSigned))
5254 op2.kind = op1.kind, op2.ops = op1.ops;
5255 else if(Promote(op1, op2.kind, op2.type.isSigned))
5256 op1.kind = op2.kind, op1.ops = op2.ops;
5260 // binary arithmetic
5262 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5265 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5268 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5271 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5274 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5276 // binary arithmetic assignment
5277 //OPERATOR_ALL(BINARY, =, Asign)
5278 //OPERATOR_ALL(BINARY, +=, AddAsign)
5279 //OPERATOR_ALL(BINARY, -=, SubAsign)
5280 //OPERATOR_ALL(BINARY, *=, MulAsign)
5281 //OPERATOR_ALL(BINARY, /=, DivAsign)
5282 //OPERATOR_ALL(BINARY, %=, ModAsign)
5287 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5291 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5294 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5297 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5300 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5302 // binary bitwise assignment
5303 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5304 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5305 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5306 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5307 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5308 // binary logical equality
5310 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5313 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5317 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5320 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5322 // binary logical relational
5324 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5327 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5330 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5333 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5340 void ComputeExpression(Expression exp)
5342 char expString[10240];
5343 expString[0] = '\0';
5345 PrintExpression(exp, expString);
5352 ComputeInstantiation(exp);
5361 Expression exp1, exp2 = null;
5365 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5368 Expression e = exp.op.exp2;
5370 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5372 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5374 if(e.type == extensionCompoundExp)
5375 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5380 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5382 if(e.type == stringExp && e.string)
5384 char * string = e.string;
5385 int len = strlen(string);
5386 char * tmp = new char[len-2+1];
5387 len = UnescapeString(tmp, string + 1, len - 2);
5389 FreeExpContents(exp);
5390 exp.type = constantExp;
5391 exp.constant = PrintUInt(len + 1);
5395 Type type = e.expType;
5397 FreeExpContents(exp);
5398 exp.type = constantExp;
5399 exp.constant = PrintUInt(ComputeTypeSize(type));
5405 ComputeExpression(exp.op.exp2);
5409 ComputeExpression(exp.op.exp1);
5412 op1 = GetOperand(exp1);
5413 if(op1.type) op1.type.refCount++;
5416 op2 = GetOperand(exp2);
5417 if(op2.type) op2.type.refCount++;
5423 op1 = GetOperand(exp1);
5424 if(op1.type) op1.type.refCount++;
5427 CallOperator(exp, exp1, exp2, op1, op2);
5434 if(exp.op.exp1 && exp.op.exp2)
5439 FreeExpContents(exp);
5440 op1.ops.BitAnd(exp, op1, op2);
5449 FreeExpContents(exp);
5450 op1.ops.Mul(exp, op1, op2);
5459 FreeExpContents(exp);
5460 op1.ops.Add(exp, op1, op2);
5465 // Provide default unary +
5466 Expression exp2 = exp.op.exp2;
5468 FreeExpContents(exp);
5469 FreeType(exp.expType);
5470 FreeType(exp.destType);
5481 FreeExpContents(exp);
5482 op1.ops.Sub(exp, op1, op2);
5489 FreeExpContents(exp);
5490 op1.ops.Neg(exp, op1);
5497 FreeExpContents(exp);
5498 op1.ops.BitNot(exp, op1);
5504 FreeExpContents(exp);
5505 op1.ops.Not(exp, op1);
5508 // Binary only operators
5512 FreeExpContents(exp);
5513 op1.ops.Div(exp, op1, op2);
5519 FreeExpContents(exp);
5520 op1.ops.Mod(exp, op1, op2);
5532 FreeExpContents(exp);
5533 op1.ops.Sma(exp, op1, op2);
5542 FreeExpContents(exp);
5543 op1.ops.Grt(exp, op1, op2);
5552 FreeExpContents(exp);
5553 op1.ops.SmaEqu(exp, op1, op2);
5562 FreeExpContents(exp);
5563 op1.ops.GrtEqu(exp, op1, op2);
5572 FreeExpContents(exp);
5573 op1.ops.Equ(exp, op1, op2);
5582 FreeExpContents(exp);
5583 op1.ops.Nqu(exp, op1, op2);
5590 FreeExpContents(exp);
5591 op1.ops.BitOr(exp, op1, op2);
5597 FreeExpContents(exp);
5598 op1.ops.BitXor(exp, op1, op2);
5606 FreeExpContents(exp);
5607 exp.type = constantExp;
5608 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5612 if(op1.type) FreeType(op1.type);
5613 if(op2.type) FreeType(op2.type);
5617 case extensionExpressionExp:
5620 for(e = exp.list->first; e; e = n)
5625 OldList * list = exp.list;
5626 Expression prev = exp.prev;
5627 Expression next = exp.next;
5628 ComputeExpression(e);
5629 //FreeExpContents(exp);
5630 FreeType(exp.expType);
5631 FreeType(exp.destType);
5650 exp.isConstant = true;
5652 ComputeExpression(exp.index.exp);
5653 if(!exp.index.exp.isConstant)
5654 exp.isConstant = false;
5656 for(e = exp.index.index->first; e; e = e.next)
5658 ComputeExpression(e);
5661 // Check if this type is int
5664 exp.isConstant = false;
5666 exp.expType = Dereference(exp.index.exp.expType);
5672 Expression memberExp = exp.member.exp;
5673 Identifier memberID = exp.member.member;
5676 ComputeExpression(exp.member.exp);
5677 type = exp.member.exp.expType;
5680 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);
5681 Property prop = null;
5682 DataMember member = null;
5683 Class convertTo = null;
5684 if(type.kind == subClassType && exp.member.exp.type == classExp)
5685 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5692 PrintTypeNoConst(type, string, false, true);
5693 classSym = FindClass(string);
5694 _class = classSym ? classSym.registered : null;
5697 if(exp.member.member)
5699 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5701 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5703 if(!prop && !member && _class && exp.member.member)
5705 Symbol classSym = FindClass(exp.member.member.string);
5707 _class = classSym ? classSym.registered : null;
5708 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5715 Type type = prop.dataType;
5716 // TODO: Assuming same base type for units...
5717 if(_class.type == unitClass)
5719 if(type.kind == classType)
5721 Class _class = type._class.registered;
5722 if(_class.type == unitClass)
5724 if(!_class.dataType)
5725 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5726 type = _class.dataType;
5734 float (*Get)(float) = (void *)prop.Get;
5735 GetFloat(exp.member.exp, &value);
5736 exp.constant = PrintFloat(Get ? Get(value) : value);
5737 exp.type = constantExp;
5743 double (*Get)(double);
5744 GetDouble(exp.member.exp, &value);
5747 Get = (void *)prop.Set;
5749 Get = (void *)prop.Get;
5750 exp.constant = PrintDouble(Get ? Get(value) : value);
5751 exp.type = constantExp;
5760 Expression value = exp.member.exp;
5763 ProcessPropertyType(prop);
5765 type = prop.dataType;
5768 // printf("Investigate this\n");
5770 else if(_class.type == structClass)
5776 Class propertyClass = type._class.registered;
5777 if(propertyClass.type == structClass && value.type == instanceExp)
5779 void (*Set)(void *, void *) = (void *)prop.Set;
5780 exp.instance = Instantiation { };
5781 exp.instance.data = new0 byte[_class.structSize];
5782 exp.instance._class = MkSpecifierName(_class.fullName);
5783 exp.instance.loc = exp.loc;
5784 exp.type = instanceExp;
5785 Set(exp.instance.data, value.instance.data);
5786 PopulateInstance(exp.instance);
5793 void (*Set)(void *, int) = (void *)prop.Set;
5795 exp.instance = Instantiation { };
5796 exp.instance.data = new0 byte[_class.structSize];
5797 exp.instance._class = MkSpecifierName(_class.fullName);
5798 exp.instance.loc = exp.loc;
5799 exp.type = instanceExp;
5801 GetInt(value, &intValue);
5803 Set(exp.instance.data, intValue);
5804 PopulateInstance(exp.instance);
5810 void (*Set)(void *, int64) = (void *)prop.Set;
5812 exp.instance = Instantiation { };
5813 exp.instance.data = new0 byte[_class.structSize];
5814 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5815 exp.instance.loc = exp.loc;
5816 exp.type = instanceExp;
5818 GetInt64(value, &intValue);
5820 Set(exp.instance.data, intValue);
5821 PopulateInstance(exp.instance);
5828 void (*Set)(void *, intptr) = (void *)prop.Set;
5830 exp.instance = Instantiation { };
5831 exp.instance.data = new0 byte[_class.structSize];
5832 exp.instance._class = MkSpecifierName(_class.fullName);
5833 exp.instance.loc = exp.loc;
5834 exp.type = instanceExp;
5836 GetIntPtr(value, &intValue);
5838 Set(exp.instance.data, intValue);
5839 PopulateInstance(exp.instance);
5846 void (*Set)(void *, intsize) = (void *)prop.Set;
5848 exp.instance = Instantiation { };
5849 exp.instance.data = new0 byte[_class.structSize];
5850 exp.instance._class = MkSpecifierName(_class.fullName);
5851 exp.instance.loc = exp.loc;
5852 exp.type = instanceExp;
5854 GetIntSize(value, &intValue);
5856 Set(exp.instance.data, intValue);
5857 PopulateInstance(exp.instance);
5863 void (*Set)(void *, float) = (void *)prop.Set;
5865 exp.instance = Instantiation { };
5866 exp.instance.data = new0 byte[_class.structSize];
5867 exp.instance._class = MkSpecifierName(_class.fullName);
5868 exp.instance.loc = exp.loc;
5869 exp.type = instanceExp;
5871 GetFloat(value, &floatValue);
5873 Set(exp.instance.data, floatValue);
5874 PopulateInstance(exp.instance);
5880 void (*Set)(void *, double) = (void *)prop.Set;
5882 exp.instance = Instantiation { };
5883 exp.instance.data = new0 byte[_class.structSize];
5884 exp.instance._class = MkSpecifierName(_class.fullName);
5885 exp.instance.loc = exp.loc;
5886 exp.type = instanceExp;
5888 GetDouble(value, &doubleValue);
5890 Set(exp.instance.data, doubleValue);
5891 PopulateInstance(exp.instance);
5896 else if(_class.type == bitClass)
5902 Class propertyClass = type._class.registered;
5903 if(propertyClass.type == structClass && value.instance.data)
5905 unsigned int (*Set)(void *) = (void *)prop.Set;
5906 unsigned int bits = Set(value.instance.data);
5907 exp.constant = PrintHexUInt(bits);
5908 exp.type = constantExp;
5911 else if(_class.type == bitClass)
5914 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5917 GetUInt(exp.member.exp, &value);
5919 exp.constant = PrintHexUInt(bits);
5920 exp.type = constantExp;
5928 if(_class.type == bitClass)
5931 GetUInt(exp.member.exp, &value);
5937 Class _class = type._class.registered;
5938 if(_class.type == structClass)
5940 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5942 exp.instance = Instantiation { };
5943 exp.instance.data = new0 byte[_class.structSize];
5944 exp.instance._class = MkSpecifierName(_class.fullName);
5945 exp.instance.loc = exp.loc;
5946 //exp.instance.fullSet = true;
5947 exp.type = instanceExp;
5948 Get(value, exp.instance.data);
5949 PopulateInstance(exp.instance);
5951 else if(_class.type == bitClass)
5953 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5954 uint64 bits = Get(value);
5955 exp.constant = PrintHexUInt64(bits);
5956 exp.type = constantExp;
5962 else if(_class.type == structClass)
5964 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5969 Class _class = type._class.registered;
5970 if(_class.type == structClass && value)
5972 void (*Get)(void *, void *) = (void *)prop.Get;
5974 exp.instance = Instantiation { };
5975 exp.instance.data = new0 byte[_class.structSize];
5976 exp.instance._class = MkSpecifierName(_class.fullName);
5977 exp.instance.loc = exp.loc;
5978 //exp.instance.fullSet = true;
5979 exp.type = instanceExp;
5980 Get(value, exp.instance.data);
5981 PopulateInstance(exp.instance);
5989 char * value = exp.member.exp.instance.data;
5994 Class _class = type._class.registered;
5995 if(_class.type == normalClass)
5997 void *(*Get)(void *) = (void *)prop.Get;
5999 exp.instance = Instantiation { };
6000 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6001 exp.type = instanceExp;
6002 exp.instance.data = Get(value, exp.instance.data);
6014 exp.isConstant = false;
6022 if(exp.type != ExpressionType::memberExp)
6024 FreeExpression(memberExp);
6025 FreeIdentifier(memberID);
6031 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6032 FreeExpContents(exp);
6033 exp.constant = PrintUInt(ComputeTypeSize(type));
6034 exp.type = constantExp;
6040 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6041 if(classSym && classSym.registered)
6043 if(classSym.registered.fixed)
6045 FreeSpecifier(exp._class);
6046 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6047 exp.type = constantExp;
6051 char className[1024];
6052 strcpy(className, "__ecereClass_");
6053 FullClassNameCat(className, classSym.string, true);
6054 MangleClassName(className);
6056 DeclareClass(classSym, className);
6058 FreeExpContents(exp);
6059 exp.type = pointerExp;
6060 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6061 exp.member.member = MkIdentifier("structSize");
6071 if(exp.type == castExp)
6074 ComputeExpression(exp.cast.exp);
6077 if(e && exp.expType)
6080 type = exp.destType;
6083 if(type.kind == classType)
6085 Class _class = type._class.registered;
6086 if(_class && (_class.type == unitClass || _class.type == bitClass))
6088 if(!_class.dataType)
6089 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6090 type = _class.dataType;
6101 if(GetChar(e, &value))
6103 FreeExpContents(exp);
6104 exp.constant = PrintChar(value);
6105 exp.type = constantExp;
6110 unsigned char value = 0;
6111 if(GetUChar(e, &value))
6113 FreeExpContents(exp);
6114 exp.constant = PrintUChar(value);
6115 exp.type = constantExp;
6123 if(GetShort(e, &value))
6125 FreeExpContents(exp);
6126 exp.constant = PrintShort(value);
6127 exp.type = constantExp;
6132 unsigned short value = 0;
6133 if(GetUShort(e, &value))
6135 FreeExpContents(exp);
6136 exp.constant = PrintUShort(value);
6137 exp.type = constantExp;
6145 if(GetInt(e, &value))
6147 FreeExpContents(exp);
6148 exp.constant = PrintInt(value);
6149 exp.type = constantExp;
6154 unsigned int value = 0;
6155 if(GetUInt(e, &value))
6157 FreeExpContents(exp);
6158 exp.constant = PrintUInt(value);
6159 exp.type = constantExp;
6167 if(GetInt64(e, &value))
6169 FreeExpContents(exp);
6170 exp.constant = PrintInt64(value);
6171 exp.type = constantExp;
6177 if(GetUInt64(e, &value))
6179 FreeExpContents(exp);
6180 exp.constant = PrintUInt64(value);
6181 exp.type = constantExp;
6189 if(GetIntPtr(e, &value))
6191 FreeExpContents(exp);
6192 exp.constant = PrintInt64((int64)value);
6193 exp.type = constantExp;
6199 if(GetUIntPtr(e, &value))
6201 FreeExpContents(exp);
6202 exp.constant = PrintUInt64((uint64)value);
6203 exp.type = constantExp;
6211 if(GetIntSize(e, &value))
6213 FreeExpContents(exp);
6214 exp.constant = PrintInt64((int64)value);
6215 exp.type = constantExp;
6221 if(GetUIntSize(e, &value))
6223 FreeExpContents(exp);
6224 exp.constant = PrintUInt64((uint64)value);
6225 exp.type = constantExp;
6232 if(GetFloat(e, &value))
6234 FreeExpContents(exp);
6235 exp.constant = PrintFloat(value);
6236 exp.type = constantExp;
6243 if(GetDouble(e, &value))
6245 FreeExpContents(exp);
6246 exp.constant = PrintDouble(value);
6247 exp.type = constantExp;
6262 // Caring only about last expression for now...
6263 ComputeExpression(exp.cond.exp->last);
6264 if(exp.cond.elseExp)
6265 ComputeExpression(exp.cond.elseExp);
6267 ComputeExpression(exp.cond.cond);
6269 op1 = GetOperand(exp.cond.cond);
6270 if(op1.type) op1.type.refCount++;
6271 op2 = GetOperand(exp.cond.exp->last);
6272 if(op2.type) op2.type.refCount++;
6273 op3 = GetOperand(exp.cond.elseExp);
6274 if(op3.type) op3.type.refCount++;
6276 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6277 if(op1.type) FreeType(op1.type);
6278 if(op2.type) FreeType(op2.type);
6279 if(op3.type) FreeType(op3.type);
6285 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
6290 OldList converts { };
6293 if(destType.kind == voidType)
6296 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
6300 // for(convert = converts.last; convert; convert = convert.prev)
6301 for(convert = converts.first; convert; convert = convert.next)
6303 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6306 Expression newExp { };
6307 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6309 // TODO: Check this...
6313 newExp.destType = null;
6318 exp.type = memberExp;
6319 exp.addedThis = true;
6320 exp.member.exp = newExp;
6321 FreeType(exp.member.exp.expType);
6323 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6324 exp.member.exp.expType.classObjectType = objectType;
6325 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6326 exp.member.memberType = propertyMember;
6327 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6328 // TESTING THIS... for (int)degrees
6329 exp.needCast = true;
6330 if(exp.expType) exp.expType.refCount++;
6331 ApplyAnyObjectLogic(exp.member.exp);
6336 /*if(exp.isConstant)
6338 // Color { ColorRGB = [exp] };
6339 exp.type = instanceExp;
6340 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6341 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6342 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6346 // If not constant, don't turn it yet into an instantiation
6347 // (Go through the deep members system first)
6348 exp.type = memberExp;
6349 exp.addedThis = true;
6350 exp.member.exp = newExp;
6352 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6353 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6354 newExp.expType._class.registered.type == noHeadClass)
6356 newExp.byReference = true;
6359 FreeType(exp.member.exp.expType);
6360 /*exp.member.exp.expType = convert.convert.dataType;
6361 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6362 exp.member.exp.expType = null;
6363 if(convert.convert.dataType)
6365 exp.member.exp.expType = { };
6366 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6367 exp.member.exp.expType.refCount = 1;
6368 exp.member.exp.expType.classObjectType = objectType;
6369 ApplyAnyObjectLogic(exp.member.exp);
6372 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6373 exp.member.memberType = reverseConversionMember;
6374 exp.expType = convert.resultType ? convert.resultType :
6375 MkClassType(convert.convert._class.fullName);
6376 exp.needCast = true;
6377 if(convert.resultType) convert.resultType.refCount++;
6383 FreeType(exp.expType);
6386 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6387 exp.needCast = true;
6388 if(exp.expType) exp.expType.refCount++;
6392 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6393 exp.needCast = true;
6394 if(convert.resultType)
6395 convert.resultType.refCount++;
6399 if(exp.isConstant && inCompiler)
6400 ComputeExpression(exp);
6402 converts.Free(FreeConvert);
6405 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6407 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6409 if(!result && exp.expType && exp.destType)
6411 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6412 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6413 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6414 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6418 // if(result) CheckTemplateTypes(exp);
6422 void CheckTemplateTypes(Expression exp)
6424 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6426 Expression newExp { };
6430 if(exp.destType) exp.destType.refCount++;
6431 if(exp.expType) exp.expType.refCount++;
6435 switch(exp.expType.kind)
6438 if(exp.destType.classObjectType)
6440 // We need to pass the address, just pass it along (Undo what was done above)
6441 if(exp.destType) exp.destType.refCount--;
6442 if(exp.expType) exp.expType.refCount--;
6447 // If we're looking for value:
6448 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6450 OldList * unionDefs = MkList();
6451 OldList * statements = MkList();
6452 context = PushContext();
6453 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6454 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6455 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6456 exp.type = extensionCompoundExp;
6457 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6458 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6459 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6460 exp.compound.compound.context = context;
6461 PopContext(context);
6466 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6467 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6471 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6473 Expression newExp { };
6477 if(exp.destType) exp.destType.refCount++;
6478 if(exp.expType) exp.expType.refCount++;
6482 switch(exp.expType.kind)
6485 if(exp.destType.classObjectType)
6487 // We need to pass the address, just pass it along (Undo what was done above)
6488 if(exp.destType) exp.destType.refCount--;
6489 if(exp.expType) exp.expType.refCount--;
6494 // If we're looking for value:
6495 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6497 OldList * unionDefs = MkList();
6498 OldList * statements = MkList();
6499 context = PushContext();
6500 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6501 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6502 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6503 exp.type = extensionCompoundExp;
6504 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6505 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6506 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6507 exp.compound.compound.context = context;
6508 PopContext(context);
6513 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6515 exp.type = bracketsExp;
6516 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6517 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6518 ProcessExpressionType(exp.list->first);
6523 exp.type = bracketsExp;
6524 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6525 newExp.needCast = true;
6526 ProcessExpressionType(exp.list->first);
6532 if(exp.expType.kind == templateType)
6534 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6537 FreeType(exp.destType);
6538 FreeType(exp.expType);
6543 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6548 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6549 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6553 char typeString[1024];
6555 OldList * specs = MkList();
6556 typeString[0] = '\0';
6557 PrintType(exp.expType, typeString, false, false);
6558 decl = SpecDeclFromString(typeString, specs, null);
6561 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6562 exp.cast.typeName = MkTypeName(specs, decl);
6563 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6564 exp.cast.exp.needCast = true;
6571 // TODO: The Symbol tree should be reorganized by namespaces
6573 // - Tree of all symbols within (stored without namespace)
6574 // - Tree of sub-namespaces
6576 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6578 int nsLen = strlen(nameSpace);
6580 // Start at the name space prefix
6581 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6583 char * s = symbol.string;
6584 if(!strncmp(s, nameSpace, nsLen))
6586 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6589 for(c = strlen(s)-1; c >= 0; c--)
6594 if(!strcmp(namePart, name))
6596 // TODO: Error on ambiguity
6606 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6609 char nameSpace[1024];
6611 bool gotColon = false;
6613 nameSpace[0] = '\0';
6614 for(c = strlen(name)-1; c >= 0; c--)
6621 namePart = name+c+1;
6622 while(c >= 0 && name[c] == ':') c--;
6625 // Try an exact match first
6626 Symbol symbol = (Symbol)tree.FindString(name);
6630 // Namespace specified
6631 memcpy(nameSpace, name, c + 1);
6634 return ScanWithNameSpace(tree, nameSpace, namePart);
6638 // Looking for a global symbol, e.g. ::Sleep()
6639 Symbol symbol = (Symbol)tree.FindString(namePart);
6644 // Name only (no namespace specified)
6645 Symbol symbol = (Symbol)tree.FindString(namePart);
6648 return ScanWithNameSpace(tree, "", namePart);
6653 static void ProcessDeclaration(Declaration decl);
6655 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6658 //Time startTime = GetTime();
6660 // Optimize this later? Do this before/less?
6662 Symbol symbol = null;
6663 // First, check if the identifier is declared inside the function
6664 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6666 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6668 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6674 strcpy(curName, thisNameSpace);
6675 strcat(curName, "::");
6676 strcat(curName, name);
6677 // Try to resolve in current namespace first
6678 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6681 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6684 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6686 if(symbol || ctx == endContext) break;
6688 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6690 if(symbol.pointerExternal.type == functionExternal)
6692 FunctionDefinition function = symbol.pointerExternal.function;
6694 // Modified this recently...
6695 Context tmpContext = curContext;
6697 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6698 curContext = tmpContext;
6700 symbol.pointerExternal.symbol = symbol;
6703 DeclareType(symbol.type, true, true);
6705 ast->Insert(curExternal.prev, symbol.pointerExternal);
6707 symbol.id = curExternal.symbol.idCode;
6710 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6712 ast->Move(symbol.pointerExternal, curExternal.prev);
6713 symbol.id = curExternal.symbol.idCode;
6717 //findSymbolTotalTime += GetTime() - startTime;
6722 static void GetTypeSpecs(Type type, OldList * specs)
6724 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6729 if(type._class.registered)
6731 if(!type._class.registered.dataType)
6732 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6733 GetTypeSpecs(type._class.registered.dataType, specs);
6737 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6738 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6739 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6740 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6741 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6742 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6743 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6744 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6747 ListAdd(specs, MkSpecifier(INT)); break;
6751 static void PrintArraySize(Type arrayType, char * string)
6756 if(arrayType.enumClass)
6757 strcat(size, arrayType.enumClass.string);
6758 else if(arrayType.arraySizeExp)
6759 PrintExpression(arrayType.arraySizeExp, size);
6761 strcat(string, size);
6764 // WARNING : This function expects a null terminated string since it recursively concatenate...
6765 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6769 if(printConst && type.constant)
6770 strcat(string, "const ");
6775 Symbol c = type._class;
6776 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6777 // look into merging with thisclass ?
6778 if(type.classObjectType == typedObject)
6779 strcat(string, "typed_object");
6780 else if(type.classObjectType == anyObject)
6781 strcat(string, "any_object");
6785 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6787 if(type.byReference)
6788 strcat(string, " &");
6791 case voidType: strcat(string, "void"); break;
6792 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6793 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6794 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6795 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6796 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6797 case _BoolType: strcat(string, "_Bool"); break;
6798 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6799 case floatType: strcat(string, "float"); break;
6800 case doubleType: strcat(string, "double"); break;
6804 strcat(string, "struct ");
6805 strcat(string, type.enumName);
6807 else if(type.typeName)
6808 strcat(string, type.typeName);
6812 strcat(string, "struct { ");
6813 for(member = type.members.first; member; member = member.next)
6815 PrintType(member, string, true, fullName);
6816 strcat(string,"; ");
6824 strcat(string, "union ");
6825 strcat(string, type.enumName);
6827 else if(type.typeName)
6828 strcat(string, type.typeName);
6831 strcat(string, "union ");
6832 strcat(string,"(unnamed)");
6838 strcat(string, "enum ");
6839 strcat(string, type.enumName);
6841 else if(type.typeName)
6842 strcat(string, type.typeName);
6844 strcat(string, "int"); // "enum");
6847 strcat(string, "...");
6850 strcat(string, "subclass(");
6851 strcat(string, type._class ? type._class.string : "int");
6852 strcat(string, ")");
6855 strcat(string, type.templateParameter.identifier.string);
6858 strcat(string, "thisclass");
6861 strcat(string, "__builtin_va_list");
6867 static void PrintName(Type type, char * string, bool fullName)
6869 if(type.name && type.name[0])
6872 strcat(string, type.name);
6875 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6876 if(name) name += 2; else name = type.name;
6877 strcat(string, name);
6882 static void PrintAttribs(Type type, char * string)
6886 if(type.dllExport) strcat(string, "dllexport ");
6887 if(type.attrStdcall) strcat(string, "stdcall ");
6891 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
6893 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6895 Type attrType = null;
6896 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
6897 PrintAttribs(type, string);
6898 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
6899 strcat(string, " const");
6900 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
6901 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6902 strcat(string, " (");
6903 if(type.kind == pointerType)
6905 if(type.type.kind == functionType || type.type.kind == methodType)
6906 PrintAttribs(type.type, string);
6908 if(type.kind == pointerType)
6910 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
6911 strcat(string, "*");
6913 strcat(string, " *");
6915 if(printConst && type.constant && type.kind == pointerType)
6916 strcat(string, " const");
6919 PrintTypeSpecs(type, string, fullName, printConst);
6922 static void PostPrintType(Type type, char * string, bool fullName)
6924 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6925 strcat(string, ")");
6926 if(type.kind == arrayType)
6927 PrintArraySize(type, string);
6928 else if(type.kind == functionType)
6931 strcat(string, "(");
6932 for(param = type.params.first; param; param = param.next)
6934 PrintType(param, string, true, fullName);
6935 if(param.next) strcat(string, ", ");
6937 strcat(string, ")");
6939 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6940 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
6944 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6946 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
6948 PrePrintType(type, string, fullName, null, printConst);
6950 if(type.thisClass || (printName && type.name && type.name[0]))
6951 strcat(string, " ");
6952 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
6954 Symbol _class = type.thisClass;
6955 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
6957 if(type.classObjectType == classPointer)
6958 strcat(string, "class");
6960 strcat(string, type.byReference ? "typed_object&" : "typed_object");
6962 else if(_class && _class.string)
6964 String s = _class.string;
6969 char * name = RSearchString(s, "::", strlen(s), true, false);
6970 if(name) name += 2; else name = s;
6971 strcat(string, name);
6974 strcat(string, "::");
6977 if(printName && type.name)
6978 PrintName(type, string, fullName);
6979 PostPrintType(type, string, fullName);
6980 if(type.bitFieldCount)
6983 sprintf(count, ":%d", type.bitFieldCount);
6984 strcat(string, count);
6988 void PrintType(Type type, char * string, bool printName, bool fullName)
6990 _PrintType(type, string, printName, fullName, true);
6993 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
6995 _PrintType(type, string, printName, fullName, false);
6998 static Type FindMember(Type type, char * string)
7001 for(memberType = type.members.first; memberType; memberType = memberType.next)
7003 if(!memberType.name)
7005 Type subType = FindMember(memberType, string);
7009 else if(!strcmp(memberType.name, string))
7015 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7018 for(memberType = type.members.first; memberType; memberType = memberType.next)
7020 if(!memberType.name)
7022 Type subType = FindMember(memberType, string);
7025 *offset += memberType.offset;
7029 else if(!strcmp(memberType.name, string))
7031 *offset += memberType.offset;
7038 public bool GetParseError() { return parseError; }
7040 Expression ParseExpressionString(char * expression)
7044 fileInput = TempFile { };
7045 fileInput.Write(expression, 1, strlen(expression));
7046 fileInput.Seek(0, start);
7049 parsedExpression = null;
7051 expression_yyparse();
7054 return parsedExpression;
7057 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7059 Identifier id = exp.identifier;
7060 Method method = null;
7061 Property prop = null;
7062 DataMember member = null;
7063 ClassProperty classProp = null;
7065 if(_class && _class.type == enumClass)
7067 NamedLink value = null;
7068 Class enumClass = eSystem_FindClass(privateModule, "enum");
7072 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7074 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7075 for(value = e.values.first; value; value = value.next)
7077 if(!strcmp(value.name, id.string))
7084 FreeExpContents(exp);
7086 exp.type = constantExp;
7087 exp.isConstant = true;
7088 if(!strcmp(baseClass.dataTypeString, "int"))
7089 sprintf(constant, "%d",(int)value.data);
7091 sprintf(constant, "0x%X",(int)value.data);
7092 exp.constant = CopyString(constant);
7093 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7094 exp.expType = MkClassType(baseClass.fullName);
7102 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7104 ProcessMethodType(method);
7111 // TOCHECK: Put it back to what it was...
7112 // methodClass = _class;
7113 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7118 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7121 ProcessPropertyType(prop);
7122 exp.expType = prop.dataType;
7123 if(prop.dataType) prop.dataType.refCount++;
7126 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7128 if(!member.dataType)
7129 member.dataType = ProcessTypeString(member.dataTypeString, false);
7130 exp.expType = member.dataType;
7131 if(member.dataType) member.dataType.refCount++;
7134 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7136 if(!classProp.dataType)
7137 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7139 if(classProp.constant)
7141 FreeExpContents(exp);
7143 exp.isConstant = true;
7144 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7146 //char constant[256];
7147 exp.type = stringExp;
7148 exp.constant = QMkString((char *)classProp.Get(_class));
7153 exp.type = constantExp;
7154 sprintf(constant, "%d", (int)classProp.Get(_class));
7155 exp.constant = CopyString(constant);
7163 exp.expType = classProp.dataType;
7164 if(classProp.dataType) classProp.dataType.refCount++;
7170 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7172 BinaryTree * tree = &nameSpace.functions;
7173 GlobalData data = (GlobalData)tree->FindString(name);
7177 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7179 data = ScanGlobalData(child, name);
7187 static GlobalData FindGlobalData(char * name)
7190 NameSpace * nameSpace;
7191 nameSpace = globalData;
7192 for(c = 0; name[c]; c++)
7194 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7196 NameSpace * newSpace;
7197 char * spaceName = new char[c - start + 1];
7198 strncpy(spaceName, name + start, c - start);
7199 spaceName[c-start] = '\0';
7200 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7204 nameSpace = newSpace;
7205 if(name[c] == ':') c++;
7211 return ScanGlobalData(nameSpace, name + start);
7216 static int definedExpStackPos;
7217 static void * definedExpStack[512];
7219 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7220 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7222 Expression prev = checkedExp.prev, next = checkedExp.next;
7224 FreeExpContents(checkedExp);
7225 FreeType(checkedExp.expType);
7226 FreeType(checkedExp.destType);
7228 *checkedExp = *newExp;
7232 checkedExp.prev = prev;
7233 checkedExp.next = next;
7236 void ApplyAnyObjectLogic(Expression e)
7238 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7240 char debugExpString[4096];
7241 debugExpString[0] = '\0';
7242 PrintExpression(e, debugExpString);
7245 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7247 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7248 //ellipsisDestType = destType;
7251 Type type = e.expType;
7252 Class _class = null;
7253 //Type destType = e.destType;
7255 if(type.kind == classType && type._class && type._class.registered)
7257 _class = type._class.registered;
7259 else if(type.kind == subClassType)
7261 _class = FindClass("ecere::com::Class").registered;
7265 char string[1024] = "";
7268 PrintTypeNoConst(type, string, false, true);
7269 classSym = FindClass(string);
7270 if(classSym) _class = classSym.registered;
7273 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...
7274 (!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))) ||
7275 destType.byReference)))
7277 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7279 Expression checkedExp = e, newExp;
7281 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7283 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7285 if(checkedExp.type == extensionCompoundExp)
7287 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7290 checkedExp = checkedExp.list->last;
7292 else if(checkedExp.type == castExp)
7293 checkedExp = checkedExp.cast.exp;
7296 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7298 newExp = checkedExp.op.exp2;
7299 checkedExp.op.exp2 = null;
7300 FreeExpContents(checkedExp);
7302 if(e.expType && e.expType.passAsTemplate)
7305 ComputeTypeSize(e.expType);
7306 sprintf(size, "%d", e.expType.size);
7307 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7308 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7309 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7312 ReplaceExpContents(checkedExp, newExp);
7313 e.byReference = true;
7315 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7317 Expression checkedExp, newExp;
7320 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7322 e.type == identifierExp ||
7323 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7324 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7325 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7328 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7330 Context context = PushContext();
7332 OldList * specs = MkList();
7333 char typeString[1024];
7334 Expression newExp { };
7336 typeString[0] = '\0';
7339 //if(e.destType) e.destType.refCount++;
7340 // if(exp.expType) exp.expType.refCount++;
7343 newExp.expType = null;
7345 PrintTypeNoConst(e.expType, typeString, false, true);
7346 decl = SpecDeclFromString(typeString, specs, null);
7347 newExp.destType = ProcessType(specs, decl);
7349 curContext = context;
7351 // We need a current compound for this
7355 OldList * stmts = MkList();
7356 e.type = extensionCompoundExp;
7357 sprintf(name, "__internalValue%03X", internalValueCounter++);
7358 if(!curCompound.compound.declarations)
7359 curCompound.compound.declarations = MkList();
7360 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7361 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7362 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7363 e.compound = MkCompoundStmt(null, stmts);
7366 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7369 e.compound = MkCompoundStmt(
7370 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7371 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7373 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7377 Type type = e.destType;
7379 CopyTypeInto(e.destType, type);
7380 e.destType.refCount = 1;
7381 e.destType.classObjectType = none;
7385 e.compound.compound.context = context;
7386 PopContext(context);
7387 curContext = context.parent;
7391 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7393 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7395 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7397 if(checkedExp.type == extensionCompoundExp)
7399 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7402 checkedExp = checkedExp.list->last;
7404 else if(checkedExp.type == castExp)
7405 checkedExp = checkedExp.cast.exp;
7408 Expression operand { };
7409 operand = *checkedExp;
7410 checkedExp.destType = null;
7411 checkedExp.expType = null;
7413 checkedExp.type = opExp;
7414 checkedExp.op.op = '&';
7415 checkedExp.op.exp1 = null;
7416 checkedExp.op.exp2 = operand;
7418 //newExp = MkExpOp(null, '&', checkedExp);
7420 //ReplaceExpContents(checkedExp, newExp);
7427 // If expression type is a simple class, make it an address
7428 // FixReference(e, true);
7431 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7432 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7433 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7435 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"))
7437 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7441 Expression thisExp { };
7444 thisExp.prev = null;
7445 thisExp.next = null;
7448 e.type = bracketsExp;
7449 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7450 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7451 ((Expression)e.list->first).byReference = true;
7453 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7455 e.expType = thisExp.expType;
7456 e.expType.refCount++;
7461 CopyTypeInto(e.expType, thisExp.expType);
7462 e.expType.byReference = false;
7463 e.expType.refCount = 1;
7465 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7466 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7468 e.expType.classObjectType = none;
7473 // TOFIX: Try this for a nice IDE crash!
7475 // The other way around
7478 if(destType && e.expType &&
7479 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7480 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7481 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7483 if(destType.kind == ellipsisType)
7485 Compiler_Error($"Unspecified type\n");
7487 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7489 bool byReference = e.expType.byReference;
7490 Expression thisExp { };
7492 OldList * specs = MkList();
7493 char typeString[1024]; // Watch buffer overruns
7495 ClassObjectType backupClassObjectType;
7496 bool backupByReference;
7498 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7503 backupClassObjectType = type.classObjectType;
7504 backupByReference = type.byReference;
7506 type.classObjectType = none;
7507 type.byReference = false;
7509 typeString[0] = '\0';
7510 PrintType(type, typeString, false, true);
7511 decl = SpecDeclFromString(typeString, specs, null);
7513 type.classObjectType = backupClassObjectType;
7514 type.byReference = backupByReference;
7517 thisExp.prev = null;
7518 thisExp.next = null;
7521 if( ( type.kind == classType && type._class && type._class.registered &&
7522 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7523 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7524 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7525 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7530 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7533 CopyTypeInto(e.expType, type);
7534 e.expType.byReference = false;
7535 e.expType.refCount = 1;
7540 e.cast.typeName = MkTypeName(specs, decl);
7541 e.cast.exp = thisExp;
7542 e.byReference = true;
7546 e.destType = destType;
7547 destType.refCount++;
7552 void ProcessExpressionType(Expression exp)
7554 bool unresolved = false;
7555 Location oldyylloc = yylloc;
7556 bool notByReference = false;
7558 char debugExpString[4096];
7559 debugExpString[0] = '\0';
7560 PrintExpression(exp, debugExpString);
7562 if(!exp || exp.expType)
7565 //eSystem_Logf("%s\n", expString);
7567 // Testing this here
7573 Identifier id = exp.identifier;
7574 if(!id || !topContext) return;
7576 // DOING THIS LATER NOW...
7577 if(id._class && id._class.name)
7579 id.classSym = id._class.symbol; // FindClass(id._class.name);
7580 /* TODO: Name Space Fix ups
7582 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7586 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7588 exp.expType = ProcessTypeString("Module", true);
7591 else */if(strstr(id.string, "__ecereClass") == id.string)
7593 exp.expType = ProcessTypeString("ecere::com::Class", true);
7596 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7598 // Added this here as well
7599 ReplaceClassMembers(exp, thisClass);
7600 if(exp.type != identifierExp)
7602 ProcessExpressionType(exp);
7606 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7611 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7612 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7613 if(!symbol/* && exp.destType*/)
7615 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7621 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7622 if(exp.type != identifierExp)
7624 ProcessExpressionType(exp);
7628 // Static methods called from inside the _class
7629 else if(currentClass && !id._class)
7631 if(ResolveIdWithClass(exp, currentClass, true))
7634 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7638 // If we manage to resolve this symbol
7641 Type type = symbol.type;
7642 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7644 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7646 Context context = SetupTemplatesContext(_class);
7647 type = ReplaceThisClassType(_class);
7648 FinishTemplatesContext(context);
7649 if(type) type.refCount = 0; // We'll be incrementing it right below...
7652 FreeSpecifier(id._class);
7655 id.string = CopyString(symbol.string);
7662 // Commented this out, it was making non-constant enum parameters seen as constant
7663 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7664 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7665 // Add missing cases here... enum Classes...
7666 exp.isConstant = true;
7668 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7669 if(symbol.isParam || !strcmp(id.string, "this"))
7671 if(_class && _class.type == structClass && !type.declaredWithStruct)
7672 exp.byReference = true;
7674 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7675 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7676 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7677 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7679 Identifier id = exp.identifier;
7680 exp.type = bracketsExp;
7681 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7685 if(symbol.isIterator)
7687 if(symbol.isIterator == 3)
7689 exp.type = bracketsExp;
7690 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7691 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7693 ProcessExpressionType(exp);
7695 else if(symbol.isIterator != 4)
7697 exp.type = memberExp;
7698 exp.member.exp = MkExpIdentifier(exp.identifier);
7699 exp.member.exp.expType = exp.expType;
7700 /*if(symbol.isIterator == 6)
7701 exp.member.member = MkIdentifier("key");
7703 exp.member.member = MkIdentifier("data");
7705 ProcessExpressionType(exp);
7712 DefinedExpression definedExp = null;
7713 if(thisNameSpace && !(id._class && !id._class.name))
7716 strcpy(name, thisNameSpace);
7718 strcat(name, id.string);
7719 definedExp = eSystem_FindDefine(privateModule, name);
7722 definedExp = eSystem_FindDefine(privateModule, id.string);
7726 for(c = 0; c<definedExpStackPos; c++)
7727 if(definedExpStack[c] == definedExp)
7729 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7731 Location backupYylloc = yylloc;
7732 File backInput = fileInput;
7733 definedExpStack[definedExpStackPos++] = definedExp;
7735 fileInput = TempFile { };
7736 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7737 fileInput.Seek(0, start);
7740 parsedExpression = null;
7742 expression_yyparse();
7745 fileInput = backInput;
7747 yylloc = backupYylloc;
7749 if(parsedExpression)
7752 exp.type = bracketsExp;
7753 exp.list = MkListOne(parsedExpression);
7754 parsedExpression.loc = yylloc;
7755 ProcessExpressionType(exp);
7756 definedExpStackPos--;
7759 definedExpStackPos--;
7765 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7771 GlobalData data = null;
7772 if(thisNameSpace && !(id._class && !id._class.name))
7775 strcpy(name, thisNameSpace);
7777 strcat(name, id.string);
7778 data = FindGlobalData(name);
7781 data = FindGlobalData(id.string);
7784 DeclareGlobalData(data);
7785 exp.expType = data.dataType;
7786 if(data.dataType) data.dataType.refCount++;
7789 id.string = CopyString(data.fullName);
7790 FreeSpecifier(id._class);
7797 GlobalFunction function = null;
7798 if(thisNameSpace && !(id._class && !id._class.name))
7801 strcpy(name, thisNameSpace);
7803 strcat(name, id.string);
7804 function = eSystem_FindFunction(privateModule, name);
7807 function = eSystem_FindFunction(privateModule, id.string);
7812 id.string = CopyString(function.name);
7815 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7816 strcpy(name, "__ecereFunction_");
7817 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7818 if(DeclareFunction(function, name))
7821 id.string = CopyString(name);
7823 exp.expType = function.dataType;
7824 if(function.dataType) function.dataType.refCount++;
7826 FreeSpecifier(id._class);
7843 if(!exp.instance._class)
7845 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7847 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7851 //classSym = FindClass(exp.instance._class.fullName);
7852 //_class = classSym ? classSym.registered : null;
7854 ProcessInstantiationType(exp.instance);
7855 exp.isConstant = exp.instance.isConstant;
7858 if(_class.type == unitClass && _class.base.type != systemClass)
7861 Type destType = exp.destType;
7863 exp.destType = MkClassType(_class.base.fullName);
7864 exp.expType = MkClassType(_class.fullName);
7865 CheckExpressionType(exp, exp.destType, true);
7867 exp.destType = destType;
7869 exp.expType = MkClassType(_class.fullName);
7872 if(exp.instance._class)
7874 exp.expType = MkClassType(exp.instance._class.name);
7875 /*if(exp.expType._class && exp.expType._class.registered &&
7876 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7877 exp.expType.byReference = true;*/
7885 char * constant = exp.constant;
7893 if(constant[0] == '\'')
7895 if((int)((byte *)constant)[1] > 127)
7898 unichar ch = UTF8GetChar(constant + 1, &nb);
7899 if(nb < 2) ch = constant[1];
7901 exp.constant = PrintUInt(ch);
7902 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7903 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7904 type._class = FindClass("unichar");
7906 type.isSigned = false;
7910 type.kind = charType;
7911 type.isSigned = true;
7916 char * dot = strchr(constant, '.');
7917 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
7921 exponent = strchr(constant, 'p');
7922 if(!exponent) exponent = strchr(constant, 'P');
7926 exponent = strchr(constant, 'e');
7927 if(!exponent) exponent = strchr(constant, 'E');
7932 if(strchr(constant, 'f') || strchr(constant, 'F'))
7933 type.kind = floatType;
7935 type.kind = doubleType;
7936 type.isSigned = true;
7940 bool isSigned = constant[0] == '-';
7942 int64 i64 = strtoll(constant, &endP, 0);
7943 uint64 ui64 = strtoull(constant, &endP, 0);
7944 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
7957 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
7961 else if(constant[0] != '0' || !constant[1])
7964 type.kind = is64Bit ? int64Type : intType;
7965 type.isSigned = isSigned;
7968 exp.isConstant = true;
7969 if(exp.destType && exp.destType.kind == doubleType)
7970 type.kind = doubleType;
7971 else if(exp.destType && exp.destType.kind == floatType)
7972 type.kind = floatType;
7973 else if(exp.destType && exp.destType.kind == int64Type)
7974 type.kind = int64Type;
7980 exp.isConstant = true; // Why wasn't this constant?
7997 ProcessExpressionType(exp._new.size);
8002 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8004 DeclareType(exp.expType.type, false, false);
8008 ProcessExpressionType(exp._renew.size);
8009 ProcessExpressionType(exp._renew.exp);
8014 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8016 DeclareType(exp.expType.type, false, false);
8020 bool assign = false, boolResult = false, boolOps = false;
8021 Type type1 = null, type2 = null;
8022 bool useDestType = false, useSideType = false;
8023 Location oldyylloc = yylloc;
8024 bool useSideUnit = false;
8025 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8027 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8036 // Assignment Operators
8050 // boolean Operators
8052 // Expect boolean operators
8054 //boolResult = true;
8058 // Expect boolean operands
8069 // Gives boolean result
8101 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8107 /*// Implement speed etc.
8113 if(exp.op.op == '&')
8115 // Added this here earlier for Iterator address as key
8116 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8118 Identifier id = exp.op.exp2.identifier;
8119 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8120 if(symbol && symbol.isIterator == 2)
8122 exp.type = memberExp;
8123 exp.member.exp = exp.op.exp2;
8124 exp.member.member = MkIdentifier("key");
8126 exp.op.exp2.expType = symbol.type;
8127 symbol.type.refCount++;
8128 ProcessExpressionType(exp);
8132 // exp.op.exp2.usage.usageRef = true;
8136 //dummy.kind = TypeDummy;
8139 // Added this check here to use the dest type only for units derived from the base unit
8140 // So that untyped units will use the side unit as opposed to the untyped destination unit
8141 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8142 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8143 useDestType = false;
8145 if(destClass && useDestType &&
8146 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8148 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8150 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8151 exp.op.exp1.destType = exp.destType;
8152 exp.op.exp1.opDestType = true;
8154 exp.destType.refCount++;
8158 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8159 exp.op.exp1.destType = dummy;
8163 // TESTING THIS HERE...
8164 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8165 ProcessExpressionType(exp.op.exp1);
8166 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8168 exp.op.exp1.opDestType = false;
8170 // Fix for unit and ++ / --
8171 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8172 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8174 exp.op.exp2 = MkExpConstant("1");
8175 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8179 if(exp.op.exp1.destType == dummy)
8182 exp.op.exp1.destType = null;
8184 type1 = exp.op.exp1.expType;
8189 char expString[10240];
8190 expString[0] = '\0';
8191 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8195 exp.op.exp2.destType = exp.op.exp1.expType;
8196 if(exp.op.exp1.expType)
8197 exp.op.exp1.expType.refCount++;
8201 exp.op.exp2.destType = exp.destType;
8202 if(!exp.op.exp1 || exp.op.op != '&')
8203 exp.op.exp2.opDestType = true;
8205 exp.destType.refCount++;
8208 if(type1) type1.refCount++;
8209 exp.expType = type1;
8214 PrintExpression(exp.op.exp2, expString);
8216 if(type1 && type1.kind == pointerType)
8218 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 ||
8219 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8220 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8221 else if(exp.op.op == '=')
8223 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8224 exp.op.exp2.destType = type1;
8231 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8232 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/* ||
8233 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8236 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8237 exp.op.exp2.destType = type1;
8242 if(type1) type1.refCount++;
8243 exp.expType = type1;
8245 else if(destClass &&
8246 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8247 (destClass.type == enumClass && useDestType)))
8249 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8250 exp.op.exp2.destType = exp.destType;
8251 if(exp.op.op != '&')
8252 exp.op.exp2.opDestType = true;
8254 exp.destType.refCount++;
8258 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8259 exp.op.exp2.destType = dummy;
8263 // TESTING THIS HERE... (DANGEROUS)
8264 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8265 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8267 FreeType(exp.op.exp2.destType);
8268 exp.op.exp2.destType = type1;
8271 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8272 // Cannot lose the cast on a sizeof
8273 if(exp.op.op == SIZEOF)
8275 Expression e = exp.op.exp2;
8276 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8278 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8280 if(e.type == extensionCompoundExp)
8281 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8286 if(e.type == castExp && e.cast.exp)
8287 e.cast.exp.needCast = true;
8289 ProcessExpressionType(exp.op.exp2);
8290 exp.op.exp2.opDestType = false;
8291 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8293 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8295 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)
8297 if(exp.op.op != '=' && type1.type.kind == voidType)
8298 Compiler_Error($"void *: unknown size\n");
8300 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||
8301 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8302 (exp.op.exp2.expType._class.registered.type == normalClass ||
8303 exp.op.exp2.expType._class.registered.type == structClass ||
8304 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8306 if(exp.op.op == ADD_ASSIGN)
8307 Compiler_Error($"cannot add two pointers\n");
8309 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8310 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8312 if(exp.op.op == ADD_ASSIGN)
8313 Compiler_Error($"cannot add two pointers\n");
8317 char type1String[1024];
8318 char type2String[1024];
8319 type1String[0] = '\0';
8320 type2String[0] = '\0';
8322 PrintType(exp.op.exp2.expType, type1String, false, true);
8323 PrintType(type1, type2String, false, true);
8324 ChangeCh(expString, '\n', ' ');
8325 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8329 if(exp.op.exp2.destType == dummy)
8332 exp.op.exp2.destType = null;
8335 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8339 CopyTypeInto(type2, exp.op.exp2.expType);
8340 type2.isSigned = true;
8342 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8344 type2 = { kind = intType };
8346 type2.isSigned = true;
8350 type2 = exp.op.exp2.expType;
8351 if(type2) type2.refCount++;
8355 dummy.kind = voidType;
8357 if(exp.op.op == SIZEOF)
8364 exp.isConstant = true;
8366 // Get type of dereferenced pointer
8367 else if(exp.op.op == '*' && !exp.op.exp1)
8369 exp.expType = Dereference(type2);
8370 if(type2 && type2.kind == classType)
8371 notByReference = true;
8373 else if(exp.op.op == '&' && !exp.op.exp1)
8374 exp.expType = Reference(type2);
8381 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8382 exp.op.exp1.destType = MkClassType("bool");
8383 exp.op.exp1.destType.truth = true;
8384 if(!exp.op.exp1.expType)
8385 ProcessExpressionType(exp.op.exp1);
8387 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8388 FreeType(exp.op.exp1.expType);
8389 exp.op.exp1.expType = MkClassType("bool");
8390 exp.op.exp1.expType.truth = true;
8394 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8395 exp.op.exp2.destType = MkClassType("bool");
8396 exp.op.exp2.destType.truth = true;
8397 if(!exp.op.exp2.expType)
8398 ProcessExpressionType(exp.op.exp2);
8400 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8401 FreeType(exp.op.exp2.expType);
8402 exp.op.exp2.expType = MkClassType("bool");
8403 exp.op.exp2.expType.truth = true;
8406 else if(exp.op.exp1 && exp.op.exp2 &&
8409 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8410 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8411 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8412 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8414 if(type1 && type2 &&
8415 // If either both are class or both are not class
8416 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8418 // Added this check for enum subtraction to result in an int type:
8419 if(exp.op.op == '-' &&
8420 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8421 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8424 if(!type1._class.registered.dataType)
8425 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8426 if(!type2._class.registered.dataType)
8427 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8429 intType = ProcessTypeString(
8430 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8432 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8433 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8434 exp.op.exp1.destType = intType;
8435 exp.op.exp2.destType = intType;
8440 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8441 exp.op.exp2.destType = type1;
8443 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8444 exp.op.exp1.destType = type2;
8448 // Warning here for adding Radians + Degrees with no destination type
8449 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8450 type1._class.registered && type1._class.registered.type == unitClass &&
8451 type2._class.registered && type2._class.registered.type == unitClass &&
8452 type1._class.registered != type2._class.registered)
8453 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8454 type1._class.string, type2._class.string, type1._class.string);
8456 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8458 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8461 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8463 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8464 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8467 ProcessExpressionType(exp.op.exp1);
8469 if(type2.kind != pointerType)
8471 ProcessExpressionType(classExp);
8473 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8474 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8475 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8477 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8480 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8481 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8482 MkPointer(null, null), null)))),
8483 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8485 if(!exp.op.exp2.expType)
8489 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8493 ProcessExpressionType(exp.op.exp2);
8498 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)))
8500 if(type1.kind != classType && type1.type.kind == voidType)
8501 Compiler_Error($"void *: unknown size\n");
8502 exp.expType = type1;
8503 if(type1) type1.refCount++;
8505 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)))
8507 if(type2.kind != classType && type2.type.kind == voidType)
8508 Compiler_Error($"void *: unknown size\n");
8509 exp.expType = type2;
8510 if(type2) type2.refCount++;
8512 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8513 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8515 Compiler_Warning($"different levels of indirection\n");
8519 bool success = false;
8520 if(type1.kind == pointerType && type2.kind == pointerType)
8522 if(exp.op.op == '+')
8523 Compiler_Error($"cannot add two pointers\n");
8524 else if(exp.op.op == '-')
8526 // Pointer Subtraction gives integer
8527 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8536 if(type1.type.kind == templateType)
8538 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8541 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8543 ProcessExpressionType(classExp);
8545 exp.type = bracketsExp;
8546 exp.list = MkListOne(MkExpOp(
8547 MkExpBrackets(MkListOne(MkExpOp(
8548 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8550 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8552 //MkExpMember(classExp, MkIdentifier("typeSize"))
8554 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8555 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8557 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8560 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8561 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8562 MkPointer(null, null), null)))),
8563 MkExpMember(classExp, MkIdentifier("typeSize")))))
8568 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8577 if(!success && exp.op.exp1.type == constantExp)
8579 // If first expression is constant, try to match that first
8580 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8582 if(exp.expType) FreeType(exp.expType);
8583 exp.expType = exp.op.exp1.destType;
8584 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8587 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8589 if(exp.expType) FreeType(exp.expType);
8590 exp.expType = exp.op.exp2.destType;
8591 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8597 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8599 if(exp.expType) FreeType(exp.expType);
8600 exp.expType = exp.op.exp2.destType;
8601 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8604 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8606 if(exp.expType) FreeType(exp.expType);
8607 exp.expType = exp.op.exp1.destType;
8608 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8614 char expString1[10240];
8615 char expString2[10240];
8618 expString1[0] = '\0';
8619 expString2[0] = '\0';
8624 PrintExpression(exp.op.exp1, expString1);
8625 ChangeCh(expString1, '\n', ' ');
8626 PrintExpression(exp.op.exp2, expString2);
8627 ChangeCh(expString2, '\n', ' ');
8628 PrintType(exp.op.exp1.expType, type1, false, true);
8629 PrintType(exp.op.exp2.expType, type2, false, true);
8632 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8636 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8637 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8639 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8640 // Convert e.g. / 4 into / 4.0
8641 exp.op.exp1.destType = type2._class.registered.dataType;
8642 if(type2._class.registered.dataType)
8643 type2._class.registered.dataType.refCount++;
8644 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8645 exp.expType = type2;
8646 if(type2) type2.refCount++;
8648 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8650 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8651 // Convert e.g. / 4 into / 4.0
8652 exp.op.exp2.destType = type1._class.registered.dataType;
8653 if(type1._class.registered.dataType)
8654 type1._class.registered.dataType.refCount++;
8655 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8656 exp.expType = type1;
8657 if(type1) type1.refCount++;
8663 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8665 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8667 if(!type1._class.registered.dataType)
8668 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8669 exp.op.exp2.destType = type1._class.registered.dataType;
8670 exp.op.exp2.destType.refCount++;
8672 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8675 type2 = exp.op.exp2.destType;
8676 if(type2) type2.refCount++;
8678 exp.expType = type2;
8682 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8684 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8686 if(!type2._class.registered.dataType)
8687 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8688 exp.op.exp1.destType = type2._class.registered.dataType;
8689 exp.op.exp1.destType.refCount++;
8691 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8692 type1 = exp.op.exp1.destType;
8693 exp.expType = type1;
8697 // TESTING THIS NEW CODE
8698 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8700 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8701 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8702 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8704 // Convert the enum to an int instead for these operators
8705 if(op1IsEnum && exp.op.exp2.expType)
8707 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8709 if(exp.expType) FreeType(exp.expType);
8710 exp.expType = exp.op.exp2.expType;
8711 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8715 else if(op2IsEnum && exp.op.exp1.expType)
8717 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8719 if(exp.expType) FreeType(exp.expType);
8720 exp.expType = exp.op.exp1.expType;
8721 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8728 if(op1IsEnum && exp.op.exp2.expType)
8730 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8732 if(exp.expType) FreeType(exp.expType);
8733 exp.expType = exp.op.exp1.expType;
8734 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8738 else if(op2IsEnum && exp.op.exp1.expType)
8740 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8742 if(exp.expType) FreeType(exp.expType);
8743 exp.expType = exp.op.exp2.expType;
8744 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8753 // 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
8754 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8755 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8757 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8758 exp.op.exp1.destType = type2;
8761 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8763 if(exp.expType) FreeType(exp.expType);
8764 exp.expType = exp.op.exp1.destType;
8765 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8770 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8771 exp.op.exp2.destType = type1;
8775 // Maybe this was meant to be an enum...
8776 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8778 Type oldType = exp.op.exp2.expType;
8779 exp.op.exp2.expType = null;
8780 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8783 exp.op.exp2.expType = oldType;
8788 // TESTING THIS HERE... LATEST ADDITION
8789 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8791 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8792 exp.op.exp2.destType = type2._class.registered.dataType;
8793 if(type2._class.registered.dataType)
8794 type2._class.registered.dataType.refCount++;
8795 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8797 //exp.expType = type2._class.registered.dataType; //type2;
8798 //if(type2) type2.refCount++;
8801 // TESTING THIS HERE... LATEST ADDITION
8802 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8804 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8805 exp.op.exp1.destType = type1._class.registered.dataType;
8806 if(type1._class.registered.dataType)
8807 type1._class.registered.dataType.refCount++;
8808 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8809 exp.expType = type1._class.registered.dataType; //type1;
8810 if(type1) type1.refCount++;
8814 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8816 if(exp.expType) FreeType(exp.expType);
8817 exp.expType = exp.op.exp2.destType;
8818 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8820 else if(type1 && type2)
8822 char expString1[10240];
8823 char expString2[10240];
8824 char type1String[1024];
8825 char type2String[1024];
8826 expString1[0] = '\0';
8827 expString2[0] = '\0';
8828 type1String[0] = '\0';
8829 type2String[0] = '\0';
8832 PrintExpression(exp.op.exp1, expString1);
8833 ChangeCh(expString1, '\n', ' ');
8834 PrintExpression(exp.op.exp2, expString2);
8835 ChangeCh(expString2, '\n', ' ');
8836 PrintType(exp.op.exp1.expType, type1String, false, true);
8837 PrintType(exp.op.exp2.expType, type2String, false, true);
8840 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8842 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8844 exp.expType = exp.op.exp1.expType;
8845 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8847 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8849 exp.expType = exp.op.exp2.expType;
8850 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8858 // Maybe this was meant to be an enum...
8859 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8861 Type oldType = exp.op.exp1.expType;
8862 exp.op.exp1.expType = null;
8863 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8866 exp.op.exp1.expType = oldType;
8869 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8870 exp.op.exp1.destType = type2;
8873 // TESTING THIS HERE... LATEST ADDITION
8874 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8876 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8877 exp.op.exp1.destType = type1._class.registered.dataType;
8878 if(type1._class.registered.dataType)
8879 type1._class.registered.dataType.refCount++;
8882 // TESTING THIS HERE... LATEST ADDITION
8883 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8885 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8886 exp.op.exp2.destType = type2._class.registered.dataType;
8887 if(type2._class.registered.dataType)
8888 type2._class.registered.dataType.refCount++;
8892 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8894 if(exp.expType) FreeType(exp.expType);
8895 exp.expType = exp.op.exp1.destType;
8896 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8900 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8902 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8904 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8905 // Convert e.g. / 4 into / 4.0
8906 exp.op.exp1.destType = type2._class.registered.dataType;
8907 if(type2._class.registered.dataType)
8908 type2._class.registered.dataType.refCount++;
8909 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8911 if(exp.op.op == '!')
8913 exp.expType = MkClassType("bool");
8914 exp.expType.truth = true;
8918 exp.expType = type2;
8919 if(type2) type2.refCount++;
8922 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8924 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8926 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8927 // Convert e.g. / 4 into / 4.0
8928 exp.op.exp2.destType = type1._class.registered.dataType;
8929 if(type1._class.registered.dataType)
8930 type1._class.registered.dataType.refCount++;
8931 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8933 exp.expType = type1;
8934 if(type1) type1.refCount++;
8939 if(exp.op.exp1 && !exp.op.exp1.expType)
8941 char expString[10000];
8942 expString[0] = '\0';
8945 PrintExpression(exp.op.exp1, expString);
8946 ChangeCh(expString, '\n', ' ');
8949 Compiler_Error($"couldn't determine type of %s\n", expString);
8951 if(exp.op.exp2 && !exp.op.exp2.expType)
8953 char expString[10240];
8954 expString[0] = '\0';
8957 PrintExpression(exp.op.exp2, expString);
8958 ChangeCh(expString, '\n', ' ');
8961 Compiler_Error($"couldn't determine type of %s\n", expString);
8966 FreeType(exp.expType);
8967 exp.expType = MkClassType("bool");
8968 exp.expType.truth = true;
8971 if(exp.op.op != SIZEOF)
8972 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8973 (!exp.op.exp2 || exp.op.exp2.isConstant);
8975 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8977 DeclareType(exp.op.exp2.expType, false, false);
8988 case extensionExpressionExp:
8991 exp.isConstant = true;
8992 for(e = exp.list->first; e; e = e.next)
8997 FreeType(e.destType);
8998 e.opDestType = exp.opDestType;
8999 e.destType = exp.destType;
9000 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
9002 ProcessExpressionType(e);
9004 exp.destType.count--;
9005 if(!exp.expType && !e.next)
9007 exp.expType = e.expType;
9008 if(e.expType) e.expType.refCount++;
9011 exp.isConstant = false;
9014 // In case a cast became a member...
9015 e = exp.list->first;
9016 if(!e.next && e.type == memberExp)
9018 // Preserve prev, next
9019 Expression next = exp.next, prev = exp.prev;
9022 FreeType(exp.expType);
9023 FreeType(exp.destType);
9033 ProcessExpressionType(exp);
9040 exp.isConstant = true;
9042 ProcessExpressionType(exp.index.exp);
9043 if(!exp.index.exp.isConstant)
9044 exp.isConstant = false;
9046 if(exp.index.exp.expType)
9048 Type source = exp.index.exp.expType;
9049 if(source.kind == classType && source._class && source._class.registered)
9051 Class _class = source._class.registered;
9052 Class c = _class.templateClass ? _class.templateClass : _class;
9053 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9055 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9057 if(exp.index.index && exp.index.index->last)
9059 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9065 for(e = exp.index.index->first; e; e = e.next)
9067 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9069 if(e.destType) FreeType(e.destType);
9070 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9072 ProcessExpressionType(e);
9075 // Check if this type is int
9078 exp.isConstant = false;
9082 exp.expType = Dereference(exp.index.exp.expType);
9084 DeclareType(exp.expType, false, false);
9091 Type methodType = null;
9097 PrintExpression(exp.call.exp, name);
9098 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9100 //exp.call.exp.expType = null;
9101 PrintExpression(exp.call.exp, name);
9104 if(exp.call.exp.type == identifierExp)
9106 Expression idExp = exp.call.exp;
9107 Identifier id = idExp.identifier;
9108 if(!strcmp(id.string, "__builtin_frame_address"))
9110 exp.expType = ProcessTypeString("void *", true);
9111 if(exp.call.arguments && exp.call.arguments->first)
9112 ProcessExpressionType(exp.call.arguments->first);
9115 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9117 exp.expType = ProcessTypeString("int", true);
9118 if(exp.call.arguments && exp.call.arguments->first)
9119 ProcessExpressionType(exp.call.arguments->first);
9122 else if(!strcmp(id.string, "Max") ||
9123 !strcmp(id.string, "Min") ||
9124 !strcmp(id.string, "Sgn") ||
9125 !strcmp(id.string, "Abs"))
9127 Expression a = null;
9128 Expression b = null;
9129 Expression tempExp1 = null, tempExp2 = null;
9130 if((!strcmp(id.string, "Max") ||
9131 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9133 a = exp.call.arguments->first;
9134 b = exp.call.arguments->last;
9138 else if(exp.call.arguments->count == 1)
9140 a = exp.call.arguments->first;
9146 exp.call.arguments->Clear();
9147 idExp.identifier = null;
9149 FreeExpContents(exp);
9151 ProcessExpressionType(a);
9153 ProcessExpressionType(b);
9155 exp.type = bracketsExp;
9156 exp.list = MkList();
9158 if(a.expType && (!b || b.expType))
9160 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9162 // Use the simpleStruct name/ids for now...
9165 OldList * specs = MkList();
9166 OldList * decls = MkList();
9168 char temp1[1024], temp2[1024];
9170 GetTypeSpecs(a.expType, specs);
9172 if(a && !a.isConstant && a.type != identifierExp)
9174 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9175 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9176 tempExp1 = QMkExpId(temp1);
9177 tempExp1.expType = a.expType;
9179 a.expType.refCount++;
9180 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9182 if(b && !b.isConstant && b.type != identifierExp)
9184 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9185 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9186 tempExp2 = QMkExpId(temp2);
9187 tempExp2.expType = b.expType;
9189 b.expType.refCount++;
9190 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9193 decl = MkDeclaration(specs, decls);
9194 if(!curCompound.compound.declarations)
9195 curCompound.compound.declarations = MkList();
9196 curCompound.compound.declarations->Insert(null, decl);
9201 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9203 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9205 MkExpCondition(MkExpBrackets(MkListOne(
9206 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9207 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9208 exp.expType = a.expType;
9210 a.expType.refCount++;
9212 else if(!strcmp(id.string, "Abs"))
9215 MkExpCondition(MkExpBrackets(MkListOne(
9216 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9217 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9218 exp.expType = a.expType;
9220 a.expType.refCount++;
9222 else if(!strcmp(id.string, "Sgn"))
9224 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9226 MkExpCondition(MkExpBrackets(MkListOne(
9227 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9228 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9229 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9230 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9231 exp.expType = ProcessTypeString("int", false);
9234 FreeExpression(tempExp1);
9235 if(tempExp2) FreeExpression(tempExp2);
9249 if(!exp.call.exp.destType)
9251 exp.call.exp.destType = dummy;
9254 ProcessExpressionType(exp.call.exp);
9255 if(exp.call.exp.destType == dummy)
9258 exp.call.exp.destType = null;
9263 // Check argument types against parameter types
9264 functionType = exp.call.exp.expType;
9266 if(functionType && functionType.kind == TypeKind::methodType)
9268 methodType = functionType;
9269 functionType = methodType.method.dataType;
9271 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9272 // TOCHECK: Instead of doing this here could this be done per param?
9273 if(exp.call.exp.expType.usedClass)
9275 char typeString[1024];
9276 typeString[0] = '\0';
9278 Symbol back = functionType.thisClass;
9279 // Do not output class specifier here (thisclass was added to this)
9280 functionType.thisClass = null;
9281 PrintType(functionType, typeString, true, true);
9282 functionType.thisClass = back;
9284 if(strstr(typeString, "thisclass"))
9286 OldList * specs = MkList();
9289 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9291 decl = SpecDeclFromString(typeString, specs, null);
9293 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9294 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9295 exp.call.exp.expType.usedClass))
9296 thisClassParams = false;
9298 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9300 Class backupThisClass = thisClass;
9301 thisClass = exp.call.exp.expType.usedClass;
9302 ProcessDeclarator(decl);
9303 thisClass = backupThisClass;
9306 thisClassParams = true;
9308 functionType = ProcessType(specs, decl);
9309 functionType.refCount = 0;
9310 FinishTemplatesContext(context);
9313 FreeList(specs, FreeSpecifier);
9314 FreeDeclarator(decl);
9318 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9320 Type type = functionType.type;
9321 if(!functionType.refCount)
9323 functionType.type = null;
9324 FreeType(functionType);
9326 //methodType = functionType;
9327 functionType = type;
9329 if(functionType && functionType.kind != TypeKind::functionType)
9331 Compiler_Error($"called object %s is not a function\n", name);
9333 else if(functionType)
9335 bool emptyParams = false, noParams = false;
9336 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9337 Type type = functionType.params.first;
9338 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9340 Location oldyylloc = yylloc;
9342 if(!type) emptyParams = true;
9345 if(functionType.extraParam && e && functionType.thisClass)
9347 e.destType = MkClassType(functionType.thisClass.string);
9351 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9352 // Fixed #141 by adding '&& !functionType.extraParam'
9353 if(!functionType.staticMethod && !functionType.extraParam)
9355 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9356 memberExp.member.exp.expType._class)
9358 type = MkClassType(memberExp.member.exp.expType._class.string);
9363 type = functionType.params.first;
9368 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9370 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9371 type.byReference = functionType.byReference;
9372 type.typedByReference = functionType.typedByReference;
9375 // Allow manually passing a class for typed object
9376 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9380 type = functionType.params.first;
9388 if(type && type.kind == voidType)
9391 if(!type.refCount) FreeType(type);
9395 for( ; e; e = e.next)
9397 if(!type && !emptyParams)
9400 if(methodType && methodType.methodClass)
9401 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9402 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9403 noParams ? 0 : functionType.params.count);
9405 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9406 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9407 noParams ? 0 : functionType.params.count);
9411 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9413 Type templatedType = null;
9414 Class _class = methodType.usedClass;
9415 ClassTemplateParameter curParam = null;
9417 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9420 for(sClass = _class; sClass; sClass = sClass.base)
9422 if(sClass.templateClass) sClass = sClass.templateClass;
9424 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9426 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9429 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9431 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9432 id += nextClass.templateParams.count;
9441 if(curParam && _class.templateArgs[id].dataTypeString)
9443 ClassTemplateArgument arg = _class.templateArgs[id];
9445 Context context = SetupTemplatesContext(_class);
9448 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9449 templatedType = ProcessTypeString(arg.dataTypeString, false);
9450 FinishTemplatesContext(context);
9452 e.destType = templatedType;
9455 templatedType.passAsTemplate = true;
9456 // templatedType.refCount++;
9462 if(type) type.refCount++;
9467 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9469 e.destType = type.prev;
9470 e.destType.refCount++;
9475 if(type) type.refCount++;
9478 // Don't reach the end for the ellipsis
9479 if(type && type.kind != ellipsisType)
9481 Type next = type.next;
9482 if(!type.refCount) FreeType(type);
9487 if(type && type.kind != ellipsisType)
9489 if(methodType && methodType.methodClass)
9490 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9491 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9492 functionType.params.count + extra);
9494 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9495 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9496 functionType.params.count + extra);
9499 if(type && !type.refCount) FreeType(type);
9506 kind = TypeKind::functionType;
9509 if(exp.call.exp.type == identifierExp)
9511 char * string = exp.call.exp.identifier.string;
9515 Location oldyylloc = yylloc;
9517 yylloc = exp.call.exp.identifier.loc;
9518 if(strstr(string, "__builtin_") == string)
9522 functionType.returnType = exp.destType;
9523 exp.destType.refCount++;
9527 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9528 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9529 globalContext.symbols.Add((BTNode)symbol);
9530 if(strstr(symbol.string, "::"))
9531 globalContext.hasNameSpace = true;
9536 else if(exp.call.exp.type == memberExp)
9538 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9539 exp.call.exp.member.member.string);*/
9542 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9544 if(!functionType.returnType)
9546 functionType.returnType = Type
9553 if(functionType && functionType.kind == TypeKind::functionType)
9555 exp.expType = functionType.returnType;
9557 if(functionType.returnType)
9558 functionType.returnType.refCount++;
9560 if(!functionType.refCount)
9561 FreeType(functionType);
9564 if(exp.call.arguments)
9566 for(e = exp.call.arguments->first; e; e = e.next)
9568 Type destType = e.destType;
9569 ProcessExpressionType(e);
9577 Location oldyylloc = yylloc;
9579 Expression checkExp = exp.member.exp;
9582 if(checkExp.type == castExp)
9583 checkExp = checkExp.cast.exp;
9584 else if(checkExp.type == bracketsExp)
9585 checkExp = checkExp.list ? checkExp.list->first : null;
9590 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9591 exp.thisPtr = thisPtr;
9593 // DOING THIS LATER NOW...
9594 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9596 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9597 /* TODO: Name Space Fix ups
9598 if(!exp.member.member.classSym)
9599 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9603 ProcessExpressionType(exp.member.exp);
9604 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9605 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9607 exp.isConstant = false;
9610 exp.isConstant = exp.member.exp.isConstant;
9611 type = exp.member.exp.expType;
9615 if(type && (type.kind == templateType))
9617 Class _class = thisClass ? thisClass : currentClass;
9618 ClassTemplateParameter param = null;
9621 for(param = _class.templateParams.first; param; param = param.next)
9623 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9627 if(param && param.defaultArg.member)
9629 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9632 Expression expMember = exp.member.exp;
9634 OldList * specs = MkList();
9635 char thisClassTypeString[1024];
9637 FreeIdentifier(exp.member.member);
9639 ProcessExpressionType(argExp);
9642 char * colon = strstr(param.defaultArg.memberString, "::");
9645 char className[1024];
9648 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9649 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9652 strcpy(thisClassTypeString, _class.fullName);
9655 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9657 exp.expType = ProcessType(specs, decl);
9658 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9660 Class expClass = exp.expType._class.registered;
9661 Class cClass = null;
9666 char templateString[1024];
9667 ClassTemplateParameter param;
9668 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9669 for(cClass = expClass; cClass; cClass = cClass.base)
9672 for(param = cClass.templateParams.first; param; param = param.next)
9676 ClassTemplateArgument arg;
9677 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9678 arg = expClass.templateArgs[id];
9680 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9682 ClassTemplateParameter cParam;
9683 //int p = numParams - sClass.templateParams.count;
9686 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9688 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9690 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9692 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9694 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9695 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9707 strcat(argument, arg.name.string);
9708 strcat(argument, " = ");
9714 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9715 char expString[1024];
9716 OldList * specs = MkList();
9717 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9719 char * string = PrintHexUInt64(arg.expression.ui64);
9720 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9723 ProcessExpressionType(exp);
9724 ComputeExpression(exp);
9725 expString[0] = '\0';
9726 PrintExpression(exp, expString);
9727 strcat(argument, expString);
9729 FreeExpression(exp);
9734 strcat(argument, arg.member.name);
9737 case TemplateParameterType::type:
9739 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9741 if(!strcmp(arg.dataTypeString, "thisclass"))
9742 strcat(argument, thisClassTypeString);
9744 strcat(argument, arg.dataTypeString);
9751 if(paramCount) strcat(templateString, ", ");
9752 if(lastParam != p - 1)
9754 strcat(templateString, param.name);
9755 strcat(templateString, " = ");
9757 strcat(templateString, argument);
9766 int len = strlen(templateString);
9767 if(templateString[len-1] == '>') templateString[len++] = ' ';
9768 templateString[len++] = '>';
9769 templateString[len++] = '\0';
9772 Context context = SetupTemplatesContext(_class);
9773 FreeType(exp.expType);
9774 exp.expType = ProcessTypeString(templateString, false);
9775 FinishTemplatesContext(context);
9779 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9780 exp.type = bracketsExp;
9781 exp.list = MkListOne(MkExpOp(null, '*',
9786 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9787 MkExpBrackets(MkListOne(
9788 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9790 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9792 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9797 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9798 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9800 type = ProcessTemplateParameterType(type.templateParameter);
9803 // TODO: *** This seems to be where we should add method support for all basic types ***
9804 if(type && (type.kind == templateType));
9805 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9806 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
9807 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9808 (type.kind == pointerType && type.type.kind == charType)))
9810 Identifier id = exp.member.member;
9811 TypeKind typeKind = type.kind;
9812 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9813 if(typeKind == subClassType && exp.member.exp.type == classExp)
9815 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9816 typeKind = classType;
9821 if(typeKind == intType || typeKind == enumType)
9822 _class = eSystem_FindClass(privateModule, "int");
9825 if(type.kind == classType && type._class && type._class.registered)
9827 _class = type._class.registered;
9829 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
9831 _class = FindClass("char *").registered;
9833 else if(type.kind == pointerType)
9835 _class = eSystem_FindClass(privateModule, "uintptr");
9836 FreeType(exp.expType);
9837 exp.expType = ProcessTypeString("uintptr", false);
9838 exp.byReference = true;
9842 char string[1024] = "";
9844 PrintTypeNoConst(type, string, false, true);
9845 classSym = FindClass(string);
9846 if(classSym) _class = classSym.registered;
9854 (exp.member.exp.type == identifierExp &&
9855 !strcmp(exp.member.exp.identifier.string, "this"));*/
9856 Property prop = null;
9857 Method method = null;
9858 DataMember member = null;
9859 Property revConvert = null;
9860 ClassProperty classProp = null;
9862 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9863 exp.member.memberType = propertyMember;
9865 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9866 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9868 if(typeKind != subClassType)
9870 // Prioritize data members over properties for "this"
9871 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9873 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9874 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9876 prop = eClass_FindProperty(_class, id.string, privateModule);
9880 if(!member && !prop)
9881 prop = eClass_FindProperty(_class, id.string, privateModule);
9882 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9883 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9884 exp.member.thisPtr = true;
9886 // Prioritize properties over data members otherwise
9889 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9892 prop = eClass_FindProperty(_class, id.string, null);
9893 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9894 member = eClass_FindDataMember(_class, id.string, null, null, null);
9897 if(!prop && !member)
9899 method = eClass_FindMethod(_class, id.string, null);
9902 prop = eClass_FindProperty(_class, id.string, privateModule);
9903 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9904 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9910 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9917 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
9918 method = eClass_FindMethod(_class, id.string, privateModule);
9919 if(!prop && !member && !method)
9921 if(typeKind == subClassType)
9923 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9926 exp.member.memberType = classPropertyMember;
9927 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9931 // Assume this is a class_data member
9932 char structName[1024];
9933 Identifier id = exp.member.member;
9934 Expression classExp = exp.member.exp;
9937 FreeType(classExp.expType);
9938 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9940 strcpy(structName, "__ecereClassData_");
9941 FullClassNameCat(structName, type._class.string, false);
9942 exp.type = pointerExp;
9943 exp.member.member = id;
9945 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9946 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9947 MkExpBrackets(MkListOne(MkExpOp(
9948 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9949 MkExpMember(classExp, MkIdentifier("data"))), '+',
9950 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9955 ProcessExpressionType(exp);
9961 // Check for reverse conversion
9962 // (Convert in an instantiation later, so that we can use
9963 // deep properties system)
9964 Symbol classSym = FindClass(id.string);
9967 Class convertClass = classSym.registered;
9969 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9976 exp.member.memberType = propertyMember;
9978 ProcessPropertyType(prop);
9979 exp.expType = prop.dataType;
9980 if(prop.dataType) prop.dataType.refCount++;
9984 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9986 FreeExpContents(exp);
9987 exp.type = identifierExp;
9988 exp.identifier = MkIdentifier("class");
9989 ProcessExpressionType(exp);
9993 exp.member.memberType = dataMember;
9994 DeclareStruct(_class.fullName, false);
9995 if(!member.dataType)
9997 Context context = SetupTemplatesContext(_class);
9998 member.dataType = ProcessTypeString(member.dataTypeString, false);
9999 FinishTemplatesContext(context);
10001 exp.expType = member.dataType;
10002 if(member.dataType) member.dataType.refCount++;
10004 else if(revConvert)
10006 exp.member.memberType = reverseConversionMember;
10007 exp.expType = MkClassType(revConvert._class.fullName);
10015 exp.type = identifierExp;
10016 exp.identifier = exp.member.member;
10019 exp.member.memberType = methodMember;
10021 if(!method.dataType)
10022 ProcessMethodType(method);
10030 // Tricky spot here... To use instance versus class virtual table
10031 // Put it back to what it was... What did we break?
10033 // Had to put it back for overriding Main of Thread global instance
10035 //exp.expType.methodClass = _class;
10036 exp.expType.methodClass = (id && id._class) ? _class : null;
10038 // Need the actual class used for templated classes
10039 exp.expType.usedClass = _class;
10041 else if(!classProp)
10043 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10045 FreeExpContents(exp);
10046 exp.type = identifierExp;
10047 exp.identifier = MkIdentifier("class");
10048 FreeType(exp.expType);
10049 exp.expType = MkClassType("ecere::com::Class");
10052 yylloc = exp.member.member.loc;
10053 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10055 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10058 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10063 while(tClass && !tClass.templateClass) tClass = tClass.base;
10065 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10068 ClassTemplateParameter curParam = null;
10071 for(sClass = tClass; sClass; sClass = sClass.base)
10074 if(sClass.templateClass) sClass = sClass.templateClass;
10075 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10077 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10079 for(sClass = sClass.base; sClass; sClass = sClass.base)
10080 id += sClass.templateParams.count;
10085 if(curParam) break;
10088 if(curParam && tClass.templateArgs[id].dataTypeString)
10090 ClassTemplateArgument arg = tClass.templateArgs[id];
10091 Context context = SetupTemplatesContext(tClass);
10092 /*if(!arg.dataType)
10093 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10094 FreeType(exp.expType);
10095 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10098 if(exp.expType.kind == thisClassType)
10100 FreeType(exp.expType);
10101 exp.expType = ReplaceThisClassType(_class);
10104 if(tClass.templateClass)
10105 exp.expType.passAsTemplate = true;
10106 //exp.expType.refCount++;
10109 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10110 //exp.destType.refCount++;
10112 if(exp.destType.kind == thisClassType)
10114 FreeType(exp.destType);
10115 exp.destType = ReplaceThisClassType(_class);
10119 FinishTemplatesContext(context);
10122 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10123 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10126 ClassTemplateParameter curParam = null;
10129 for(sClass = tClass; sClass; sClass = sClass.base)
10132 if(sClass.templateClass) sClass = sClass.templateClass;
10133 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10135 if(curParam.type == TemplateParameterType::type &&
10136 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10138 for(sClass = sClass.base; sClass; sClass = sClass.base)
10139 id += sClass.templateParams.count;
10144 if(curParam) break;
10149 ClassTemplateArgument arg = tClass.templateArgs[id];
10150 Context context = SetupTemplatesContext(tClass);
10152 /*if(!arg.dataType)
10153 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10155 basicType = ProcessTypeString(arg.dataTypeString, false);
10158 if(basicType.kind == thisClassType)
10160 FreeType(basicType);
10161 basicType = ReplaceThisClassType(_class);
10164 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10165 if(tClass.templateClass)
10166 basicType.passAsTemplate = true;
10169 FreeType(exp.expType);
10171 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10172 //exp.expType.refCount++;
10175 exp.destType = exp.expType;
10176 exp.destType.refCount++;
10180 Expression newExp { };
10181 OldList * specs = MkList();
10183 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10185 if(exp.destType) exp.destType.refCount++;
10186 if(exp.expType) exp.expType.refCount++;
10187 exp.type = castExp;
10188 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10189 exp.cast.exp = newExp;
10190 //FreeType(exp.expType);
10191 //exp.expType = null;
10192 //ProcessExpressionType(sourceExp);
10195 FinishTemplatesContext(context);
10198 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10200 Class expClass = exp.expType._class.registered;
10203 Class cClass = null;
10206 int paramCount = 0;
10207 int lastParam = -1;
10208 char templateString[1024];
10209 ClassTemplateParameter param;
10210 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10211 while(cClass != expClass)
10214 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10217 for(param = cClass.templateParams.first; param; param = param.next)
10219 Class cClassCur = null;
10222 ClassTemplateParameter paramCur = null;
10223 ClassTemplateArgument arg;
10224 while(cClassCur != tClass && !paramCur)
10227 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10228 cClassCur = sClassCur;
10230 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10232 if(!strcmp(paramCur.name, param.name))
10240 if(paramCur && paramCur.type == TemplateParameterType::type)
10241 arg = tClass.templateArgs[cp];
10243 arg = expClass.templateArgs[p];
10246 char argument[256];
10247 argument[0] = '\0';
10250 strcat(argument, arg.name.string);
10251 strcat(argument, " = ");
10257 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10258 char expString[1024];
10259 OldList * specs = MkList();
10260 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10262 char * string = PrintHexUInt64(arg.expression.ui64);
10263 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10266 ProcessExpressionType(exp);
10267 ComputeExpression(exp);
10268 expString[0] = '\0';
10269 PrintExpression(exp, expString);
10270 strcat(argument, expString);
10272 FreeExpression(exp);
10277 strcat(argument, arg.member.name);
10280 case TemplateParameterType::type:
10282 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10283 strcat(argument, arg.dataTypeString);
10289 if(paramCount) strcat(templateString, ", ");
10290 if(lastParam != p - 1)
10292 strcat(templateString, param.name);
10293 strcat(templateString, " = ");
10295 strcat(templateString, argument);
10304 int len = strlen(templateString);
10305 if(templateString[len-1] == '>') templateString[len++] = ' ';
10306 templateString[len++] = '>';
10307 templateString[len++] = '\0';
10310 FreeType(exp.expType);
10312 Context context = SetupTemplatesContext(tClass);
10313 exp.expType = ProcessTypeString(templateString, false);
10314 FinishTemplatesContext(context);
10321 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10323 else if(type && (type.kind == structType || type.kind == unionType))
10325 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10328 exp.expType = memberType;
10330 memberType.refCount++;
10335 char expString[10240];
10336 expString[0] = '\0';
10337 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10338 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10341 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10343 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10345 Identifier id = exp.member.member;
10346 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10349 FreeType(exp.expType);
10350 exp.expType = ReplaceThisClassType(_class);
10354 yylloc = oldyylloc;
10357 // Convert x->y into (*x).y
10360 Type destType = exp.destType;
10362 // DOING THIS LATER NOW...
10363 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10365 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10366 /* TODO: Name Space Fix ups
10367 if(!exp.member.member.classSym)
10368 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10372 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10373 exp.type = memberExp;
10376 ProcessExpressionType(exp);
10383 //ComputeExpression(exp);
10385 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10386 if(classSym && classSym.registered)
10388 if(classSym.registered.type == noHeadClass)
10392 DeclareStruct(classSym.string, false);
10393 FreeSpecifier(exp._class);
10394 exp.type = typeSizeExp;
10395 FullClassNameCat(name, classSym.string, false);
10396 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10400 if(classSym.registered.fixed)
10402 FreeSpecifier(exp._class);
10403 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10404 exp.type = constantExp;
10408 char className[1024];
10409 strcpy(className, "__ecereClass_");
10410 FullClassNameCat(className, classSym.string, true);
10411 MangleClassName(className);
10413 DeclareClass(classSym, className);
10415 FreeExpContents(exp);
10416 exp.type = pointerExp;
10417 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10418 exp.member.member = MkIdentifier("structSize");
10428 // exp.isConstant = true;
10433 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10440 exp.isConstant = true;
10442 DeclareType(type, false, false);
10448 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10450 FreeType(exp.cast.exp.destType);
10451 exp.cast.exp.destType = type;
10453 ProcessExpressionType(exp.cast.exp);
10455 exp.expType = type;
10458 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10459 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10461 void * prev = exp.prev, * next = exp.next;
10462 Type expType = exp.cast.exp.destType;
10463 Expression castExp = exp.cast.exp;
10464 Type destType = exp.destType;
10466 if(expType) expType.refCount++;
10468 //FreeType(exp.destType);
10469 FreeType(exp.expType);
10470 FreeTypeName(exp.cast.typeName);
10473 FreeType(exp.expType);
10474 FreeType(exp.destType);
10476 exp.expType = expType;
10477 exp.destType = destType;
10487 exp.isConstant = exp.cast.exp.isConstant;
10492 case extensionInitializerExp:
10494 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10495 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10496 // ProcessInitializer(exp.initializer.initializer, type);
10497 exp.expType = type;
10502 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10503 ProcessExpressionType(exp.vaArg.exp);
10504 exp.expType = type;
10510 exp.isConstant = true;
10512 FreeType(exp.cond.cond.destType);
10513 exp.cond.cond.destType = MkClassType("bool");
10514 exp.cond.cond.destType.truth = true;
10515 ProcessExpressionType(exp.cond.cond);
10516 if(!exp.cond.cond.isConstant)
10517 exp.isConstant = false;
10518 for(e = exp.cond.exp->first; e; e = e.next)
10522 FreeType(e.destType);
10523 e.destType = exp.destType;
10524 if(e.destType) e.destType.refCount++;
10526 ProcessExpressionType(e);
10529 exp.expType = e.expType;
10530 if(e.expType) e.expType.refCount++;
10533 exp.isConstant = false;
10536 FreeType(exp.cond.elseExp.destType);
10537 // Added this check if we failed to find an expType
10538 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10541 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10543 if(exp.cond.elseExp.destType)
10544 exp.cond.elseExp.destType.refCount++;
10545 ProcessExpressionType(exp.cond.elseExp);
10547 // FIXED THIS: Was done before calling process on elseExp
10548 if(!exp.cond.elseExp.isConstant)
10549 exp.isConstant = false;
10552 case extensionCompoundExp:
10554 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10556 Statement last = exp.compound.compound.statements->last;
10557 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10559 ((Expression)last.expressions->last).destType = exp.destType;
10561 exp.destType.refCount++;
10563 ProcessStatement(exp.compound);
10564 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10566 exp.expType.refCount++;
10572 Specifier spec = exp._classExp.specifiers->first;
10573 if(spec && spec.type == nameSpecifier)
10575 exp.expType = MkClassType(spec.name);
10576 exp.expType.kind = subClassType;
10577 exp.byReference = true;
10581 exp.expType = MkClassType("ecere::com::Class");
10582 exp.byReference = true;
10588 Class _class = thisClass ? thisClass : currentClass;
10591 Identifier id = exp.classData.id;
10592 char structName[1024];
10593 Expression classExp;
10594 strcpy(structName, "__ecereClassData_");
10595 FullClassNameCat(structName, _class.fullName, false);
10596 exp.type = pointerExp;
10597 exp.member.member = id;
10598 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10599 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10601 classExp = MkExpIdentifier(MkIdentifier("class"));
10603 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10604 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10605 MkExpBrackets(MkListOne(MkExpOp(
10606 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10607 MkExpMember(classExp, MkIdentifier("data"))), '+',
10608 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10611 ProcessExpressionType(exp);
10619 char * typeString = null;
10620 char typeStringBuf[1024];
10621 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10622 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10624 Class templateClass = exp.destType._class.registered;
10625 typeString = templateClass.templateArgs[2].dataTypeString;
10629 // Guess type from expressions in the array
10631 for(e = exp.list->first; e; e = e.next)
10633 ProcessExpressionType(e);
10636 if(!type) { type = e.expType; type.refCount++; }
10639 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10640 if(!MatchTypeExpression(e, type, null, false))
10646 e = exp.list->first;
10647 ProcessExpressionType(e);
10650 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10651 if(!MatchTypeExpression(e, type, null, false))
10653 FreeType(e.expType);
10664 FreeType(e.expType);
10671 typeStringBuf[0] = '\0';
10672 PrintTypeNoConst(type, typeStringBuf, false, true);
10673 typeString = typeStringBuf;
10681 (Container)& (struct BuiltInContainer)
10683 ._vTbl = class(BuiltInContainer)._vTbl,
10684 ._class = class(BuiltInContainer),
10686 .data = (int[]){ 1, 7, 3, 4, 5 },
10688 .type = class(int),
10691 char templateString[1024];
10692 OldList * initializers = MkList();
10693 OldList * structInitializers = MkList();
10694 OldList * specs = MkList();
10696 Declarator decl = SpecDeclFromString(typeString, specs, null);
10697 sprintf(templateString, "Container<%s>", typeString);
10702 type = ProcessTypeString(typeString, false);
10703 while(e = exp.list->first)
10705 exp.list->Remove(e);
10708 ProcessExpressionType(e);
10709 ListAdd(initializers, MkInitializerAssignment(e));
10715 DeclareStruct("ecere::com::BuiltInContainer", false);
10717 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10718 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10719 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10720 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10721 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10722 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10723 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10724 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10725 MkInitializerList(initializers))));
10726 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10727 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10728 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10729 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10730 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10731 exp.expType = ProcessTypeString(templateString, false);
10732 exp.type = bracketsExp;
10733 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10735 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10736 MkInitializerList(structInitializers)))));
10737 ProcessExpressionType(expExt);
10741 exp.expType = ProcessTypeString("Container", false);
10742 Compiler_Error($"Couldn't determine type of array elements\n");
10748 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10750 FreeType(exp.expType);
10751 exp.expType = ReplaceThisClassType(thisClass);
10754 // Resolve structures here
10755 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10757 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10758 // TODO: Fix members reference...
10761 if(exp.expType.kind != enumType)
10764 String enumName = CopyString(exp.expType.enumName);
10766 // Fixed a memory leak on self-referencing C structs typedefs
10767 // by instantiating a new type rather than simply copying members
10768 // into exp.expType
10769 FreeType(exp.expType);
10770 exp.expType = Type { };
10771 exp.expType.kind = symbol.type.kind;
10772 exp.expType.refCount++;
10773 exp.expType.enumName = enumName;
10775 exp.expType.members = symbol.type.members;
10776 for(member = symbol.type.members.first; member; member = member.next)
10782 for(member = symbol.type.members.first; member; member = member.next)
10784 NamedLink value { name = CopyString(member.name) };
10785 exp.expType.members.Add(value);
10792 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10793 else if(exp.destType && !exp.destType.keepCast)
10795 if(!CheckExpressionType(exp, exp.destType, false))
10797 if(!exp.destType.count || unresolved)
10802 if(exp.destType.kind != ellipsisType)
10808 char expString[10240];
10809 expString[0] = '\0';
10811 PrintType(exp.destType, type2, false, true);
10813 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10815 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10816 else if(exp.type != dummyExp)
10817 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10822 char expString[10240] ;
10823 expString[0] = '\0';
10824 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10827 Compiler_Error($"unresolved identifier %s\n", expString);
10828 else if(exp.type != dummyExp)
10829 Compiler_Error($"couldn't determine type of %s\n", expString);
10840 PrintType(exp.expType, type1, false, true);
10841 PrintType(exp.destType, type2, false, true);
10844 //CheckExpressionType(exp, exp.destType, false);
10846 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10847 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10848 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10851 char expString[10240];
10852 expString[0] = '\0';
10853 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10856 CheckExpressionType(exp, exp.destType, false);
10858 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10859 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10860 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10862 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10863 FreeType(exp.expType);
10864 exp.destType.refCount++;
10865 exp.expType = exp.destType;
10870 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10872 Expression newExp { };
10873 char typeString[1024];
10874 OldList * specs = MkList();
10877 typeString[0] = '\0';
10881 if(exp.expType) exp.expType.refCount++;
10882 if(exp.expType) exp.expType.refCount++;
10883 exp.type = castExp;
10884 newExp.destType = exp.expType;
10886 PrintType(exp.expType, typeString, false, false);
10887 decl = SpecDeclFromString(typeString, specs, null);
10889 exp.cast.typeName = MkTypeName(specs, decl);
10890 exp.cast.exp = newExp;
10893 else if(unresolved)
10895 if(exp.identifier._class && exp.identifier._class.name)
10896 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10897 else if(exp.identifier.string && exp.identifier.string[0])
10898 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10900 else if(!exp.expType && exp.type != dummyExp)
10902 char expString[10240];
10903 expString[0] = '\0';
10904 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10905 Compiler_Error($"couldn't determine type of %s\n", expString);
10908 // Let's try to support any_object & typed_object here:
10910 ApplyAnyObjectLogic(exp);
10912 // Mark nohead classes as by reference, unless we're casting them to an integral type
10913 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10914 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
10915 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
10916 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
10918 exp.byReference = true;
10920 yylloc = oldyylloc;
10923 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10925 // THIS CODE WILL FIND NEXT MEMBER...
10928 *curMember = (*curMember).next;
10930 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10932 *curMember = subMemberStack[--(*subMemberStackPos)];
10933 *curMember = (*curMember).next;
10936 // SKIP ALL PROPERTIES HERE...
10937 while((*curMember) && (*curMember).isProperty)
10938 *curMember = (*curMember).next;
10940 if(subMemberStackPos)
10942 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10944 subMemberStack[(*subMemberStackPos)++] = *curMember;
10946 *curMember = (*curMember).members.first;
10947 while(*curMember && (*curMember).isProperty)
10948 *curMember = (*curMember).next;
10956 if(subMemberStackPos && *subMemberStackPos)
10958 *curMember = subMemberStack[--(*subMemberStackPos)];
10959 *curMember = (*curMember).next;
10963 Class lastCurClass = *curClass;
10965 if(*curClass == _class) break; // REACHED THE END
10967 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10968 *curMember = (*curClass).membersAndProperties.first;
10971 while((*curMember) && (*curMember).isProperty)
10972 *curMember = (*curMember).next;
10973 if(subMemberStackPos)
10975 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10977 subMemberStack[(*subMemberStackPos)++] = *curMember;
10979 *curMember = (*curMember).members.first;
10980 while(*curMember && (*curMember).isProperty)
10981 *curMember = (*curMember).next;
10989 static void ProcessInitializer(Initializer init, Type type)
10993 case expInitializer:
10994 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10996 // TESTING THIS FOR SHUTTING = 0 WARNING
10997 if(init.exp && !init.exp.destType)
10999 FreeType(init.exp.destType);
11000 init.exp.destType = type;
11001 if(type) type.refCount++;
11005 ProcessExpressionType(init.exp);
11006 init.isConstant = init.exp.isConstant;
11012 Expression exp = init.exp;
11013 Instantiation inst = exp.instance;
11014 MembersInit members;
11016 init.type = listInitializer;
11017 init.list = MkList();
11021 for(members = inst.members->first; members; members = members.next)
11023 if(members.type == dataMembersInit)
11026 for(member = members.dataMembers->first; member; member = member.next)
11028 ListAdd(init.list, member.initializer);
11029 member.initializer = null;
11032 // Discard all MembersInitMethod
11035 FreeExpression(exp);
11037 case listInitializer:
11040 Type initializerType = null;
11041 Class curClass = null;
11042 DataMember curMember = null;
11043 DataMember subMemberStack[256];
11044 int subMemberStackPos = 0;
11046 if(type && type.kind == arrayType)
11047 initializerType = Dereference(type);
11048 else if(type && (type.kind == structType || type.kind == unionType))
11049 initializerType = type.members.first;
11051 for(i = init.list->first; i; i = i.next)
11053 if(type && type.kind == classType && type._class && type._class.registered)
11055 // 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)
11056 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11057 // TODO: Generate error on initializing a private data member this way from another module...
11060 if(!curMember.dataType)
11061 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11062 initializerType = curMember.dataType;
11065 ProcessInitializer(i, initializerType);
11066 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11067 initializerType = initializerType.next;
11069 init.isConstant = false;
11072 if(type && type.kind == arrayType)
11073 FreeType(initializerType);
11075 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11077 Compiler_Error($"Assigning list initializer to non list\n");
11084 static void ProcessSpecifier(Specifier spec, bool declareStruct)
11088 case baseSpecifier:
11090 if(spec.specifier == THISCLASS)
11094 spec.type = nameSpecifier;
11095 spec.name = ReplaceThisClass(thisClass);
11096 spec.symbol = FindClass(spec.name);
11097 ProcessSpecifier(spec, declareStruct);
11102 case nameSpecifier:
11104 Symbol symbol = FindType(curContext, spec.name);
11106 DeclareType(symbol.type, true, true);
11107 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
11108 DeclareStruct(spec.name, false);
11111 case enumSpecifier:
11116 for(e = spec.list->first; e; e = e.next)
11119 ProcessExpressionType(e.exp);
11124 case structSpecifier:
11125 case unionSpecifier:
11127 if(spec.definitions)
11130 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11132 ProcessClass(spec.definitions, symbol);
11135 for(def = spec.definitions->first; def; def = def.next)
11137 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11138 ProcessDeclaration(def.decl);
11145 case classSpecifier:
11147 Symbol classSym = FindClass(spec.name);
11148 if(classSym && classSym.registered && classSym.registered.type == structClass)
11149 DeclareStruct(spec.name, false);
11157 static void ProcessDeclarator(Declarator decl)
11161 case identifierDeclarator:
11162 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11164 FreeSpecifier(decl.identifier._class);
11165 decl.identifier._class = null;
11168 case arrayDeclarator:
11170 ProcessExpressionType(decl.array.exp);
11171 case structDeclarator:
11172 case bracketsDeclarator:
11173 case functionDeclarator:
11174 case pointerDeclarator:
11175 case extendedDeclarator:
11176 case extendedDeclaratorEnd:
11177 if(decl.declarator)
11178 ProcessDeclarator(decl.declarator);
11179 if(decl.type == functionDeclarator)
11181 Identifier id = GetDeclId(decl);
11182 if(id && id._class)
11186 qualifiers = MkListOne(id._class);
11189 if(!decl.function.parameters)
11190 decl.function.parameters = MkList();
11191 decl.function.parameters->Insert(null, param);
11194 if(decl.function.parameters)
11198 for(param = decl.function.parameters->first; param; param = param.next)
11200 if(param.qualifiers && param.qualifiers->first)
11202 Specifier spec = param.qualifiers->first;
11203 if(spec && spec.specifier == TYPED_OBJECT)
11205 Declarator d = param.declarator;
11208 qualifiers = MkListOne(MkSpecifier(VOID));
11209 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11212 FreeList(param.qualifiers, FreeSpecifier);
11214 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11215 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11217 decl.function.parameters->Insert(param, newParam);
11220 else if(spec && spec.specifier == ANY_OBJECT)
11222 Declarator d = param.declarator;
11224 FreeList(param.qualifiers, FreeSpecifier);
11226 param.qualifiers = MkListOne(MkSpecifier(VOID));
11227 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11229 else if(spec.specifier == THISCLASS)
11233 spec.type = nameSpecifier;
11234 spec.name = ReplaceThisClass(thisClass);
11235 spec.symbol = FindClass(spec.name);
11236 ProcessSpecifier(spec, false);
11241 if(param.declarator)
11242 ProcessDeclarator(param.declarator);
11250 static void ProcessDeclaration(Declaration decl)
11255 case initDeclaration:
11257 bool declareStruct = false;
11259 lineNum = decl.pos.line;
11260 column = decl.pos.col;
11263 if(decl.declarators)
11267 for(d = decl.declarators->first; d; d = d.next)
11269 Type type, subType;
11270 ProcessDeclarator(d.declarator);
11272 type = ProcessType(decl.specifiers, d.declarator);
11276 ProcessInitializer(d.initializer, type);
11278 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11280 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11281 d.initializer.exp.type == instanceExp)
11283 if(type.kind == classType && type._class ==
11284 d.initializer.exp.expType._class)
11286 Instantiation inst = d.initializer.exp.instance;
11287 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11289 d.initializer.exp.instance = null;
11290 if(decl.specifiers)
11291 FreeList(decl.specifiers, FreeSpecifier);
11292 FreeList(decl.declarators, FreeInitDeclarator);
11296 decl.type = instDeclaration;
11301 for(subType = type; subType;)
11303 if(subType.kind == classType)
11305 declareStruct = true;
11308 else if(subType.kind == pointerType)
11310 else if(subType.kind == arrayType)
11311 subType = subType.arrayType;
11321 if(decl.specifiers)
11324 for(s = decl.specifiers->first; s; s = s.next)
11326 ProcessSpecifier(s, declareStruct);
11331 case instDeclaration:
11333 ProcessInstantiationType(decl.inst);
11336 case structDeclaration:
11340 bool declareStruct = false;
11342 if(decl.declarators)
11344 for(d = decl.declarators->first; d; d = d.next)
11346 Type type = ProcessType(decl.specifiers, d.declarator);
11348 ProcessDeclarator(d);
11349 for(subType = type; subType;)
11351 if(subType.kind == classType)
11353 declareStruct = true;
11356 else if(subType.kind == pointerType)
11358 else if(subType.kind == arrayType)
11359 subType = subType.arrayType;
11366 if(decl.specifiers)
11368 for(spec = decl.specifiers->first; spec; spec = spec.next)
11369 ProcessSpecifier(spec, declareStruct);
11376 static FunctionDefinition curFunction;
11378 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11380 char propName[1024], propNameM[1024];
11381 char getName[1024], setName[1024];
11384 DeclareProperty(prop, setName, getName);
11386 // eInstance_FireWatchers(object, prop);
11387 strcpy(propName, "__ecereProp_");
11388 FullClassNameCat(propName, prop._class.fullName, false);
11389 strcat(propName, "_");
11390 // strcat(propName, prop.name);
11391 FullClassNameCat(propName, prop.name, true);
11392 MangleClassName(propName);
11394 strcpy(propNameM, "__ecerePropM_");
11395 FullClassNameCat(propNameM, prop._class.fullName, false);
11396 strcat(propNameM, "_");
11397 // strcat(propNameM, prop.name);
11398 FullClassNameCat(propNameM, prop.name, true);
11399 MangleClassName(propNameM);
11401 if(prop.isWatchable)
11404 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11405 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11406 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11409 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11410 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11411 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11417 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11418 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11419 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11422 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11423 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11424 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11427 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11428 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11429 curFunction.propSet.fireWatchersDone = true;
11432 static void ProcessStatement(Statement stmt)
11436 lineNum = stmt.pos.line;
11437 column = stmt.pos.col;
11442 ProcessStatement(stmt.labeled.stmt);
11445 // This expression should be constant...
11446 if(stmt.caseStmt.exp)
11448 FreeType(stmt.caseStmt.exp.destType);
11449 stmt.caseStmt.exp.destType = curSwitchType;
11450 if(curSwitchType) curSwitchType.refCount++;
11451 ProcessExpressionType(stmt.caseStmt.exp);
11452 ComputeExpression(stmt.caseStmt.exp);
11454 if(stmt.caseStmt.stmt)
11455 ProcessStatement(stmt.caseStmt.stmt);
11459 if(stmt.compound.context)
11464 Statement prevCompound = curCompound;
11465 Context prevContext = curContext;
11467 if(!stmt.compound.isSwitch)
11468 curCompound = stmt;
11469 curContext = stmt.compound.context;
11471 if(stmt.compound.declarations)
11473 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11474 ProcessDeclaration(decl);
11476 if(stmt.compound.statements)
11478 for(s = stmt.compound.statements->first; s; s = s.next)
11479 ProcessStatement(s);
11482 curContext = prevContext;
11483 curCompound = prevCompound;
11487 case expressionStmt:
11490 if(stmt.expressions)
11492 for(exp = stmt.expressions->first; exp; exp = exp.next)
11493 ProcessExpressionType(exp);
11501 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11502 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11503 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11504 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11506 ProcessExpressionType(exp);
11508 if(stmt.ifStmt.stmt)
11509 ProcessStatement(stmt.ifStmt.stmt);
11510 if(stmt.ifStmt.elseStmt)
11511 ProcessStatement(stmt.ifStmt.elseStmt);
11516 Type oldSwitchType = curSwitchType;
11517 if(stmt.switchStmt.exp)
11520 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11530 e.exp.destType = destType;
11533 ProcessExpressionType(exp);
11536 curSwitchType = exp.expType;
11539 ProcessStatement(stmt.switchStmt.stmt);
11540 curSwitchType = oldSwitchType;
11545 if(stmt.whileStmt.exp)
11549 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11550 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11551 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11552 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11554 ProcessExpressionType(exp);
11557 if(stmt.whileStmt.stmt)
11558 ProcessStatement(stmt.whileStmt.stmt);
11563 if(stmt.doWhile.exp)
11567 if(stmt.doWhile.exp->last)
11569 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11570 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11571 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11573 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11575 ProcessExpressionType(exp);
11578 if(stmt.doWhile.stmt)
11579 ProcessStatement(stmt.doWhile.stmt);
11585 if(stmt.forStmt.init)
11586 ProcessStatement(stmt.forStmt.init);
11588 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11590 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11591 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11592 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11595 if(stmt.forStmt.check)
11596 ProcessStatement(stmt.forStmt.check);
11597 if(stmt.forStmt.increment)
11599 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11600 ProcessExpressionType(exp);
11603 if(stmt.forStmt.stmt)
11604 ProcessStatement(stmt.forStmt.stmt);
11609 Identifier id = stmt.forEachStmt.id;
11610 OldList * exp = stmt.forEachStmt.exp;
11611 OldList * filter = stmt.forEachStmt.filter;
11612 Statement block = stmt.forEachStmt.stmt;
11613 char iteratorType[1024];
11616 bool isBuiltin = exp && exp->last &&
11617 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11618 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11619 Expression arrayExp;
11620 char * typeString = null;
11621 int builtinCount = 0;
11623 for(e = exp ? exp->first : null; e; e = e.next)
11627 FreeType(e.destType);
11628 e.destType = ProcessTypeString("Container", false);
11630 if(!isBuiltin || e.next)
11631 ProcessExpressionType(e);
11634 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11635 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11636 eClass_IsDerived(source._class.registered, containerClass)))
11638 Class _class = source ? source._class.registered : null;
11640 Expression expIt = null;
11641 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
11642 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11643 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11644 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11645 stmt.type = compoundStmt;
11647 stmt.compound.context = Context { };
11648 stmt.compound.context.parent = curContext;
11649 curContext = stmt.compound.context;
11651 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11653 Class mapClass = eSystem_FindClass(privateModule, "Map");
11654 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11655 isCustomAVLTree = true;
11656 if(eClass_IsDerived(source._class.registered, avlTreeClass))
11658 else if(eClass_IsDerived(source._class.registered, mapClass))
11661 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11662 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11664 Class listClass = eSystem_FindClass(privateModule, "List");
11666 isList = eClass_IsDerived(source._class.registered, listClass);
11672 OldList * specs = MkList();
11673 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11674 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11675 stmt.compound.declarations = MkListOne(
11676 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11677 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11678 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11679 MkInitializerAssignment(MkExpBrackets(exp))))));
11684 char typeStringBuf[1024];
11686 // TODO: Merge this code?
11687 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11688 if(((Expression)exp->last).type == castExp)
11690 TypeName typeName = ((Expression)exp->last).cast.typeName;
11692 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11695 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11696 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11697 arrayExp.destType._class.registered.templateArgs)
11699 Class templateClass = arrayExp.destType._class.registered;
11700 typeString = templateClass.templateArgs[2].dataTypeString;
11702 else if(arrayExp.list)
11704 // Guess type from expressions in the array
11706 for(e = arrayExp.list->first; e; e = e.next)
11708 ProcessExpressionType(e);
11711 if(!type) { type = e.expType; type.refCount++; }
11714 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11715 if(!MatchTypeExpression(e, type, null, false))
11721 e = arrayExp.list->first;
11722 ProcessExpressionType(e);
11725 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11726 if(!MatchTypeExpression(e, type, null, false))
11728 FreeType(e.expType);
11739 FreeType(e.expType);
11746 typeStringBuf[0] = '\0';
11747 PrintType(type, typeStringBuf, false, true);
11748 typeString = typeStringBuf;
11754 OldList * initializers = MkList();
11756 OldList * specs = MkList();
11761 builtinCount = arrayExp.list->count;
11762 type = ProcessTypeString(typeString, false);
11763 while(e = arrayExp.list->first)
11765 arrayExp.list->Remove(e);
11768 ProcessExpressionType(e);
11769 ListAdd(initializers, MkInitializerAssignment(e));
11772 delete arrayExp.list;
11774 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11775 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11776 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11778 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
11780 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
11781 ), MkInitializerList(initializers)))));
11782 FreeList(exp, FreeExpression);
11786 arrayExp.expType = ProcessTypeString("Container", false);
11787 Compiler_Error($"Couldn't determine type of array elements\n");
11792 OldList * specs = MkList();
11794 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11795 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11796 stmt.compound.declarations = MkListOne(
11797 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11798 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11799 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11800 MkInitializerAssignment(MkExpBrackets(exp))))));
11803 else if(isLinkList && !isList)
11806 OldList * specs = MkList();
11807 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11808 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11809 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11810 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11811 MkInitializerAssignment(MkExpBrackets(exp))))));
11813 /*else if(isCustomAVLTree)
11816 OldList * specs = MkList();
11817 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11818 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11819 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11820 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11821 MkInitializerAssignment(MkExpBrackets(exp))))));
11823 else if(_class.templateArgs)
11826 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11828 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11830 stmt.compound.declarations = MkListOne(
11831 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11832 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11833 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11835 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11839 // Reparent sub-contexts in this statement
11843 if(block.compound.context)
11844 block.compound.context.parent = stmt.compound.context;
11847 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
11848 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
11849 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
11850 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
11853 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
11854 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
11857 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
11858 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
11861 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
11862 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
11865 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
11866 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
11869 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
11870 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
11872 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
11875 case expressionStmt:
11881 case badDeclarationStmt:
11882 case fireWatchersStmt:
11883 case stopWatchingStmt:
11890 block = MkIfStmt(filter, block, null);
11894 stmt.compound.statements = MkListOne(MkForStmt(
11895 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11896 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11897 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11898 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11900 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11901 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11902 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11907 //OldList * specs = MkList();
11908 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11910 sprintf(count, "%d", builtinCount);
11912 stmt.compound.statements = MkListOne(MkForStmt(
11913 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11914 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11915 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11916 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11920 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11921 stmt.compound.statements = MkListOne(MkForStmt(
11922 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11923 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11924 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11925 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11928 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11929 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11930 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11932 else if(isLinkList && !isList)
11934 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11935 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11936 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11937 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11939 stmt.compound.statements = MkListOne(MkForStmt(
11940 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11941 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11942 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11947 OldList * specs = MkList();
11948 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11949 stmt.compound.statements = MkListOne(MkForStmt(
11950 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11951 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11952 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11953 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11954 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11957 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11958 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11959 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11961 /*else if(isCustomAVLTree)
11963 stmt.compound.statements = MkListOne(MkForStmt(
11964 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11965 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11966 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11967 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11970 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11971 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11972 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11976 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11977 MkIdentifier("Next")), null)), block));
11979 ProcessExpressionType(expIt);
11980 if(stmt.compound.declarations->first)
11981 ProcessDeclaration(stmt.compound.declarations->first);
11984 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11986 ProcessStatement(stmt);
11987 curContext = stmt.compound.context.parent;
11992 Compiler_Error($"Expression is not a container\n");
12005 if(stmt.expressions)
12007 for(exp = stmt.expressions->first; exp; exp = exp.next)
12011 if(curFunction && !curFunction.type)
12012 curFunction.type = ProcessType(
12013 curFunction.specifiers, curFunction.declarator);
12014 FreeType(exp.destType);
12015 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12016 if(exp.destType) exp.destType.refCount++;
12018 ProcessExpressionType(exp);
12023 case badDeclarationStmt:
12025 ProcessDeclaration(stmt.decl);
12031 if(stmt.asmStmt.inputFields)
12033 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12034 if(field.expression)
12035 ProcessExpressionType(field.expression);
12037 if(stmt.asmStmt.outputFields)
12039 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12040 if(field.expression)
12041 ProcessExpressionType(field.expression);
12043 if(stmt.asmStmt.clobberedFields)
12045 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12047 if(field.expression)
12048 ProcessExpressionType(field.expression);
12055 PropertyWatch propWatch;
12056 OldList * watches = stmt._watch.watches;
12057 Expression object = stmt._watch.object;
12058 Expression watcher = stmt._watch.watcher;
12060 ProcessExpressionType(watcher);
12062 ProcessExpressionType(object);
12066 if(watcher || thisClass)
12068 External external = curExternal;
12069 Context context = curContext;
12071 stmt.type = expressionStmt;
12072 stmt.expressions = MkList();
12074 curExternal = external.prev;
12076 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12078 ClassFunction func;
12079 char watcherName[1024];
12080 Class watcherClass = watcher ?
12081 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12082 External createdExternal;
12084 // Create a declaration above
12085 External externalDecl = MkExternalDeclaration(null);
12086 ast->Insert(curExternal.prev, externalDecl);
12088 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12089 if(propWatch.deleteWatch)
12090 strcat(watcherName, "_delete");
12094 for(propID = propWatch.properties->first; propID; propID = propID.next)
12096 strcat(watcherName, "_");
12097 strcat(watcherName, propID.string);
12101 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12103 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
12104 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12105 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
12106 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12107 ProcessClassFunctionBody(func, propWatch.compound);
12108 propWatch.compound = null;
12110 //afterExternal = afterExternal ? afterExternal : curExternal;
12112 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
12113 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12115 createdExternal.symbol.idCode = external.symbol.idCode;
12117 curExternal = createdExternal;
12118 ProcessFunction(createdExternal.function);
12121 // Create a declaration above
12123 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
12124 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
12125 externalDecl.declaration = decl;
12126 if(decl.symbol && !decl.symbol.pointerExternal)
12127 decl.symbol.pointerExternal = externalDecl;
12130 if(propWatch.deleteWatch)
12132 OldList * args = MkList();
12133 ListAdd(args, CopyExpression(object));
12134 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12135 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12136 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12140 Class _class = object.expType._class.registered;
12143 for(propID = propWatch.properties->first; propID; propID = propID.next)
12145 char propName[1024];
12146 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12149 char getName[1024], setName[1024];
12150 OldList * args = MkList();
12152 DeclareProperty(prop, setName, getName);
12154 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12155 strcpy(propName, "__ecereProp_");
12156 FullClassNameCat(propName, prop._class.fullName, false);
12157 strcat(propName, "_");
12158 // strcat(propName, prop.name);
12159 FullClassNameCat(propName, prop.name, true);
12161 ListAdd(args, CopyExpression(object));
12162 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12163 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12164 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12166 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12169 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12174 Compiler_Error($"Invalid watched object\n");
12177 curExternal = external;
12178 curContext = context;
12181 FreeExpression(watcher);
12183 FreeExpression(object);
12184 FreeList(watches, FreePropertyWatch);
12187 Compiler_Error($"No observer specified and not inside a _class\n");
12191 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12193 ProcessStatement(propWatch.compound);
12199 case fireWatchersStmt:
12201 OldList * watches = stmt._watch.watches;
12202 Expression object = stmt._watch.object;
12204 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12205 // printf("%X\n", watches);
12206 // printf("%X\n", stmt._watch.watches);
12208 ProcessExpressionType(object);
12213 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12219 stmt.type = expressionStmt;
12220 stmt.expressions = MkList();
12222 // Check if we're inside a property set
12223 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12225 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12229 //Compiler_Error($"No property specified and not inside a property set\n");
12233 for(propID = watches->first; propID; propID = propID.next)
12235 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12238 CreateFireWatcher(prop, object, stmt);
12241 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12246 // Fire all properties!
12249 for(base = _class; base; base = base.base)
12251 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12253 if(prop.isProperty && prop.isWatchable)
12255 CreateFireWatcher(prop, object, stmt);
12262 FreeExpression(object);
12263 FreeList(watches, FreeIdentifier);
12266 Compiler_Error($"Invalid object specified and not inside a class\n");
12270 case stopWatchingStmt:
12272 OldList * watches = stmt._watch.watches;
12273 Expression object = stmt._watch.object;
12274 Expression watcher = stmt._watch.watcher;
12277 ProcessExpressionType(object);
12279 ProcessExpressionType(watcher);
12282 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12284 if(watcher || thisClass)
12290 stmt.type = expressionStmt;
12291 stmt.expressions = MkList();
12296 // eInstance_StopWatching(object, null, watcher);
12298 ListAdd(args, CopyExpression(object));
12299 ListAdd(args, MkExpConstant("0"));
12300 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12301 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12305 for(propID = watches->first; propID; propID = propID.next)
12307 char propName[1024];
12308 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12311 char getName[1024], setName[1024];
12312 OldList * args = MkList();
12314 DeclareProperty(prop, setName, getName);
12316 // eInstance_StopWatching(object, prop, watcher);
12317 strcpy(propName, "__ecereProp_");
12318 FullClassNameCat(propName, prop._class.fullName, false);
12319 strcat(propName, "_");
12320 // strcat(propName, prop.name);
12321 FullClassNameCat(propName, prop.name, true);
12322 MangleClassName(propName);
12324 ListAdd(args, CopyExpression(object));
12325 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12326 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12327 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12330 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12335 FreeExpression(object);
12337 FreeExpression(watcher);
12338 FreeList(watches, FreeIdentifier);
12341 Compiler_Error($"Invalid object specified and not inside a class\n");
12344 Compiler_Error($"No observer specified and not inside a class\n");
12351 static void ProcessFunction(FunctionDefinition function)
12353 Identifier id = GetDeclId(function.declarator);
12354 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12355 Type type = symbol ? symbol.type : null;
12356 Class oldThisClass = thisClass;
12357 Context oldTopContext = topContext;
12359 yylloc = function.loc;
12360 // Process thisClass
12362 if(type && type.thisClass)
12364 Symbol classSym = type.thisClass;
12365 Class _class = type.thisClass.registered;
12366 char className[1024];
12367 char structName[1024];
12368 Declarator funcDecl;
12371 bool typedObject = false;
12373 if(_class && !_class.base)
12375 _class = currentClass;
12376 if(_class && !_class.symbol)
12377 _class.symbol = FindClass(_class.fullName);
12378 classSym = _class ? _class.symbol : null;
12379 typedObject = true;
12382 thisClass = _class;
12384 if(inCompiler && _class)
12386 if(type.kind == functionType)
12388 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12390 //TypeName param = symbol.type.params.first;
12391 Type param = symbol.type.params.first;
12392 symbol.type.params.Remove(param);
12393 //FreeTypeName(param);
12396 if(type.classObjectType != classPointer)
12398 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12399 symbol.type.staticMethod = true;
12400 symbol.type.thisClass = null;
12402 // HIGH DANGER: VERIFYING THIS...
12403 symbol.type.extraParam = false;
12407 strcpy(className, "__ecereClass_");
12408 FullClassNameCat(className, _class.fullName, true);
12410 MangleClassName(className);
12413 FullClassNameCat(structName, _class.fullName, false);
12418 funcDecl = GetFuncDecl(function.declarator);
12421 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12423 TypeName param = funcDecl.function.parameters->first;
12424 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12426 funcDecl.function.parameters->Remove(param);
12427 FreeTypeName(param);
12431 // DANGER: Watch for this... Check if it's a Conversion?
12432 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12434 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12435 if(!function.propertyNoThis)
12437 TypeName thisParam;
12439 if(type.classObjectType != classPointer)
12441 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12442 if(!funcDecl.function.parameters)
12443 funcDecl.function.parameters = MkList();
12444 funcDecl.function.parameters->Insert(null, thisParam);
12449 if(type.classObjectType != classPointer)
12451 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12452 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12455 thisParam = TypeName
12457 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12458 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12460 funcDecl.function.parameters->Insert(null, thisParam);
12465 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12467 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12468 funcDecl = GetFuncDecl(initDecl.declarator);
12471 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12473 TypeName param = funcDecl.function.parameters->first;
12474 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12476 funcDecl.function.parameters->Remove(param);
12477 FreeTypeName(param);
12481 if(type.classObjectType != classPointer)
12483 // DANGER: Watch for this... Check if it's a Conversion?
12484 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12486 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12488 if(!funcDecl.function.parameters)
12489 funcDecl.function.parameters = MkList();
12490 funcDecl.function.parameters->Insert(null, thisParam);
12497 // Add this to the context
12500 if(type.classObjectType != classPointer)
12502 thisSymbol = Symbol
12504 string = CopyString("this");
12505 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12507 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12509 if(typedObject && thisSymbol.type)
12511 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12512 thisSymbol.type.byReference = type.byReference;
12513 thisSymbol.type.typedByReference = type.byReference;
12515 thisSymbol = Symbol { string = CopyString("class") };
12516 function.body.compound.context.symbols.Add(thisSymbol);
12522 // Pointer to class data
12524 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12526 DataMember member = null;
12529 for(base = _class; base && base.type != systemClass; base = base.next)
12531 for(member = base.membersAndProperties.first; member; member = member.next)
12532 if(!member.isProperty)
12538 for(member = _class.membersAndProperties.first; member; member = member.next)
12539 if(!member.isProperty)
12543 char pointerName[1024];
12546 Initializer initializer;
12547 Expression exp, bytePtr;
12549 strcpy(pointerName, "__ecerePointer_");
12550 FullClassNameCat(pointerName, _class.fullName, false);
12552 char className[1024];
12553 strcpy(className, "__ecereClass_");
12554 FullClassNameCat(className, classSym.string, true);
12555 MangleClassName(className);
12558 DeclareClass(classSym, className);
12562 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12567 sprintf(string, "%d", _class.offset);
12568 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12572 // ([bytePtr] + [className]->offset)
12573 exp = QBrackets(MkExpOp(bytePtr, '+',
12574 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12577 // (this ? [exp] : 0)
12578 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12582 kind = pointerType;
12583 type = Type { refCount = 1, kind = voidType };
12588 yylloc = function.body.loc;
12589 // ([structName] *) [exp]
12590 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12591 initializer = MkInitializerAssignment(
12592 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12594 // [structName] * [pointerName] = [initializer];
12595 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12598 Context prevContext = curContext;
12599 curContext = function.body.compound.context;
12601 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12602 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12604 curContext = prevContext;
12608 decl.symbol = null;
12610 if(!function.body.compound.declarations)
12611 function.body.compound.declarations = MkList();
12612 function.body.compound.declarations->Insert(null, decl);
12618 // Loop through the function and replace undeclared identifiers
12619 // which are a member of the class (methods, properties or data)
12620 // by "this.[member]"
12627 FreeSpecifier(id._class);
12630 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12632 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12633 id = GetDeclId(initDecl.declarator);
12635 FreeSpecifier(id._class);
12640 topContext = function.body.compound.context;
12642 FunctionDefinition oldFunction = curFunction;
12643 curFunction = function;
12645 ProcessStatement(function.body);
12647 // If this is a property set and no firewatchers has been done yet, add one here
12648 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12650 Statement prevCompound = curCompound;
12651 Context prevContext = curContext;
12653 Statement fireWatchers = MkFireWatchersStmt(null, null);
12654 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12655 ListAdd(function.body.compound.statements, fireWatchers);
12657 curCompound = function.body;
12658 curContext = function.body.compound.context;
12660 ProcessStatement(fireWatchers);
12662 curContext = prevContext;
12663 curCompound = prevCompound;
12667 curFunction = oldFunction;
12670 if(function.declarator)
12672 ProcessDeclarator(function.declarator);
12675 topContext = oldTopContext;
12676 thisClass = oldThisClass;
12679 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12680 static void ProcessClass(OldList definitions, Symbol symbol)
12683 External external = curExternal;
12684 Class regClass = symbol ? symbol.registered : null;
12686 // Process all functions
12687 for(def = definitions.first; def; def = def.next)
12689 if(def.type == functionClassDef)
12691 if(def.function.declarator)
12692 curExternal = def.function.declarator.symbol.pointerExternal;
12694 curExternal = external;
12696 ProcessFunction((FunctionDefinition)def.function);
12698 else if(def.type == declarationClassDef)
12700 if(def.decl.type == instDeclaration)
12702 thisClass = regClass;
12703 ProcessInstantiationType(def.decl.inst);
12709 Class backThisClass = thisClass;
12710 if(regClass) thisClass = regClass;
12711 ProcessDeclaration(def.decl);
12712 thisClass = backThisClass;
12715 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12717 MemberInit defProperty;
12719 // Add this to the context
12720 Symbol thisSymbol = Symbol
12722 string = CopyString("this");
12723 type = regClass ? MkClassType(regClass.fullName) : null;
12725 globalContext.symbols.Add((BTNode)thisSymbol);
12727 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12729 thisClass = regClass;
12730 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12734 globalContext.symbols.Remove((BTNode)thisSymbol);
12735 FreeSymbol(thisSymbol);
12737 else if(def.type == propertyClassDef && def.propertyDef)
12739 PropertyDef prop = def.propertyDef;
12741 // Add this to the context
12743 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12744 globalContext.symbols.Add(thisSymbol);
12747 thisClass = regClass;
12754 string = CopyString("this");
12755 type = MkClassType(regClass.fullName);
12757 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12760 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12761 ProcessStatement(prop.setStmt);
12769 string = CopyString("this");
12770 type = MkClassType(regClass.fullName);
12772 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12775 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12776 ProcessStatement(prop.getStmt);
12784 string = CopyString("this");
12785 type = MkClassType(regClass.fullName);
12787 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12790 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12791 ProcessStatement(prop.issetStmt);
12797 globalContext.symbols.Remove(thisSymbol);
12798 FreeSymbol(thisSymbol);
12801 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12803 PropertyWatch propertyWatch = def.propertyWatch;
12805 thisClass = regClass;
12806 if(propertyWatch.compound)
12810 string = CopyString("this");
12811 type = regClass ? MkClassType(regClass.fullName) : null;
12814 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12816 curExternal = null;
12817 ProcessStatement(propertyWatch.compound);
12824 void DeclareFunctionUtil(String s)
12826 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12831 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12832 strcpy(name, "__ecereFunction_");
12833 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12834 DeclareFunction(function, name);
12838 void ComputeDataTypes()
12842 External after = null;
12844 currentClass = null;
12846 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12848 for(external = ast->first; external; external = external.next)
12850 if(external.type == declarationExternal)
12852 Declaration decl = external.declaration;
12855 OldList * decls = decl.declarators;
12858 InitDeclarator initDecl = decls->first;
12861 Declarator declarator = initDecl.declarator;
12862 if(declarator && declarator.type == identifierDeclarator)
12864 Identifier id = declarator.identifier;
12865 if(id && id.string)
12867 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12869 external.symbol.id = -1001, external.symbol.idCode = -1001;
12880 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12881 ast->Insert(after, temp);
12882 curExternal = temp;
12884 DeclareFunctionUtil("eSystem_New");
12885 DeclareFunctionUtil("eSystem_New0");
12886 DeclareFunctionUtil("eSystem_Renew");
12887 DeclareFunctionUtil("eSystem_Renew0");
12888 DeclareFunctionUtil("eSystem_Delete");
12889 DeclareFunctionUtil("eClass_GetProperty");
12890 DeclareFunctionUtil("eInstance_FireSelfWatchers");
12892 DeclareStruct("ecere::com::Class", false);
12893 DeclareStruct("ecere::com::Instance", false);
12894 DeclareStruct("ecere::com::Property", false);
12895 DeclareStruct("ecere::com::DataMember", false);
12896 DeclareStruct("ecere::com::Method", false);
12897 DeclareStruct("ecere::com::SerialBuffer", false);
12898 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12902 for(external = ast->first; external; external = external.next)
12904 afterExternal = curExternal = external;
12905 if(external.type == functionExternal)
12907 currentClass = external.function._class;
12908 ProcessFunction(external.function);
12910 // There shouldn't be any _class member access here anyways...
12911 else if(external.type == declarationExternal)
12913 currentClass = null;
12914 if(external.declaration)
12915 ProcessDeclaration(external.declaration);
12917 else if(external.type == classExternal)
12919 ClassDefinition _class = external._class;
12920 currentClass = external.symbol.registered;
12921 if(_class.definitions)
12923 ProcessClass(_class.definitions, _class.symbol);
12927 // Free class data...
12928 ast->Remove(external);
12932 else if(external.type == nameSpaceExternal)
12934 thisNameSpace = external.id.string;
12937 currentClass = null;
12938 thisNameSpace = null;
12939 curExternal = null;
12941 delete temp.symbol;