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)
52 OutputExpression(exp, f);
54 count = strlen(string);
55 count += f.Read(string + count, 1, 1023);
61 Type ProcessTemplateParameterType(TemplateParameter param)
63 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
65 // TOFIX: Will need to free this Type
68 if(param.dataTypeString)
69 param.baseType = ProcessTypeString(param.dataTypeString, false);
71 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
73 return param.baseType;
78 bool NeedCast(Type type1, Type type2)
80 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
82 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
87 if(type1.kind == type2.kind)
98 if(type1.passAsTemplate && !type2.passAsTemplate)
100 return type1.isSigned != type2.isSigned;
102 return type1._class != type2._class;
104 return NeedCast(type1.type, type2.type);
106 return true; //false; ????
112 static void ReplaceClassMembers(Expression exp, Class _class)
114 if(exp.type == identifierExp && exp.identifier)
116 Identifier id = exp.identifier;
118 Symbol symbol = null;
119 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
121 // First, check if the identifier is declared inside the function
122 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
124 symbol = (Symbol)ctx.symbols.FindString(id.string);
129 // If it is not, check if it is a member of the _class
130 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
132 Property prop = eClass_FindProperty(_class, id.string, privateModule);
133 Method method = null;
134 DataMember member = null;
135 ClassProperty classProp = null;
138 method = eClass_FindMethod(_class, id.string, privateModule);
141 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
142 if(!prop && !method && !member)
144 classProp = eClass_FindClassProperty(_class, id.string);
146 if(prop || method || member || classProp)
148 // Replace by this.[member]
149 exp.type = memberExp;
150 exp.member.member = id;
151 exp.member.memberType = unresolvedMember;
152 exp.member.exp = QMkExpId("this");
153 //exp.member.exp.loc = exp.loc;
154 exp.addedThis = true;
156 else if(_class && _class.templateParams.first)
159 for(sClass = _class; sClass; sClass = sClass.base)
161 if(sClass.templateParams.first)
163 ClassTemplateParameter param;
164 for(param = sClass.templateParams.first; param; param = param.next)
166 if(param.type == expression && !strcmp(param.name, id.string))
168 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
173 OldList * specs = MkList();
175 FreeIdentifier(exp.member.member);
177 ProcessExpressionType(argExp);
179 decl = SpecDeclFromString(param.dataTypeString, specs, null);
181 exp.expType = ProcessType(specs, decl);
183 // *[expType] *[argExp]
184 exp.type = bracketsExp;
185 exp.list = MkListOne(MkExpOp(null, '*',
186 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
197 ////////////////////////////////////////////////////////////////////////
198 // PRINTING ////////////////////////////////////////////////////////////
199 ////////////////////////////////////////////////////////////////////////
201 public char * PrintInt(int64 result)
204 if(result > MAXINT64)
205 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
207 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
208 return CopyString(temp);
211 public char * PrintUInt(uint64 result)
214 if(result > MAXDWORD)
215 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
216 else if(result > MAXINT)
217 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
219 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
220 return CopyString(temp);
223 public char * PrintInt64(int64 result)
226 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
227 return CopyString(temp);
230 public char * PrintUInt64(uint64 result)
233 if(result > MAXINT64)
234 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
236 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
237 return CopyString(temp);
240 public char * PrintHexUInt(uint64 result)
243 if(result > MAXDWORD)
244 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
246 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
247 return CopyString(temp);
250 public char * PrintHexUInt64(uint64 result)
253 if(result > MAXDWORD)
254 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
256 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
257 return CopyString(temp);
260 public char * PrintShort(short result)
263 sprintf(temp, "%d", (unsigned short)result);
264 return CopyString(temp);
267 public char * PrintUShort(unsigned short result)
271 sprintf(temp, "0x%X", (int)result);
273 sprintf(temp, "%d", (int)result);
274 return CopyString(temp);
277 public char * PrintChar(char result)
280 if(result > 0 && isprint(result))
281 sprintf(temp, "'%c'", result);
283 sprintf(temp, "%d", (int)result);
285 //sprintf(temp, "%#X", result);
286 sprintf(temp, "0x%X", (unsigned char)result);
287 return CopyString(temp);
290 public char * PrintUChar(unsigned char result)
293 sprintf(temp, "0x%X", result);
294 return CopyString(temp);
297 public char * PrintFloat(float result)
300 sprintf(temp, "%.16ff", result);
301 return CopyString(temp);
304 public char * PrintDouble(double result)
307 sprintf(temp, "%.16f", result);
308 return CopyString(temp);
311 ////////////////////////////////////////////////////////////////////////
312 ////////////////////////////////////////////////////////////////////////
314 //public Operand GetOperand(Expression exp);
316 #define GETVALUE(name, t) \
317 public bool GetOp##name(Operand op2, t * value2) \
319 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
320 else if(op2.kind == intType) *value2 = (t) op2.ui; \
321 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
322 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
323 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
324 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
325 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
326 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
327 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
328 else if(op2.kind == shortType) *value2 = (t) op2.us; \
329 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
330 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
331 else if(op2.kind == floatType) *value2 = (t) op2.f; \
332 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
333 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
338 public bool Get##name(Expression exp, t * value2) \
340 Operand op2 = GetOperand(exp); \
341 return GetOp##name(op2, value2); \
344 // To help the deubugger currently not preprocessing...
347 GETVALUE(Int, HELP(int));
348 GETVALUE(UInt, HELP(unsigned int));
349 GETVALUE(Int64, HELP(int64));
350 GETVALUE(UInt64, HELP(uint64));
351 GETVALUE(IntPtr, HELP(intptr));
352 GETVALUE(UIntPtr, HELP(uintptr));
353 GETVALUE(IntSize, HELP(intsize));
354 GETVALUE(UIntSize, HELP(uintsize));
355 GETVALUE(Short, HELP(short));
356 GETVALUE(UShort, HELP(unsigned short));
357 GETVALUE(Char, HELP(char));
358 GETVALUE(UChar, HELP(unsigned char));
359 GETVALUE(Float, HELP(float));
360 GETVALUE(Double, HELP(double));
362 void ComputeExpression(Expression exp);
364 void ComputeClassMembers(Class _class, bool isMember)
366 DataMember member = isMember ? (DataMember) _class : null;
367 Context context = isMember ? null : SetupTemplatesContext(_class);
368 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
369 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
372 int unionMemberOffset = 0;
376 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
377 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
382 member.memberOffset = 0;
383 if(targetBits < sizeof(void *) * 8)
384 member.structAlignment = 0;
386 else if(targetBits < sizeof(void *) * 8)
387 _class.structAlignment = 0;
389 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
390 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
391 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
393 if(!member && _class.destructionWatchOffset)
394 _class.memberOffset += sizeof(OldList);
396 // To avoid reentrancy...
397 //_class.structSize = -1;
400 DataMember dataMember;
401 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
403 if(!dataMember.isProperty)
405 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
407 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
408 /*if(!dataMember.dataType)
409 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
417 DataMember dataMember;
418 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
420 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
422 if(!isMember && _class.type == bitClass && dataMember.dataType)
424 BitMember bitMember = (BitMember) dataMember;
428 ComputeTypeSize(dataMember.dataType);
430 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
431 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
433 _class.memberOffset = bitMember.pos + bitMember.size;
434 for(d = 0; d<bitMember.size; d++)
440 bitMember.mask = mask << bitMember.pos;
442 else if(dataMember.type == normalMember && dataMember.dataType)
447 // Prevent infinite recursion
448 if(dataMember.dataType.kind != classType ||
449 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
450 _class.type != structClass)))
451 ComputeTypeSize(dataMember.dataType);
453 if(dataMember.dataType.bitFieldCount)
455 bitFields += dataMember.dataType.bitFieldCount;
462 int size = (bitFields + 7) / 8;
466 // TESTING THIS PADDING CODE
469 member.structAlignment = Max(member.structAlignment, alignment);
471 if(member.memberOffset % alignment)
472 member.memberOffset += alignment - (member.memberOffset % alignment);
475 dataMember.offset = member.memberOffset;
476 if(member.type == unionMember)
477 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
480 member.memberOffset += size;
485 // TESTING THIS PADDING CODE
488 _class.structAlignment = Max(_class.structAlignment, alignment);
490 if(_class.memberOffset % alignment)
491 _class.memberOffset += alignment - (_class.memberOffset % alignment);
494 dataMember.offset = _class.memberOffset;
495 _class.memberOffset += size;
499 size = dataMember.dataType.size;
500 alignment = dataMember.dataType.alignment;
505 // TESTING THIS PADDING CODE
508 member.structAlignment = Max(member.structAlignment, alignment);
510 if(member.memberOffset % alignment)
511 member.memberOffset += alignment - (member.memberOffset % alignment);
514 dataMember.offset = member.memberOffset;
515 if(member.type == unionMember)
516 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
519 member.memberOffset += size;
524 // TESTING THIS PADDING CODE
527 _class.structAlignment = Max(_class.structAlignment, alignment);
529 if(_class.memberOffset % alignment)
530 _class.memberOffset += alignment - (_class.memberOffset % alignment);
533 dataMember.offset = _class.memberOffset;
534 _class.memberOffset += size;
541 ComputeClassMembers((Class)dataMember, true);
542 alignment = dataMember.structAlignment;
548 if(member.memberOffset % alignment)
549 member.memberOffset += alignment - (member.memberOffset % alignment);
551 member.structAlignment = Max(member.structAlignment, alignment);
553 dataMember.offset = member.memberOffset;
554 if(member.type == unionMember)
555 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
557 member.memberOffset += dataMember.memberOffset;
563 if(_class.memberOffset % alignment)
564 _class.memberOffset += alignment - (_class.memberOffset % alignment);
565 _class.structAlignment = Max(_class.structAlignment, alignment);
567 dataMember.offset = _class.memberOffset;
568 _class.memberOffset += dataMember.memberOffset;
576 int size = (bitFields + 7) / 8;
580 // TESTING THIS PADDING CODE
583 member.structAlignment = Max(member.structAlignment, alignment);
585 if(member.memberOffset % alignment)
586 member.memberOffset += alignment - (member.memberOffset % alignment);
589 if(member.type == unionMember)
590 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
593 member.memberOffset += size;
598 // TESTING THIS PADDING CODE
601 _class.structAlignment = Max(_class.structAlignment, alignment);
603 if(_class.memberOffset % alignment)
604 _class.memberOffset += alignment - (_class.memberOffset % alignment);
606 _class.memberOffset += size;
611 if(member && member.type == unionMember)
613 member.memberOffset = unionMemberOffset;
618 /*if(_class.type == structClass)
619 _class.size = _class.memberOffset;
623 if(_class.type != bitClass)
626 if(_class.structAlignment)
628 if(_class.memberOffset % _class.structAlignment)
629 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
631 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
635 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
637 if(prop.isProperty && prop.isWatchable)
639 prop.watcherOffset = _class.structSize;
640 _class.structSize += sizeof(OldList);
648 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
650 Class deriv = derivative.data;
652 if(deriv.computeSize)
654 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
655 deriv.offset = /*_class.offset + */_class.structSize;
656 deriv.memberOffset = 0;
657 // ----------------------
659 deriv.structSize = deriv.offset;
661 ComputeClassMembers(deriv, false);
669 FinishTemplatesContext(context);
672 public void ComputeModuleClasses(Module module)
677 for(subModule = module.modules.first; subModule; subModule = subModule.next)
678 ComputeModuleClasses(subModule.data);
679 for(_class = module.classes.first; _class; _class = _class.next)
680 ComputeClassMembers(_class, false);
684 public int ComputeTypeSize(Type type)
686 uint size = type ? type.size : 0;
687 if(!size && type && !type.computing)
689 type.computing = true;
692 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
693 case charType: type.alignment = size = sizeof(char); break;
694 case intType: type.alignment = size = sizeof(int); break;
695 case int64Type: type.alignment = size = sizeof(int64); break;
696 case intPtrType: type.alignment = size = targetBits / 8; break;
697 case intSizeType: type.alignment = size = targetBits / 8; break;
698 case longType: type.alignment = size = sizeof(long); break;
699 case shortType: type.alignment = size = sizeof(short); break;
700 case floatType: type.alignment = size = sizeof(float); break;
701 case doubleType: type.alignment = size = sizeof(double); break;
704 Class _class = type._class ? type._class.registered : null;
706 if(_class && _class.type == structClass)
708 // Ensure all members are properly registered
709 ComputeClassMembers(_class, false);
710 type.alignment = _class.structAlignment;
711 size = _class.structSize;
712 if(type.alignment && size % type.alignment)
713 size += type.alignment - (size % type.alignment);
716 else if(_class && (_class.type == unitClass ||
717 _class.type == enumClass ||
718 _class.type == bitClass))
721 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
722 size = type.alignment = ComputeTypeSize(_class.dataType);
725 size = type.alignment = targetBits / 8; // sizeof(Instance *);
728 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
730 if(type.arraySizeExp)
732 ProcessExpressionType(type.arraySizeExp);
733 ComputeExpression(type.arraySizeExp);
734 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType && type.arraySizeExp.expType.kind != enumType &&
735 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
737 Location oldLoc = yylloc;
738 // bool isConstant = type.arraySizeExp.isConstant;
739 char expression[10240];
740 expression[0] = '\0';
741 type.arraySizeExp.expType = null;
742 yylloc = type.arraySizeExp.loc;
744 PrintExpression(type.arraySizeExp, expression);
745 Compiler_Error($"Array size not constant int (%s)\n", expression);
748 GetInt(type.arraySizeExp, &type.arraySize);
750 else if(type.enumClass)
752 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
754 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
761 // Unimplemented auto size
765 size = ComputeTypeSize(type.type) * type.arraySize;
767 type.alignment = type.type.alignment;
773 for(member = type.members.first; member; member = member.next)
775 uint addSize = ComputeTypeSize(member);
777 member.offset = size;
778 if(member.alignment && size % member.alignment)
779 member.offset += member.alignment - (size % member.alignment);
780 size = member.offset;
782 type.alignment = Max(type.alignment, member.alignment);
785 if(type.alignment && size % type.alignment)
786 size += type.alignment - (size % type.alignment);
792 for(member = type.members.first; member; member = member.next)
794 uint addSize = ComputeTypeSize(member);
796 member.offset = size;
797 if(member.alignment && size % member.alignment)
798 member.offset += member.alignment - (size % member.alignment);
799 size = member.offset;
801 type.alignment = Max(type.alignment, member.alignment);
802 size = Max(size, addSize);
804 if(type.alignment && size % type.alignment)
805 size += type.alignment - (size % type.alignment);
810 TemplateParameter param = type.templateParameter;
811 Type baseType = ProcessTemplateParameterType(param);
814 size = ComputeTypeSize(baseType);
815 type.alignment = baseType.alignment;
818 type.alignment = size = sizeof(uint64);
823 type.alignment = size = sizeof(enum { test });
828 type.alignment = size = targetBits / 8; //sizeof(void *);
833 type.computing = false;
839 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
841 // This function is in need of a major review when implementing private members etc.
842 DataMember topMember = isMember ? (DataMember) _class : null;
847 Context context = isMember ? null : SetupTemplatesContext(_class);
849 *addedPadding = false;
851 if(!isMember && _class.base)
853 maxSize = _class.structSize;
854 //if(_class.base.type != systemClass) // Commented out with new Instance _class
856 // DANGER: Testing this noHeadClass here...
857 if(_class.type == structClass || _class.type == noHeadClass)
858 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
861 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
862 if(maxSize > baseSize)
870 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
872 if(!member.isProperty)
878 if(member.dataTypeString)
880 OldList * specs = MkList(), * decls = MkList();
883 decl = SpecDeclFromString(member.dataTypeString, specs,
884 MkDeclaratorIdentifier(MkIdentifier(member.name)));
885 ListAdd(decls, MkStructDeclarator(decl, null));
886 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
889 member.dataType = ProcessType(specs, decl);
891 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
894 Type type = ProcessType(specs, decl);
895 DeclareType(member.dataType, false, false);
899 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
900 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
901 DeclareStruct(member.dataType._class.string, false);
904 ComputeTypeSize(member.dataType);
905 size = member.dataType.size;
906 alignment = member.dataType.alignment;
910 if(totalSize % alignment)
911 totalSize += alignment - (totalSize % alignment);
920 OldList * specs = MkList(), * list = MkList();
923 AddMembers(list, (Class)member, true, &size, topClass, null);
925 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
926 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
927 alignment = member.structAlignment;
931 if(totalSize % alignment)
932 totalSize += alignment - (totalSize % alignment);
942 if(topMember && topMember.type == unionMember)
943 *retSize = Max(*retSize, totalSize);
945 *retSize += totalSize;
947 else if(totalSize < maxSize && _class.type != systemClass)
950 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
951 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
952 if(totalSize + autoPadding < maxSize)
955 sprintf(sizeString, "%d", maxSize - totalSize);
956 ListAdd(declarations,
957 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
958 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
960 *addedPadding = true;
964 FinishTemplatesContext(context);
965 return topMember ? topMember.memberID : _class.memberID;
968 static int DeclareMembers(Class _class, bool isMember)
970 DataMember topMember = isMember ? (DataMember) _class : null;
973 Context context = isMember ? null : SetupTemplatesContext(_class);
975 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
976 DeclareMembers(_class.base, false);
978 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
980 if(!member.isProperty)
987 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
988 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
989 DeclareStruct(member.dataType._class.string, false);
991 if(!member.dataType && member.dataTypeString)
992 member.dataType = ProcessTypeString(member.dataTypeString, false);
994 DeclareType(member.dataType, false, false);
1000 DeclareMembers((Class)member, true);
1007 FinishTemplatesContext(context);
1009 return topMember ? topMember.memberID : _class.memberID;
1012 void DeclareStruct(char * name, bool skipNoHead)
1014 External external = null;
1015 Symbol classSym = FindClass(name);
1017 if(!inCompiler || !classSym) return;
1019 // We don't need any declaration for bit classes...
1020 if(classSym.registered &&
1021 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1024 /*if(classSym.registered.templateClass)
1025 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1028 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1030 // Add typedef struct
1032 OldList * specifiers, * declarators;
1033 OldList * declarations = null;
1034 char structName[1024];
1035 external = (classSym.registered && classSym.registered.type == structClass) ?
1036 classSym.pointerExternal : classSym.structExternal;
1038 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1039 // Moved this one up because DeclareClass done later will need it
1041 classSym.declaring++;
1043 if(strchr(classSym.string, '<'))
1045 if(classSym.registered.templateClass)
1047 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1048 classSym.declaring--;
1054 DeclareMembers(classSym.registered, false);
1057 FullClassNameCat(structName, name, false);
1060 external = MkExternalDeclaration(null);*/
1064 bool addedPadding = false;
1065 classSym.declaredStructSym = true;
1067 declarations = MkList();
1069 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1071 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1072 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1074 if(!declarations->count || (declarations->count == 1 && addedPadding))
1076 FreeList(declarations, FreeClassDef);
1077 declarations = null;
1080 if(skipNoHead || declarations)
1082 if(external && external.declaration)
1084 ((Specifier)external.declaration.specifiers->first).definitions = declarations;
1086 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1089 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1092 if(classSym.structExternal)
1093 ast->Move(classSym.structExternal, curExternal.prev);
1094 ast->Move(classSym.pointerExternal, curExternal.prev);
1096 classSym.id = curExternal.symbol.idCode;
1097 classSym.idCode = curExternal.symbol.idCode;
1098 // external = classSym.pointerExternal;
1099 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1105 external = MkExternalDeclaration(null);
1107 specifiers = MkList();
1108 declarators = MkList();
1109 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1112 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1113 ListAdd(declarators, MkInitDeclarator(d, null));
1115 external.declaration = decl = MkDeclaration(specifiers, declarators);
1116 if(decl.symbol && !decl.symbol.pointerExternal)
1117 decl.symbol.pointerExternal = external;
1119 // For simple classes, keep the declaration as the external to move around
1120 if(classSym.registered && classSym.registered.type == structClass)
1122 char className[1024];
1123 strcpy(className, "__ecereClass_");
1124 FullClassNameCat(className, classSym.string, true);
1125 MangleClassName(className);
1128 DeclareClass(classSym, className);
1130 external.symbol = classSym;
1131 classSym.pointerExternal = external;
1132 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1133 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1137 char className[1024];
1138 strcpy(className, "__ecereClass_");
1139 FullClassNameCat(className, classSym.string, true);
1140 MangleClassName(className);
1142 // TOFIX: TESTING THIS...
1143 classSym.structExternal = external;
1144 DeclareClass(classSym, className);
1145 external.symbol = classSym;
1149 ast->Insert(curExternal ? curExternal.prev : null, external);
1153 classSym.declaring--;
1155 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1157 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1158 // Moved this one up because DeclareClass done later will need it
1161 classSym.declaring++;
1165 if(classSym.registered)
1166 DeclareMembers(classSym.registered, false);
1169 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1172 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1175 if(classSym.structExternal)
1176 ast->Move(classSym.structExternal, curExternal.prev);
1177 ast->Move(classSym.pointerExternal, curExternal.prev);
1179 classSym.id = curExternal.symbol.idCode;
1180 classSym.idCode = curExternal.symbol.idCode;
1181 // external = classSym.pointerExternal;
1182 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1185 classSym.declaring--;
1190 void DeclareProperty(Property prop, char * setName, char * getName)
1192 Symbol symbol = prop.symbol;
1193 char propName[1024];
1195 strcpy(setName, "__ecereProp_");
1196 FullClassNameCat(setName, prop._class.fullName, false);
1197 strcat(setName, "_Set_");
1198 // strcat(setName, prop.name);
1199 FullClassNameCat(setName, prop.name, true);
1201 strcpy(getName, "__ecereProp_");
1202 FullClassNameCat(getName, prop._class.fullName, false);
1203 strcat(getName, "_Get_");
1204 FullClassNameCat(getName, prop.name, true);
1205 // strcat(getName, prop.name);
1207 strcpy(propName, "__ecereProp_");
1208 FullClassNameCat(propName, prop._class.fullName, false);
1209 strcat(propName, "_");
1210 FullClassNameCat(propName, prop.name, true);
1211 // strcat(propName, prop.name);
1213 // To support "char *" property
1214 MangleClassName(getName);
1215 MangleClassName(setName);
1216 MangleClassName(propName);
1218 if(prop._class.type == structClass)
1219 DeclareStruct(prop._class.fullName, false);
1221 if(!symbol || curExternal.symbol.idCode < symbol.id)
1223 bool imported = false;
1224 bool dllImport = false;
1225 if(!symbol || symbol._import)
1230 if(!prop._class.symbol)
1231 prop._class.symbol = FindClass(prop._class.fullName);
1232 classSym = prop._class.symbol;
1233 if(classSym && !classSym._import)
1235 ModuleImport module;
1237 if(prop._class.module)
1238 module = FindModule(prop._class.module);
1240 module = mainModule;
1242 classSym._import = ClassImport
1244 name = CopyString(prop._class.fullName);
1245 isRemote = prop._class.isRemote;
1247 module.classes.Add(classSym._import);
1249 symbol = prop.symbol = Symbol { };
1250 symbol._import = (ClassImport)PropertyImport
1252 name = CopyString(prop.name);
1253 isVirtual = false; //prop.isVirtual;
1254 hasSet = prop.Set ? true : false;
1255 hasGet = prop.Get ? true : false;
1258 classSym._import.properties.Add(symbol._import);
1261 if(prop._class.module != privateModule && prop._class.module.importType != staticImport)
1267 Context context = SetupTemplatesContext(prop._class);
1268 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1269 FinishTemplatesContext(context);
1275 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1278 OldList * specifiers, * declarators;
1283 Declarator typeDecl;
1284 bool simple = false;
1286 specifiers = MkList();
1287 declarators = MkList();
1290 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1291 MkDeclaratorIdentifier(MkIdentifier("this"))));
1293 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1296 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1299 Context context = SetupTemplatesContext(prop._class);
1300 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1301 FinishTemplatesContext(context);
1304 // Make sure the simple _class's type is declared
1305 for(spec = specifiers->first; spec; spec = spec.next)
1307 if(spec.type == nameSpecifier /*SpecifierClass*/)
1309 if((!typeDecl || typeDecl.type == identifierDeclarator))
1311 Symbol classSym = spec.symbol; // FindClass(spec.name);
1312 symbol._class = classSym.registered;
1313 if(classSym.registered && classSym.registered.type == structClass)
1315 DeclareStruct(spec.name, false);
1323 d = PlugDeclarator(typeDecl, d);
1326 ListAdd(params, MkTypeName(specifiers,
1327 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1328 specifiers = MkList();
1331 d = MkDeclaratorFunction(d, params);
1335 specifiers->Insert(null, MkSpecifier(EXTERN));
1336 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1337 specifiers->Insert(null, MkSpecifier(STATIC));
1339 ListAdd(specifiers, MkSpecifier(VOID));
1341 ListAdd(declarators, MkInitDeclarator(d, null));
1343 decl = MkDeclaration(specifiers, declarators);
1345 external = MkExternalDeclaration(decl);
1346 ast->Insert(curExternal.prev, external);
1347 external.symbol = symbol;
1348 symbol.externalGet = external;
1350 ReplaceThisClassSpecifiers(specifiers, prop._class);
1353 FreeDeclarator(typeDecl);
1357 // Move declaration higher...
1358 ast->Move(symbol.externalGet, curExternal.prev);
1365 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1368 OldList * specifiers, * declarators;
1373 Declarator typeDecl;
1375 declarators = MkList();
1378 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1379 if(!prop.conversion || prop._class.type == structClass)
1381 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1382 MkDeclaratorIdentifier(MkIdentifier("this"))));
1385 specifiers = MkList();
1388 Context context = SetupTemplatesContext(prop._class);
1389 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1390 MkDeclaratorIdentifier(MkIdentifier("value")));
1391 FinishTemplatesContext(context);
1393 ListAdd(params, MkTypeName(specifiers, d));
1395 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1398 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1399 d = MkDeclaratorFunction(d, params);
1401 // Make sure the simple _class's type is declared
1402 for(spec = specifiers->first; spec; spec = spec.next)
1404 if(spec.type == nameSpecifier /*SpecifierClass*/)
1406 if((!typeDecl || typeDecl.type == identifierDeclarator))
1408 Symbol classSym = spec.symbol; // FindClass(spec.name);
1409 symbol._class = classSym.registered;
1410 if(classSym.registered && classSym.registered.type == structClass)
1411 DeclareStruct(spec.name, false);
1416 ListAdd(declarators, MkInitDeclarator(d, null));
1418 specifiers = MkList();
1421 specifiers->Insert(null, MkSpecifier(EXTERN));
1422 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1423 specifiers->Insert(null, MkSpecifier(STATIC));
1425 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1426 if(!prop.conversion || prop._class.type == structClass)
1427 ListAdd(specifiers, MkSpecifier(VOID));
1429 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1431 decl = MkDeclaration(specifiers, declarators);
1433 external = MkExternalDeclaration(decl);
1434 ast->Insert(curExternal.prev, external);
1435 external.symbol = symbol;
1436 symbol.externalSet = external;
1438 ReplaceThisClassSpecifiers(specifiers, prop._class);
1442 // Move declaration higher...
1443 ast->Move(symbol.externalSet, curExternal.prev);
1447 // Property (for Watchers)
1448 if(!symbol.externalPtr)
1452 OldList * specifiers = MkList();
1455 specifiers->Insert(null, MkSpecifier(EXTERN));
1457 specifiers->Insert(null, MkSpecifier(STATIC));
1459 ListAdd(specifiers, MkSpecifierName("Property"));
1462 OldList * list = MkList();
1463 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1464 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1468 strcpy(propName, "__ecerePropM_");
1469 FullClassNameCat(propName, prop._class.fullName, false);
1470 strcat(propName, "_");
1471 // strcat(propName, prop.name);
1472 FullClassNameCat(propName, prop.name, true);
1474 MangleClassName(propName);
1476 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1477 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1479 decl = MkDeclaration(specifiers, list);
1482 external = MkExternalDeclaration(decl);
1483 ast->Insert(curExternal.prev, external);
1484 external.symbol = symbol;
1485 symbol.externalPtr = external;
1489 // Move declaration higher...
1490 ast->Move(symbol.externalPtr, curExternal.prev);
1493 symbol.id = curExternal.symbol.idCode;
1497 // ***************** EXPRESSION PROCESSING ***************************
1498 public Type Dereference(Type source)
1503 if(source.kind == pointerType || source.kind == arrayType)
1506 source.type.refCount++;
1508 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1516 // Support dereferencing of no head classes for now...
1517 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1523 Compiler_Error($"cannot dereference type\n");
1528 static Type Reference(Type source)
1544 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1546 Identifier ident = member.identifiers ? member.identifiers->first : null;
1548 DataMember dataMember = null;
1549 Method method = null;
1550 bool freeType = false;
1552 yylloc = member.loc;
1558 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1562 dataMember = *curMember;
1568 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1569 DataMember _subMemberStack[256];
1570 int _subMemberStackPos = 0;
1572 // FILL MEMBER STACK
1574 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1577 dataMember = thisMember;
1578 if(curMember && thisMember.memberAccess == publicAccess)
1580 *curMember = thisMember;
1581 *curClass = thisMember._class;
1582 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1583 *subMemberStackPos = _subMemberStackPos;
1590 method = eClass_FindMethod(_class, ident.string, privateModule);
1591 if(method && method.type == virtualMethod)
1603 if(!dataMember.dataType && dataMember.dataTypeString)
1605 //Context context = SetupTemplatesContext(dataMember._class);
1606 Context context = SetupTemplatesContext(_class);
1607 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1608 FinishTemplatesContext(context);
1610 type = dataMember.dataType;
1614 // This is for destination type...
1615 if(!method.dataType)
1616 ProcessMethodType(method);
1617 //DeclareMethod(method);
1618 // method.dataType = ((Symbol)method.symbol)->type;
1619 type = method.dataType;
1622 if(ident && ident.next)
1624 for(ident = ident.next; ident && type; ident = ident.next)
1626 if(type.kind == classType)
1628 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1630 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1632 type = dataMember.dataType;
1634 else if(type.kind == structType || type.kind == unionType)
1637 for(memberType = type.members.first; memberType; memberType = memberType.next)
1639 if(!strcmp(memberType.name, ident.string))
1649 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1650 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1653 ClassTemplateParameter curParam = null;
1655 for(sClass = _class; sClass; sClass = sClass.base)
1658 if(sClass.templateClass) sClass = sClass.templateClass;
1659 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1661 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1663 for(sClass = sClass.base; sClass; sClass = sClass.base)
1665 if(sClass.templateClass) sClass = sClass.templateClass;
1666 id += sClass.templateParams.count;
1677 ClassTemplateArgument arg = _class.templateArgs[id];
1678 if(arg.dataTypeString)
1681 type = ProcessTypeString(arg.dataTypeString, false);
1683 if(type && _class.templateClass)
1684 type.passAsTemplate = true;
1690 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1691 exp.destType.refCount++;
1697 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1699 Class expClass = type._class.registered;
1700 Class cClass = null;
1705 char templateString[1024];
1706 ClassTemplateParameter param;
1707 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1708 for(cClass = expClass; cClass; cClass = cClass.base)
1711 if(cClass.templateClass) cClass = cClass.templateClass;
1712 for(param = cClass.templateParams.first; param; param = param.next)
1716 ClassTemplateArgument arg;
1717 for(sClass = cClass.base; sClass; sClass = sClass.base)
1719 if(sClass.templateClass) sClass = sClass.templateClass;
1720 id += sClass.templateParams.count;
1722 arg = expClass.templateArgs[id];
1724 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1726 ClassTemplateParameter cParam;
1727 //int p = numParams - sClass.templateParams.count;
1730 if(sClass.templateClass) sClass = sClass.templateClass;
1732 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1734 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1735 p += nextClass.templateParams.count;
1738 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1740 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1742 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1744 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1745 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1757 strcat(argument, arg.name.string);
1758 strcat(argument, " = ");
1764 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1765 char expString[1024];
1766 OldList * specs = MkList();
1767 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1769 char * string = PrintHexUInt64(arg.expression.ui64);
1770 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1773 ProcessExpressionType(exp);
1774 ComputeExpression(exp);
1775 expString[0] = '\0';
1776 PrintExpression(exp, expString);
1777 strcat(argument, expString);
1779 FreeExpression(exp);
1784 strcat(argument, arg.member.name);
1787 case TemplateParameterType::type:
1789 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1790 strcat(argument, arg.dataTypeString);
1796 if(paramCount) strcat(templateString, ", ");
1797 if(lastParam != p - 1)
1799 strcat(templateString, param.name);
1800 strcat(templateString, " = ");
1802 strcat(templateString, argument);
1811 int len = strlen(templateString);
1812 if(templateString[len-1] == '<')
1816 if(templateString[len-1] == '>')
1817 templateString[len++] = ' ';
1818 templateString[len++] = '>';
1820 templateString[len++] = '\0';
1823 Context context = SetupTemplatesContext(_class);
1824 if(freeType) FreeType(type);
1825 type = ProcessTypeString(templateString, false);
1827 FinishTemplatesContext(context);
1831 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1833 ProcessExpressionType(member.initializer.exp);
1834 if(!member.initializer.exp.expType)
1838 char expString[10240];
1839 expString[0] = '\0';
1840 PrintExpression(member.initializer.exp, expString);
1841 ChangeCh(expString, '\n', ' ');
1842 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1845 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1846 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1848 Compiler_Error($"incompatible instance method %s\n", ident.string);
1851 else if(member.initializer)
1854 FreeType(member.exp.destType);
1855 member.exp.destType = type;
1856 if(member.exp.destType)
1857 member.exp.destType.refCount++;
1858 ProcessExpressionType(member.exp);
1861 ProcessInitializer(member.initializer, type);
1863 if(freeType) FreeType(type);
1867 if(_class && _class.type == unitClass)
1869 if(member.initializer)
1872 FreeType(member.exp.destType);
1873 member.exp.destType = MkClassType(_class.fullName);
1874 ProcessExpressionType(member.initializer, type);
1876 Type type = MkClassType(_class.fullName);
1877 ProcessInitializer(member.initializer, type);
1883 if(member.initializer)
1885 //ProcessExpressionType(member.exp);
1886 ProcessInitializer(member.initializer, null);
1892 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1896 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1898 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1902 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1907 void ProcessInstantiationType(Instantiation inst)
1912 MembersInit members;
1913 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1916 /*if(!inst._class.symbol)
1917 inst._class.symbol = FindClass(inst._class.name);*/
1918 classSym = inst._class.symbol;
1919 _class = classSym ? classSym.registered : null;
1921 // DANGER: Patch for mutex not declaring its struct when not needed
1922 if(!_class || _class.type != noHeadClass)
1923 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1925 afterExternal = afterExternal ? afterExternal : curExternal;
1928 ProcessExpressionType(inst.exp);
1930 inst.isConstant = true;
1933 DataMember curMember = null;
1934 Class curClass = null;
1935 DataMember subMemberStack[256];
1936 int subMemberStackPos = 0;
1938 for(members = inst.members->first; members; members = members.next)
1940 switch(members.type)
1942 case methodMembersInit:
1945 static uint instMethodID = 0;
1946 External external = curExternal;
1947 Context context = curContext;
1948 Declarator declarator = members.function.declarator;
1949 Identifier nameID = GetDeclId(declarator);
1950 char * unmangled = nameID ? nameID.string : null;
1952 External createdExternal = null;
1957 //members.function.dontMangle = true;
1958 strcpy(name, "__ecereInstMeth_");
1959 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
1961 strcat(name, nameID.string);
1963 sprintf(number, "_%08d", instMethodID++);
1964 strcat(name, number);
1965 nameID.string = CopyString(name);
1968 // Do modifications here...
1971 Symbol symbol = declarator.symbol;
1972 Method method = eClass_FindMethod(_class, unmangled, privateModule);
1974 if(method && method.type == virtualMethod)
1976 symbol.method = method;
1977 ProcessMethodType(method);
1979 if(!symbol.type.thisClass)
1981 if(method.dataType.thisClass && currentClass &&
1982 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
1984 if(!currentClass.symbol)
1985 currentClass.symbol = FindClass(currentClass.fullName);
1986 symbol.type.thisClass = currentClass.symbol;
1991 _class.symbol = FindClass(_class.fullName);
1992 symbol.type.thisClass = _class.symbol;
1995 // TESTING THIS HERE:
1996 DeclareType(symbol.type, true, true);
2001 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2002 unmangled, classSym.string);
2006 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2007 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2011 FreeSpecifier(nameID._class);
2012 nameID._class = null;
2018 Type type = declarator.symbol.type;
2019 External oldExternal = curExternal;
2021 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2022 // *** It was commented out for problems such as
2024 class VirtualDesktop : Window
2026 clientSize = Size { };
2037 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2039 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2042 if(strcmp(declarator.symbol.string, name))
2044 printf("TOCHECK: Look out for this\n");
2045 delete declarator.symbol.string;
2046 declarator.symbol.string = CopyString(name);
2049 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2051 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2052 excludedSymbols->Remove(declarator.symbol);
2053 globalContext.symbols.Add((BTNode)declarator.symbol);
2054 if(strstr(declarator.symbol.string), "::")
2055 globalContext.hasNameSpace = true;
2060 //curExternal = curExternal.prev;
2061 //afterExternal = afterExternal->next;
2063 //ProcessFunction(afterExternal->function);
2065 //curExternal = afterExternal;
2067 External externalDecl;
2068 externalDecl = MkExternalDeclaration(null);
2069 ast->Insert(oldExternal.prev, externalDecl);
2071 // Which function does this process?
2072 if(createdExternal.function)
2074 ProcessFunction(createdExternal.function);
2076 //curExternal = oldExternal;
2079 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2081 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2082 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2084 //externalDecl = MkExternalDeclaration(decl);
2086 //***** ast->Insert(external.prev, externalDecl);
2087 //ast->Insert(curExternal.prev, externalDecl);
2088 externalDecl.declaration = decl;
2089 if(decl.symbol && !decl.symbol.pointerExternal)
2090 decl.symbol.pointerExternal = externalDecl;
2092 // Trying this out...
2093 declarator.symbol.pointerExternal = externalDecl;
2100 curExternal = declarator.symbol.pointerExternal;
2101 ProcessFunction((FunctionDefinition)members.function);
2103 curExternal = external;
2104 curContext = context;
2108 FreeClassFunction(members.function);
2110 // In this pass, turn this into a MemberInitData
2111 exp = QMkExpId(name);
2112 members.type = dataMembersInit;
2113 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2119 case dataMembersInit:
2121 if(members.dataMembers && classSym)
2124 Location oldyyloc = yylloc;
2125 for(member = members.dataMembers->first; member; member = member.next)
2127 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2128 if(member.initializer && !member.initializer.isConstant)
2129 inst.isConstant = false;
2141 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2143 // OPTIMIZATIONS: TESTING THIS...
2146 if(type.kind == functionType)
2151 for(param = type.params.first; param; param = param.next)
2152 DeclareType(param, declarePointers, true);
2154 DeclareType(type.returnType, declarePointers, true);
2156 else if(type.kind == pointerType && declarePointers)
2157 DeclareType(type.type, declarePointers, false);
2158 else if(type.kind == classType)
2160 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2161 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2163 else if(type.kind == structType || type.kind == unionType)
2166 for(member = type.members.first; member; member = member.next)
2167 DeclareType(member, false, false);
2169 else if(type.kind == arrayType)
2170 DeclareType(type.arrayType, declarePointers, false);
2174 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2176 ClassTemplateArgument * arg = null;
2178 ClassTemplateParameter curParam = null;
2180 for(sClass = _class; sClass; sClass = sClass.base)
2183 if(sClass.templateClass) sClass = sClass.templateClass;
2184 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2186 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2188 for(sClass = sClass.base; sClass; sClass = sClass.base)
2190 if(sClass.templateClass) sClass = sClass.templateClass;
2191 id += sClass.templateParams.count;
2201 arg = &_class.templateArgs[id];
2202 if(arg && param.type == type)
2203 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2208 public Context SetupTemplatesContext(Class _class)
2210 Context context = PushContext();
2211 context.templateTypesOnly = true;
2212 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2214 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2215 for(; param; param = param.next)
2217 if(param.type == type && param.identifier)
2219 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2220 curContext.templateTypes.Add((BTNode)type);
2227 for(sClass = _class; sClass; sClass = sClass.base)
2229 ClassTemplateParameter p;
2230 for(p = sClass.templateParams.first; p; p = p.next)
2232 //OldList * specs = MkList();
2233 //Declarator decl = null;
2234 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2237 TemplateParameter param = p.param;
2241 // ADD DATA TYPE HERE...
2242 p.param = param = TemplateParameter
2244 identifier = MkIdentifier(p.name), type = p.type,
2245 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2248 type = TemplatedType { key = (uintptr)p.name, param = param };
2249 curContext.templateTypes.Add((BTNode)type);
2257 public void FinishTemplatesContext(Context context)
2259 PopContext(context);
2260 FreeContext(context);
2264 public void ProcessMethodType(Method method)
2266 if(!method.dataType)
2268 Context context = SetupTemplatesContext(method._class);
2270 method.dataType = ProcessTypeString(method.dataTypeString, false);
2272 FinishTemplatesContext(context);
2274 if(method.type != virtualMethod && method.dataType)
2276 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2278 if(!method._class.symbol)
2279 method._class.symbol = FindClass(method._class.fullName);
2280 method.dataType.thisClass = method._class.symbol;
2284 // Why was this commented out? Working fine without now...
2287 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2288 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2295 char * par = strstr(type, "(");
2296 char * classOp = null;
2301 for(c = par-type-1; c >= 0; c++)
2303 if(type[c] == ':' && type[c+1] == ':')
2305 classOp = type + c - 1;
2306 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2313 else if(!isspace(type[c]))
2320 int typeLen = strlen(type);
2321 memcpy(temp, classOp, classOpLen);
2322 temp[classOpLen] = '\0';
2324 _class = eSystem_FindClass(module, temp);
2327 method.dataTypeString = new char[typeLen - classOpLen + 1];
2328 memcpy(method.dataTypeString, type, classOp - type);
2329 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2332 method.dataTypeString = type;
2338 public void ProcessPropertyType(Property prop)
2342 Context context = SetupTemplatesContext(prop._class);
2343 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2344 FinishTemplatesContext(context);
2348 public void DeclareMethod(Method method, char * name)
2350 Symbol symbol = method.symbol;
2351 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2353 bool imported = false;
2354 bool dllImport = false;
2356 if(!method.dataType)
2357 method.dataType = ProcessTypeString(method.dataTypeString, false);
2359 if(!symbol || symbol._import || method.type == virtualMethod)
2361 if(!symbol || method.type == virtualMethod)
2364 if(!method._class.symbol)
2365 method._class.symbol = FindClass(method._class.fullName);
2366 classSym = method._class.symbol;
2367 if(!classSym._import)
2369 ModuleImport module;
2371 if(method._class.module && method._class.module.name)
2372 module = FindModule(method._class.module);
2374 module = mainModule;
2375 classSym._import = ClassImport
2377 name = CopyString(method._class.fullName);
2378 isRemote = method._class.isRemote;
2380 module.classes.Add(classSym._import);
2384 symbol = method.symbol = Symbol { };
2388 symbol._import = (ClassImport)MethodImport
2390 name = CopyString(method.name);
2391 isVirtual = method.type == virtualMethod;
2393 classSym._import.methods.Add(symbol._import);
2397 // Set the symbol type
2401 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2403 else if(type.thisClass == (void *)-1)
2405 type.thisClass = null;
2408 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2409 symbol.type = method.dataType;
2410 if(symbol.type) symbol.type.refCount++;
2413 if(!method.thisClass || strcmp(method.thisClass, "void"))
2414 symbol.type.params.Insert(null,
2415 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2418 if(!method.dataType.dllExport)
2421 if(method._class.module != privateModule && method._class.module.importType != staticImport)
2427 if(!method.dataType)
2428 method.dataType = ((Symbol)method.symbol).type;
2429 //ProcessMethodType(method);
2432 if(method.type != virtualMethod && method.dataType)
2433 DeclareType(method.dataType, true, true);
2435 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2437 // We need a declaration here :)
2439 OldList * specifiers, * declarators;
2441 Declarator funcDecl;
2444 specifiers = MkList();
2445 declarators = MkList();
2449 ListAdd(specifiers, MkSpecifier(EXTERN));
2450 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2451 ListAdd(specifiers, MkSpecifier(STATIC));
2453 if(method.type == virtualMethod)
2455 ListAdd(specifiers, MkSpecifier(INT));
2456 d = MkDeclaratorIdentifier(MkIdentifier(name));
2460 d = MkDeclaratorIdentifier(MkIdentifier(name));
2463 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2465 Context context = SetupTemplatesContext(method._class);
2466 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2467 FinishTemplatesContext(context);
2469 funcDecl = GetFuncDecl(d);
2473 Specifier spec, next;
2474 for(spec = specifiers->first; spec; spec = next)
2477 if(spec.type == extendedSpecifier)
2479 specifiers->Remove(spec);
2480 FreeSpecifier(spec);
2485 // Add this parameter if not a static method
2486 if(method.dataType && !method.dataType.staticMethod)
2488 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2490 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2491 TypeName thisParam = MkTypeName(MkListOne(
2492 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2493 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2494 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2495 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2497 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2499 TypeName param = funcDecl.function.parameters->first;
2500 funcDecl.function.parameters->Remove(param);
2501 FreeTypeName(param);
2504 if(!funcDecl.function.parameters)
2505 funcDecl.function.parameters = MkList();
2506 funcDecl.function.parameters->Insert(null, thisParam);
2509 // Make sure we don't have empty parameter declarations for static methods...
2511 else if(!funcDecl.function.parameters)
2513 funcDecl.function.parameters = MkList();
2514 funcDecl.function.parameters->Insert(null,
2515 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2519 ProcessDeclarator(d);
2521 ListAdd(declarators, MkInitDeclarator(d, null));
2523 decl = MkDeclaration(specifiers, declarators);
2525 ReplaceThisClassSpecifiers(specifiers, method._class);
2527 // Keep a different symbol for the function definition than the declaration...
2528 if(symbol.pointerExternal)
2530 Symbol functionSymbol { };
2534 *functionSymbol = *symbol;
2535 functionSymbol.string = CopyString(symbol.string);
2536 if(functionSymbol.type)
2537 functionSymbol.type.refCount++;
2540 excludedSymbols->Add(functionSymbol);
2541 symbol.pointerExternal.symbol = functionSymbol;
2543 external = MkExternalDeclaration(decl);
2545 ast->Insert(curExternal ? curExternal.prev : null, external);
2546 external.symbol = symbol;
2547 symbol.pointerExternal = external;
2551 // Move declaration higher...
2552 ast->Move(symbol.pointerExternal, curExternal.prev);
2555 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2559 char * ReplaceThisClass(Class _class)
2561 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2565 ClassTemplateParameter param;
2568 char className[1024];
2569 strcpy(className, _class.fullName);
2570 for(param = _class.templateParams.first; param; param = param.next)
2572 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2574 if(first) strcat(className, "<");
2575 if(!first) strcat(className, ", ");
2576 if(lastParam + 1 != p)
2578 strcat(className, param.name);
2579 strcat(className, " = ");
2581 strcat(className, param.name);
2589 int len = strlen(className);
2590 if(className[len-1] == '>') className[len++] = ' ';
2591 className[len++] = '>';
2592 className[len++] = '\0';
2594 return CopyString(className);
2597 return CopyString(_class.fullName);
2600 Type ReplaceThisClassType(Class _class)
2602 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2606 ClassTemplateParameter param;
2608 char className[1024];
2609 strcpy(className, _class.fullName);
2611 for(param = _class.templateParams.first; param; param = param.next)
2613 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2615 if(first) strcat(className, "<");
2616 if(!first) strcat(className, ", ");
2617 if(lastParam + 1 != p)
2619 strcat(className, param.name);
2620 strcat(className, " = ");
2622 strcat(className, param.name);
2630 int len = strlen(className);
2631 if(className[len-1] == '>') className[len++] = ' ';
2632 className[len++] = '>';
2633 className[len++] = '\0';
2635 return MkClassType(className);
2636 //return ProcessTypeString(className, false);
2640 return MkClassType(_class.fullName);
2641 //return ProcessTypeString(_class.fullName, false);
2645 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2647 if(specs != null && _class)
2650 for(spec = specs.first; spec; spec = spec.next)
2652 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2654 spec.type = nameSpecifier;
2655 spec.name = ReplaceThisClass(_class);
2656 spec.symbol = FindClass(spec.name); //_class.symbol;
2662 // Returns imported or not
2663 bool DeclareFunction(GlobalFunction function, char * name)
2665 Symbol symbol = function.symbol;
2666 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2668 bool imported = false;
2669 bool dllImport = false;
2671 if(!function.dataType)
2673 function.dataType = ProcessTypeString(function.dataTypeString, false);
2674 if(!function.dataType.thisClass)
2675 function.dataType.staticMethod = true;
2682 ModuleImport module = FindModule(function.module);
2683 // WARNING: This is not added anywhere...
2684 symbol = function.symbol = Symbol { };
2688 if(!function.dataType.dllExport)
2690 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2691 module.functions.Add(symbol._import);
2694 // Set the symbol type
2696 symbol.type = ProcessTypeString(function.dataTypeString, false);
2697 if(!symbol.type.thisClass)
2698 symbol.type.staticMethod = true;
2701 imported = symbol._import ? true : false;
2702 if(imported && function.module != privateModule && function.module.importType != staticImport)
2706 DeclareType(function.dataType, true, true);
2710 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2712 // We need a declaration here :)
2714 OldList * specifiers, * declarators;
2716 Declarator funcDecl;
2719 specifiers = MkList();
2720 declarators = MkList();
2723 ListAdd(specifiers, MkSpecifier(EXTERN));
2726 ListAdd(specifiers, MkSpecifier(STATIC));
2729 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2732 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2734 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2735 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2736 if(function.module.importType == staticImport)
2739 for(spec = specifiers->first; spec; spec = spec.next)
2740 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2742 specifiers->Remove(spec);
2743 FreeSpecifier(spec);
2748 funcDecl = GetFuncDecl(d);
2750 // Make sure we don't have empty parameter declarations for static methods...
2751 if(funcDecl && !funcDecl.function.parameters)
2753 funcDecl.function.parameters = MkList();
2754 funcDecl.function.parameters->Insert(null,
2755 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2758 ListAdd(declarators, MkInitDeclarator(d, null));
2761 Context oldCtx = curContext;
2762 curContext = globalContext;
2763 decl = MkDeclaration(specifiers, declarators);
2764 curContext = oldCtx;
2767 // Keep a different symbol for the function definition than the declaration...
2768 if(symbol.pointerExternal)
2770 Symbol functionSymbol { };
2773 *functionSymbol = *symbol;
2774 functionSymbol.string = CopyString(symbol.string);
2775 if(functionSymbol.type)
2776 functionSymbol.type.refCount++;
2779 excludedSymbols->Add(functionSymbol);
2781 symbol.pointerExternal.symbol = functionSymbol;
2783 external = MkExternalDeclaration(decl);
2785 ast->Insert(curExternal.prev, external);
2786 external.symbol = symbol;
2787 symbol.pointerExternal = external;
2791 // Move declaration higher...
2792 ast->Move(symbol.pointerExternal, curExternal.prev);
2796 symbol.id = curExternal.symbol.idCode;
2799 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2802 void DeclareGlobalData(GlobalData data)
2804 Symbol symbol = data.symbol;
2805 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2810 symbol = data.symbol = Symbol { };
2813 data.dataType = ProcessTypeString(data.dataTypeString, false);
2814 DeclareType(data.dataType, true, true);
2817 if(!symbol.pointerExternal)
2819 // We need a declaration here :)
2821 OldList * specifiers, * declarators;
2825 specifiers = MkList();
2826 declarators = MkList();
2828 ListAdd(specifiers, MkSpecifier(EXTERN));
2829 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2830 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2832 ListAdd(declarators, MkInitDeclarator(d, null));
2834 decl = MkDeclaration(specifiers, declarators);
2835 external = MkExternalDeclaration(decl);
2837 ast->Insert(curExternal.prev, external);
2838 external.symbol = symbol;
2839 symbol.pointerExternal = external;
2843 // Move declaration higher...
2844 ast->Move(symbol.pointerExternal, curExternal.prev);
2848 symbol.id = curExternal.symbol.idCode;
2853 class Conversion : struct
2855 Conversion prev, next;
2861 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2865 // Property convert;
2867 if(source.kind == templateType && dest.kind != templateType)
2869 Type type = ProcessTemplateParameterType(source.templateParameter);
2870 if(type) source = type;
2873 if(dest.kind == templateType && source.kind != templateType)
2875 Type type = ProcessTemplateParameterType(dest.templateParameter);
2876 if(type) dest = type;
2879 if(dest.classObjectType == typedObject)
2881 if(source.classObjectType != anyObject)
2885 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2886 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2894 if(source.classObjectType == anyObject)
2896 if(dest.classObjectType == anyObject && source.classObjectType != typedObject)
2900 if((dest.kind == structType && source.kind == structType) ||
2901 (dest.kind == unionType && source.kind == unionType))
2903 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2904 (source.members.first && source.members.first == dest.members.first))
2908 if(dest.kind == ellipsisType && source.kind != voidType)
2911 if(dest.kind == pointerType && dest.type.kind == voidType &&
2912 ((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))
2913 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2915 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2917 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2919 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2920 ((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))
2921 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2923 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2925 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2928 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2930 if(source._class.registered && source._class.registered.type == unitClass)
2932 if(conversions != null)
2934 if(source._class.registered == dest._class.registered)
2939 Class sourceBase, destBase;
2940 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2941 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2942 if(sourceBase == destBase)
2946 // Don't match enum inheriting from other enum if resolving enumeration values
2947 // TESTING: !dest.classObjectType
2948 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2950 (!source._class.registered || source._class.registered.type != enumClass) ||
2951 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2955 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2957 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2958 ((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)
2960 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2968 // JUST ADDED THIS...
2969 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
2974 // Just added this for Straight conversion of ColorAlpha => Color
2975 if(source.kind == classType)
2978 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
2981 for(convert = _class.conversions.first; convert; convert = convert.next)
2983 if(convert.memberAccess == publicAccess || _class.module == privateModule)
2985 Conversion after = (conversions != null) ? conversions.last : null;
2987 if(!convert.dataType)
2988 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
2989 if(MatchTypes(convert.dataType, dest, conversions, null, null, false, true, false, true))
2991 if(!conversions && !convert.Get)
2993 else if(conversions != null)
2995 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
2996 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
2997 (dest.kind != classType || dest._class.registered != _class.base))
3001 Conversion conv { convert = convert, isGet = true };
3002 // conversions.Add(conv);
3003 conversions.Insert(after, conv);
3015 if(dest.kind == classType)
3018 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3021 for(convert = _class.conversions.first; convert; convert = convert.next)
3023 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3025 // Conversion after = (conversions != null) ? conversions.last : null;
3027 if(!convert.dataType)
3028 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3029 // Just added this equality check to prevent recursion.... Make it safer?
3030 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3031 if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
3033 if(!conversions && !convert.Set)
3035 else if(conversions != null)
3037 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3038 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3039 (source.kind != classType || source._class.registered != _class.base))
3043 // *** Testing this! ***
3044 Conversion conv { convert = convert };
3045 conversions.Add(conv);
3046 //conversions.Insert(after, conv);
3054 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3056 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3057 (source.kind != classType || source._class.registered.type != structClass))
3061 // TESTING THIS... IS THIS OK??
3062 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3064 if(!dest._class.registered.dataType)
3065 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3066 // Only support this for classes...
3067 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3068 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3070 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3079 if(source.kind == classType)
3082 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3085 for(convert = _class.conversions.first; convert; convert = convert.next)
3087 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3089 Conversion after = (conversions != null) ? conversions.last : null;
3091 if(!convert.dataType)
3092 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3093 if(convert.dataType != source && MatchTypes(convert.dataType, dest, conversions, null, null, true, true, false, true))
3095 if(!conversions && !convert.Get)
3097 else if(conversions != null)
3099 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3100 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3101 (dest.kind != classType || dest._class.registered != _class.base))
3105 Conversion conv { convert = convert, isGet = true };
3107 // conversions.Add(conv);
3108 conversions.Insert(after, conv);
3117 // TESTING THIS... IS THIS OK??
3118 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3120 if(!source._class.registered.dataType)
3121 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3122 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, true, false, false))
3130 if(source.kind == classType || source.kind == subClassType)
3132 else if(dest.kind == source.kind &&
3133 (dest.kind != structType && dest.kind != unionType &&
3134 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3136 // RECENTLY ADDED THESE
3137 else if(dest.kind == doubleType && source.kind == floatType)
3139 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3141 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3143 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3145 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3147 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3149 else if(source.kind == enumType &&
3150 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3152 else if(dest.kind == enumType &&
3153 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3155 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3156 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3158 Type paramSource, paramDest;
3160 if(dest.kind == methodType)
3161 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3162 if(source.kind == methodType)
3163 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3165 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3166 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3167 if(dest.kind == methodType)
3168 dest = dest.method.dataType;
3169 if(source.kind == methodType)
3170 source = source.method.dataType;
3172 paramSource = source.params.first;
3173 if(paramSource && paramSource.kind == voidType) paramSource = null;
3174 paramDest = dest.params.first;
3175 if(paramDest && paramDest.kind == voidType) paramDest = null;
3178 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3179 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3181 // Source thisClass must be derived from destination thisClass
3182 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3183 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3185 if(paramDest && paramDest.kind == classType)
3186 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3188 Compiler_Error($"method class should not take an object\n");
3191 paramDest = paramDest.next;
3193 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3195 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3199 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3201 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3207 // THIS WAS BACKWARDS:
3208 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3209 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3212 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3214 Compiler_Error($"overriding class expected to be derived from method class\n");
3218 paramSource = paramSource.next;
3224 // Source thisClass must be derived from destination thisClass
3225 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3227 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3233 // THIS WAS BACKWARDS TOO??
3234 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3235 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3238 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3240 //Compiler_Error($"overriding class expected to be derived from method class\n");
3248 // Source return type must be derived from destination return type
3249 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3251 Compiler_Warning($"incompatible return type for function\n");
3257 for(; paramDest; paramDest = paramDest.next)
3261 //Compiler_Warning($"not enough parameters\n");
3262 Compiler_Error($"not enough parameters\n");
3266 Type paramDestType = paramDest;
3267 Type paramSourceType = paramSource;
3268 Type type = paramDestType;
3270 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3271 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3272 paramSource.kind != templateType)
3275 ClassTemplateParameter curParam = null;
3277 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3280 if(sClass.templateClass) sClass = sClass.templateClass;
3281 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3283 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3285 for(sClass = sClass.base; sClass; sClass = sClass.base)
3287 if(sClass.templateClass) sClass = sClass.templateClass;
3288 id += sClass.templateParams.count;
3299 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3300 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3304 // paramDest must be derived from paramSource
3305 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3306 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3310 PrintType(paramDest, type, false, true);
3311 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3313 if(paramDestType != paramDest)
3314 FreeType(paramDestType);
3317 if(paramDestType != paramDest)
3318 FreeType(paramDestType);
3321 paramSource = paramSource.next;
3325 Compiler_Error($"too many parameters\n");
3330 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3334 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3335 (source.kind == arrayType || source.kind == pointerType))
3337 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3344 static void FreeConvert(Conversion convert)
3346 if(convert.resultType)
3347 FreeType(convert.resultType);
3350 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3351 char * string, OldList conversions)
3355 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3357 Class _class = link.data;
3358 if(_class.type == enumClass)
3360 OldList converts { };
3362 type.kind = classType;
3365 _class.symbol = FindClass(_class.fullName);
3366 type._class = _class.symbol;
3368 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3371 Class enumClass = eSystem_FindClass(privateModule, "enum");
3375 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3377 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3378 for(value = e.values.first; value; value = value.next)
3380 if(!strcmp(value.name, string))
3385 FreeExpContents(sourceExp);
3386 FreeType(sourceExp.expType);
3388 sourceExp.isConstant = true;
3389 sourceExp.expType = MkClassType(baseClass.fullName);
3393 sourceExp.type = constantExp;
3394 if(!strcmp(baseClass.dataTypeString, "int"))
3395 sprintf(constant, "%d",(int)value.data);
3397 sprintf(constant, "0x%X",(int)value.data);
3398 sourceExp.constant = CopyString(constant);
3399 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3402 while(converts.first)
3404 Conversion convert = converts.first;
3405 converts.Remove(convert);
3406 conversions.Add(convert);
3415 converts.Free(FreeConvert);
3419 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3420 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3425 public bool ModuleVisibility(Module searchIn, Module searchFor)
3427 SubModule subModule;
3429 if(searchFor == searchIn)
3432 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3434 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3436 if(ModuleVisibility(subModule.module, searchFor))
3443 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3447 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3449 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3451 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3454 for(module = mainModule.application.allModules.first; module; module = module.next)
3456 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3462 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3464 Type source = sourceExp.expType;
3465 Type realDest = dest;
3466 Type backupSourceExpType = null;
3468 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3471 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3473 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3475 Class sourceBase, destBase;
3476 for(sourceBase = source._class.registered;
3477 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3478 sourceBase = sourceBase.base);
3479 for(destBase = dest._class.registered;
3480 destBase && destBase.base && destBase.base.type != systemClass;
3481 destBase = destBase.base);
3482 //if(source._class.registered == dest._class.registered)
3483 if(sourceBase == destBase)
3492 int64 value = MAXINT;
3497 if(sourceExp.type == constantExp)
3500 value = strtoll(sourceExp.constant, null, 0);
3502 value = strtoull(sourceExp.constant, null, 0);
3504 else if(sourceExp.type == opExp && sourceExp.op.op == '-' && !sourceExp.op.exp1 && sourceExp.op.exp2 && sourceExp.op.exp2.type == constantExp)
3507 value = -strtoll(sourceExp.op.exp2.constant, null, 0);
3509 value = -strtoull(sourceExp.op.exp2.constant, null, 0);
3512 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3513 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3516 source = Type { kind = intType, isSigned = false, refCount = 1 };
3519 if(dest.kind == classType)
3521 Class _class = dest._class ? dest._class.registered : null;
3523 if(_class && _class.type == unitClass)
3525 if(source.kind != classType)
3528 Type tempDest, tempSource;
3530 for(; _class.base.type != systemClass; _class = _class.base);
3532 tempDest = tempType;
3534 tempType.kind = classType;
3536 _class.symbol = FindClass(_class.fullName);
3538 tempType._class = _class.symbol;
3539 tempType.truth = dest.truth;
3541 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3543 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3544 backupSourceExpType = sourceExp.expType;
3545 sourceExp.expType = dest; dest.refCount++;
3546 //sourceExp.expType = MkClassType(_class.fullName);
3554 // Why wasn't there something like this?
3555 if(_class && _class.type == bitClass && source.kind != classType)
3557 if(!dest._class.registered.dataType)
3558 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3559 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3562 FreeType(sourceExp.expType);
3563 source = sourceExp.expType = MkClassType(dest._class.string);
3566 //source.kind = classType;
3567 //source._class = dest._class;
3571 // Adding two enumerations
3573 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3575 if(!source._class.registered.dataType)
3576 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3577 if(!dest._class.registered.dataType)
3578 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3580 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3583 source = sourceExp.expType = MkClassType(dest._class.string);
3586 //source.kind = classType;
3587 //source._class = dest._class;
3591 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3593 OldList * specs = MkList();
3597 ReadString(string, sourceExp.string);
3598 decl = SpecDeclFromString(string, specs, null);
3600 FreeExpContents(sourceExp);
3601 FreeType(sourceExp.expType);
3603 sourceExp.type = classExp;
3604 sourceExp._classExp.specifiers = specs;
3605 sourceExp._classExp.decl = decl;
3606 sourceExp.expType = dest;
3611 if(backupSourceExpType) FreeType(backupSourceExpType);
3615 else if(source.kind == classType)
3617 Class _class = source._class ? source._class.registered : null;
3619 if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3622 if(dest.kind != classType)
3624 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3625 if(!source._class.registered.dataType)
3626 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3629 dest = MkClassType(source._class.string);
3630 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3631 // dest = MkClassType(source._class.string);
3635 if(dest.kind != classType)
3638 Type tempDest, tempSource;
3640 if(!source._class.registered.dataType)
3641 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3643 for(; _class.base.type != systemClass; _class = _class.base);
3645 tempSource = tempType;
3646 tempType.kind = classType;
3647 tempType._class = FindClass(_class.fullName);
3648 tempType.truth = source.truth;
3649 tempType.classObjectType = source.classObjectType;
3652 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3654 // PUT THIS BACK TESTING UNITS?
3655 if(conversions.last)
3657 ((Conversion)(conversions.last)).resultType = dest;
3661 FreeType(sourceExp.expType);
3662 sourceExp.expType = MkClassType(_class.fullName);
3663 sourceExp.expType.truth = source.truth;
3664 sourceExp.expType.classObjectType = source.classObjectType;
3666 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3668 if(!sourceExp.destType)
3670 FreeType(sourceExp.destType);
3671 sourceExp.destType = sourceExp.expType;
3672 if(sourceExp.expType)
3673 sourceExp.expType.refCount++;
3676 //source = _class.dataType;
3679 // TOCHECK: TESTING THIS NEW CODE
3680 if(!_class.dataType)
3681 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3683 dest = MkClassType(source._class.string);
3684 dest.truth = source.truth;
3685 dest.classObjectType = source.classObjectType;
3688 source = _class.dataType;
3698 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3708 if(source.kind == classType)
3710 Class _class = source._class.registered;
3711 if(_class.type == unitClass)
3713 if(!_class.dataType)
3714 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3715 source = _class.dataType;
3719 if(dest.kind == classType)
3721 Class _class = dest._class ? dest._class.registered : null;
3722 if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
3723 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3725 if(_class.type == normalClass || _class.type == noHeadClass)
3727 Expression newExp { };
3728 *newExp = *sourceExp;
3729 if(sourceExp.destType) sourceExp.destType.refCount++;
3730 if(sourceExp.expType) sourceExp.expType.refCount++;
3731 sourceExp.type = castExp;
3732 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3733 sourceExp.cast.exp = newExp;
3734 FreeType(sourceExp.expType);
3735 sourceExp.expType = null;
3736 ProcessExpressionType(sourceExp);
3738 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3741 FreeType(sourceExp.expType);
3742 sourceExp.expType = dest;
3746 if(inCompiler) FreeType(dest);
3748 if(backupSourceExpType) FreeType(backupSourceExpType);
3752 if(!_class.dataType)
3753 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3755 dest = _class.dataType;
3759 // Accept lower precision types for units, since we want to keep the unit type
3760 if(dest.kind == doubleType &&
3761 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3762 source.kind == charType || source.kind == _BoolType))
3764 specs = MkListOne(MkSpecifier(DOUBLE));
3766 else if(dest.kind == floatType &&
3767 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3768 source.kind == _BoolType || source.kind == doubleType))
3770 specs = MkListOne(MkSpecifier(FLOAT));
3772 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3773 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3776 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3777 ListAdd(specs, MkSpecifier(INT64));
3779 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3780 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3783 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3784 ListAdd(specs, MkSpecifier(INT));
3786 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3787 source.kind == floatType || source.kind == doubleType))
3790 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3791 ListAdd(specs, MkSpecifier(SHORT));
3793 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3794 source.kind == floatType || source.kind == doubleType))
3797 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3798 ListAdd(specs, MkSpecifier(CHAR));
3804 if(backupSourceExpType)
3806 // Failed to convert: revert previous exp type
3807 if(sourceExp.expType) FreeType(sourceExp.expType);
3808 sourceExp.expType = backupSourceExpType;
3813 else if(dest.kind == doubleType &&
3814 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3815 source.kind == _BoolType || source.kind == charType))
3817 specs = MkListOne(MkSpecifier(DOUBLE));
3819 else if(dest.kind == floatType &&
3820 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3822 specs = MkListOne(MkSpecifier(FLOAT));
3824 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3825 (value == 1 || value == 0))
3828 ListAdd(specs, MkSpecifier(BOOL));
3830 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3831 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3834 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3835 ListAdd(specs, MkSpecifier(CHAR));
3837 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3838 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3841 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3842 ListAdd(specs, MkSpecifier(SHORT));
3844 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3847 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3848 ListAdd(specs, MkSpecifier(INT));
3850 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3853 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3854 ListAdd(specs, MkSpecifier(INT64));
3856 else if(dest.kind == enumType &&
3857 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3859 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3865 if(backupSourceExpType)
3867 // Failed to convert: revert previous exp type
3868 if(sourceExp.expType) FreeType(sourceExp.expType);
3869 sourceExp.expType = backupSourceExpType;
3876 Expression newExp { };
3877 *newExp = *sourceExp;
3880 if(sourceExp.destType) sourceExp.destType.refCount++;
3881 if(sourceExp.expType) sourceExp.expType.refCount++;
3883 sourceExp.type = castExp;
3884 if(realDest.kind == classType)
3886 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3887 FreeList(specs, FreeSpecifier);
3890 sourceExp.cast.typeName = MkTypeName(specs, null);
3891 if(newExp.type == opExp)
3893 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3896 sourceExp.cast.exp = newExp;
3898 FreeType(sourceExp.expType);
3899 sourceExp.expType = null;
3900 ProcessExpressionType(sourceExp);
3903 FreeList(specs, FreeSpecifier);
3907 if(backupSourceExpType) FreeType(backupSourceExpType);
3913 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
3914 if(sourceExp.type == identifierExp)
3916 Identifier id = sourceExp.identifier;
3917 if(dest.kind == classType)
3919 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3921 Class _class = dest._class.registered;
3922 Class enumClass = eSystem_FindClass(privateModule, "enum");
3925 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
3928 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
3929 for(value = e.values.first; value; value = value.next)
3931 if(!strcmp(value.name, id.string))
3936 FreeExpContents(sourceExp);
3937 FreeType(sourceExp.expType);
3939 sourceExp.isConstant = true;
3940 sourceExp.expType = MkClassType(_class.fullName);
3944 sourceExp.type = constantExp;
3945 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
3946 sprintf(constant, "%d", (int) value.data);
3948 sprintf(constant, "0x%X", (int) value.data);
3949 sourceExp.constant = CopyString(constant);
3950 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
3959 // Loop through all enum classes
3960 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
3967 #define TERTIARY(o, name, m, t, p) \
3968 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
3970 exp.type = constantExp; \
3971 exp.string = p(op1.m ? op2.m : op3.m); \
3973 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3977 #define BINARY(o, name, m, t, p) \
3978 static bool name(Expression exp, Operand op1, Operand op2) \
3981 exp.type = constantExp; \
3982 exp.string = p(op1.m o value2); \
3984 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3988 #define BINARY_DIVIDE(o, name, m, t, p) \
3989 static bool name(Expression exp, Operand op1, Operand op2) \
3992 exp.type = constantExp; \
3993 exp.string = p(value2 ? (op1.m o value2) : 0); \
3995 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3999 #define UNARY(o, name, m, t, p) \
4000 static bool name(Expression exp, Operand op1) \
4002 exp.type = constantExp; \
4003 exp.string = p((t)(o op1.m)); \
4005 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4009 #define OPERATOR_ALL(macro, o, name) \
4010 macro(o, Int##name, i, int, PrintInt) \
4011 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4012 macro(o, Int64##name, i64, int64, PrintInt64) \
4013 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4014 macro(o, Short##name, s, short, PrintShort) \
4015 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4016 macro(o, Char##name, c, char, PrintChar) \
4017 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4018 macro(o, Float##name, f, float, PrintFloat) \
4019 macro(o, Double##name, d, double, PrintDouble)
4021 #define OPERATOR_INTTYPES(macro, o, name) \
4022 macro(o, Int##name, i, int, PrintInt) \
4023 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4024 macro(o, Int64##name, i64, int64, PrintInt64) \
4025 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4026 macro(o, Short##name, s, short, PrintShort) \
4027 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4028 macro(o, Char##name, c, char, PrintChar) \
4029 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4032 // binary arithmetic
4033 OPERATOR_ALL(BINARY, +, Add)
4034 OPERATOR_ALL(BINARY, -, Sub)
4035 OPERATOR_ALL(BINARY, *, Mul)
4036 OPERATOR_ALL(BINARY_DIVIDE, /, Div)
4037 OPERATOR_INTTYPES(BINARY_DIVIDE, %, Mod)
4040 OPERATOR_ALL(UNARY, -, Neg)
4042 // unary arithmetic increment and decrement
4043 OPERATOR_ALL(UNARY, ++, Inc)
4044 OPERATOR_ALL(UNARY, --, Dec)
4046 // binary arithmetic assignment
4047 OPERATOR_ALL(BINARY, =, Asign)
4048 OPERATOR_ALL(BINARY, +=, AddAsign)
4049 OPERATOR_ALL(BINARY, -=, SubAsign)
4050 OPERATOR_ALL(BINARY, *=, MulAsign)
4051 OPERATOR_ALL(BINARY_DIVIDE, /=, DivAsign)
4052 OPERATOR_INTTYPES(BINARY_DIVIDE, %=, ModAsign)
4055 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4056 OPERATOR_INTTYPES(BINARY, |, BitOr)
4057 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4058 OPERATOR_INTTYPES(BINARY, <<, LShift)
4059 OPERATOR_INTTYPES(BINARY, >>, RShift)
4062 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4064 // binary bitwise assignment
4065 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4066 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4067 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4068 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4069 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4071 // unary logical negation
4072 OPERATOR_INTTYPES(UNARY, !, Not)
4074 // binary logical equality
4075 OPERATOR_ALL(BINARY, ==, Equ)
4076 OPERATOR_ALL(BINARY, !=, Nqu)
4079 OPERATOR_ALL(BINARY, &&, And)
4080 OPERATOR_ALL(BINARY, ||, Or)
4082 // binary logical relational
4083 OPERATOR_ALL(BINARY, >, Grt)
4084 OPERATOR_ALL(BINARY, <, Sma)
4085 OPERATOR_ALL(BINARY, >=, GrtEqu)
4086 OPERATOR_ALL(BINARY, <=, SmaEqu)
4088 // tertiary condition operator
4089 OPERATOR_ALL(TERTIARY, ?, Cond)
4091 //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
4092 #define OPERATOR_TABLE_ALL(name, type) \
4093 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4095 type##Inc, type##Dec, \
4096 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4097 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4099 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4101 type##Equ, type##Nqu, \
4102 type##And, type##Or, \
4103 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4106 #define OPERATOR_TABLE_INTTYPES(name, type) \
4107 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4109 type##Inc, type##Dec, \
4110 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4111 null, null, null, null, null, \
4113 null, null, null, null, null, \
4115 type##Equ, type##Nqu, \
4116 type##And, type##Or, \
4117 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4120 OPERATOR_TABLE_ALL(int, Int)
4121 OPERATOR_TABLE_ALL(uint, UInt)
4122 OPERATOR_TABLE_ALL(int64, Int64)
4123 OPERATOR_TABLE_ALL(uint64, UInt64)
4124 OPERATOR_TABLE_ALL(short, Short)
4125 OPERATOR_TABLE_ALL(ushort, UShort)
4126 OPERATOR_TABLE_INTTYPES(float, Float)
4127 OPERATOR_TABLE_INTTYPES(double, Double)
4128 OPERATOR_TABLE_ALL(char, Char)
4129 OPERATOR_TABLE_ALL(uchar, UChar)
4131 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4132 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4133 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4134 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4135 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4136 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4137 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4138 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4140 public void ReadString(char * output, char * string)
4142 int len = strlen(string);
4144 bool quoted = false, escaped = false;
4145 for(c = 0; c<len; c++)
4147 char ch = string[c];
4152 case 'n': output[d] = '\n'; break;
4153 case 't': output[d] = '\t'; break;
4154 case 'a': output[d] = '\a'; break;
4155 case 'b': output[d] = '\b'; break;
4156 case 'f': output[d] = '\f'; break;
4157 case 'r': output[d] = '\r'; break;
4158 case 'v': output[d] = '\v'; break;
4159 case '\\': output[d] = '\\'; break;
4160 case '\"': output[d] = '\"'; break;
4161 case '\'': output[d] = '\''; break;
4162 default: output[d] = ch;
4183 // String Unescape Copy
4185 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4186 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4187 public int UnescapeString(char * d, char * s, int len)
4191 while(j < len && (ch = s[j]))
4196 switch((ch = s[++j]))
4198 case 'n': d[k] = '\n'; break;
4199 case 't': d[k] = '\t'; break;
4200 case 'a': d[k] = '\a'; break;
4201 case 'b': d[k] = '\b'; break;
4202 case 'f': d[k] = '\f'; break;
4203 case 'r': d[k] = '\r'; break;
4204 case 'v': d[k] = '\v'; break;
4205 case '\\': d[k] = '\\'; break;
4206 case '\"': d[k] = '\"'; break;
4207 case '\'': d[k] = '\''; break;
4208 default: d[k] = '\\'; d[k] = ch;
4220 public char * OffsetEscapedString(char * s, int len, int offset)
4224 while(j < len && k < offset && (ch = s[j]))
4229 return (k == offset) ? s + j : null;
4232 public Operand GetOperand(Expression exp)
4235 Type type = exp.expType;
4238 while(type.kind == classType &&
4239 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4241 if(!type._class.registered.dataType)
4242 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4243 type = type._class.registered.dataType;
4246 if(exp.type == stringExp && op.kind == pointerType)
4248 op.ui64 = (uint64)exp.string;
4249 op.kind = pointerType;
4252 else if(exp.isConstant && exp.type == constantExp)
4254 op.kind = type.kind;
4255 op.type = exp.expType;
4262 if(exp.constant[0] == '\'')
4264 op.c = exp.constant[1];
4267 else if(type.isSigned)
4269 op.c = (char)strtol(exp.constant, null, 0);
4274 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4282 op.s = (short)strtol(exp.constant, null, 0);
4287 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4295 op.i = (int)strtol(exp.constant, null, 0);
4300 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4308 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4313 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4316 op.kind = int64Type;
4321 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4326 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4329 op.kind = int64Type;
4334 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4339 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4342 op.kind = int64Type;
4345 op.f = (float)strtod(exp.constant, null);
4349 op.d = (double)strtod(exp.constant, null);
4352 //case classType: For when we have operator overloading...
4353 // Pointer additions
4354 //case functionType:
4358 op.ui64 = _strtoui64(exp.constant, null, 0);
4359 op.kind = pointerType;
4369 static void UnusedFunction()
4372 a.OnGetString(0,0,0);
4375 extern int __ecereVMethodID_class_OnGetString;
4378 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4380 DataMember dataMember;
4381 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4383 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4384 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4388 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4390 void * ptr = inst.data + dataMember.offset + offset;
4391 char * result = null;
4392 exp.loc = member.loc = inst.loc;
4393 ((Identifier)member.identifiers->first).loc = inst.loc;
4395 if(!dataMember.dataType)
4396 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4397 type = dataMember.dataType;
4398 if(type.kind == classType)
4400 Class _class = type._class.registered;
4401 if(_class.type == enumClass)
4403 Class enumClass = eSystem_FindClass(privateModule, "enum");
4406 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4408 for(item = e.values.first; item; item = item.next)
4410 if((int)item.data == *(int *)ptr)
4418 exp.identifier = MkIdentifier(result);
4419 exp.type = identifierExp;
4420 exp.destType = MkClassType(_class.fullName);
4421 ProcessExpressionType(exp);
4425 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4427 if(!_class.dataType)
4428 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4429 type = _class.dataType;
4438 FreeExpContents(exp);
4440 exp.constant = PrintFloat(*(float*)ptr);
4441 exp.type = constantExp;
4446 FreeExpContents(exp);
4448 exp.constant = PrintDouble(*(double*)ptr);
4449 exp.type = constantExp;
4454 FreeExpContents(exp);
4456 exp.constant = PrintInt(*(int*)ptr);
4457 exp.type = constantExp;
4462 FreeExpContents(exp);
4464 exp.constant = PrintInt64(*(int64*)ptr);
4465 exp.type = constantExp;
4470 FreeExpContents(exp);
4471 // TODO: This should probably use proper type
4472 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4473 exp.type = constantExp;
4478 FreeExpContents(exp);
4479 // TODO: This should probably use proper type
4480 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4481 exp.type = constantExp;
4485 Compiler_Error($"Unhandled type populating instance\n");
4488 ListAdd(memberList, member);
4491 if(parentDataMember.type == unionMember)
4496 void PopulateInstance(Instantiation inst)
4498 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4499 Class _class = classSym.registered;
4500 DataMember dataMember;
4501 OldList * memberList = MkList();
4502 // Added this check and ->Add to prevent memory leaks on bad code
4504 inst.members = MkListOne(MkMembersInitList(memberList));
4506 inst.members->Add(MkMembersInitList(memberList));
4507 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4509 if(!dataMember.isProperty)
4511 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4512 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4516 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4518 void * ptr = inst.data + dataMember.offset;
4519 char * result = null;
4521 exp.loc = member.loc = inst.loc;
4522 ((Identifier)member.identifiers->first).loc = inst.loc;
4524 if(!dataMember.dataType)
4525 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4526 type = dataMember.dataType;
4527 if(type.kind == classType)
4529 Class _class = type._class.registered;
4530 if(_class.type == enumClass)
4532 Class enumClass = eSystem_FindClass(privateModule, "enum");
4535 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4537 for(item = e.values.first; item; item = item.next)
4539 if((int)item.data == *(int *)ptr)
4548 exp.identifier = MkIdentifier(result);
4549 exp.type = identifierExp;
4550 exp.destType = MkClassType(_class.fullName);
4551 ProcessExpressionType(exp);
4554 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4556 if(!_class.dataType)
4557 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4558 type = _class.dataType;
4567 exp.constant = PrintFloat(*(float*)ptr);
4568 exp.type = constantExp;
4573 exp.constant = PrintDouble(*(double*)ptr);
4574 exp.type = constantExp;
4579 exp.constant = PrintInt(*(int*)ptr);
4580 exp.type = constantExp;
4585 exp.constant = PrintInt64(*(int64*)ptr);
4586 exp.type = constantExp;
4591 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4592 exp.type = constantExp;
4596 Compiler_Error($"Unhandled type populating instance\n");
4599 ListAdd(memberList, member);
4605 void ComputeInstantiation(Expression exp)
4607 Instantiation inst = exp.instance;
4608 MembersInit members;
4609 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4610 Class _class = classSym ? classSym.registered : null;
4611 DataMember curMember = null;
4612 Class curClass = null;
4613 DataMember subMemberStack[256];
4614 int subMemberStackPos = 0;
4617 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4619 // Don't recompute the instantiation...
4620 // Non Simple classes will have become constants by now
4624 if(_class.type == normalClass || _class.type == noHeadClass)
4626 inst.data = (byte *)eInstance_New(_class);
4627 if(_class.type == normalClass)
4628 ((Instance)inst.data)._refCount++;
4631 inst.data = new0 byte[_class.structSize];
4636 for(members = inst.members->first; members; members = members.next)
4638 switch(members.type)
4640 case dataMembersInit:
4642 if(members.dataMembers)
4645 for(member = members.dataMembers->first; member; member = member.next)
4647 Identifier ident = member.identifiers ? member.identifiers->first : null;
4650 Property prop = null;
4651 DataMember dataMember = null;
4652 Method method = null;
4653 uint dataMemberOffset;
4657 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4660 if(curMember.isProperty)
4661 prop = (Property)curMember;
4664 dataMember = curMember;
4666 // CHANGED THIS HERE
4667 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4669 // 2013/17/29 -- It seems that this was missing here!
4670 if(_class.type == normalClass)
4671 dataMemberOffset += _class.base.structSize;
4672 // dataMemberOffset = dataMember.offset;
4679 prop = eClass_FindProperty(_class, ident.string, privateModule);
4683 if(prop.memberAccess == publicAccess)
4685 curMember = (DataMember)prop;
4686 curClass = prop._class;
4691 DataMember _subMemberStack[256];
4692 int _subMemberStackPos = 0;
4694 // FILL MEMBER STACK
4695 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4700 if(dataMember.memberAccess == publicAccess)
4702 curMember = dataMember;
4703 curClass = dataMember._class;
4704 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4705 subMemberStackPos = _subMemberStackPos;
4711 if(found && member.initializer && member.initializer.type == expInitializer)
4713 Expression value = member.initializer.exp;
4715 bool deepMember = false;
4718 type = prop.dataType;
4722 if(!dataMember.dataType)
4723 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4725 type = dataMember.dataType;
4728 if(ident && ident.next)
4732 // for(; ident && type; ident = ident.next)
4733 for(ident = ident.next; ident && type; ident = ident.next)
4735 if(type.kind == classType)
4737 prop = eClass_FindProperty(type._class.registered,
4738 ident.string, privateModule);
4740 type = prop.dataType;
4743 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4744 ident.string, &dataMemberOffset, privateModule, null, null);
4746 type = dataMember.dataType;
4749 else if(type.kind == structType || type.kind == unionType)
4752 for(memberType = type.members.first; memberType; memberType = memberType.next)
4754 if(!strcmp(memberType.name, ident.string))
4765 FreeType(value.destType);
4766 value.destType = type;
4767 if(type) type.refCount++;
4768 ComputeExpression(value);
4770 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4772 if(type.kind == classType)
4774 Class _class = type._class.registered;
4775 if(_class.type == bitClass || _class.type == unitClass ||
4776 _class.type == enumClass)
4778 if(!_class.dataType)
4779 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4780 type = _class.dataType;
4786 void * ptr = inst.data + dataMemberOffset;
4788 if(value.type == constantExp)
4794 GetInt(value, (int*)ptr);
4799 GetInt64(value, (int64*)ptr);
4804 GetIntPtr(value, (intptr*)ptr);
4809 GetIntSize(value, (intsize*)ptr);
4814 GetFloat(value, (float*)ptr);
4819 GetDouble(value, (double *)ptr);
4824 else if(value.type == instanceExp)
4826 if(type.kind == classType)
4828 Class _class = type._class.registered;
4829 if(_class.type == structClass)
4831 ComputeTypeSize(type);
4832 if(value.instance.data)
4833 memcpy(ptr, value.instance.data, type.size);
4840 if(value.type == instanceExp && value.instance.data)
4842 if(type.kind == classType)
4844 Class _class = type._class.registered;
4845 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
4847 void (*Set)(void *, void *) = (void *)prop.Set;
4848 Set(inst.data, value.instance.data);
4849 PopulateInstance(inst);
4853 else if(value.type == constantExp)
4859 void (*Set)(void *, double) = (void *)prop.Set;
4860 Set(inst.data, strtod(value.constant, null) );
4865 void (*Set)(void *, float) = (void *)prop.Set;
4866 Set(inst.data, (float)(strtod(value.constant, null)));
4871 void (*Set)(void *, int) = (void *)prop.Set;
4872 Set(inst.data, (int)strtol(value.constant, null, 0));
4877 void (*Set)(void *, int64) = (void *)prop.Set;
4878 Set(inst.data, _strtoi64(value.constant, null, 0));
4883 void (*Set)(void *, intptr) = (void *)prop.Set;
4884 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
4889 void (*Set)(void *, intsize) = (void *)prop.Set;
4890 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
4895 else if(value.type == stringExp)
4898 ReadString(temp, value.string);
4899 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
4903 else if(!deepMember && type && _class.type == unitClass)
4907 // Only support converting units to units for now...
4908 if(value.type == constantExp)
4910 if(type.kind == classType)
4912 Class _class = type._class.registered;
4913 if(_class.type == unitClass)
4915 if(!_class.dataType)
4916 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4917 type = _class.dataType;
4920 // TODO: Assuming same base type for units...
4926 float (*Set)(float) = (void *)prop.Set;
4927 GetFloat(member.initializer.exp, &fValue);
4928 exp.constant = PrintFloat(Set(fValue));
4929 exp.type = constantExp;
4935 double (*Set)(double) = (void *)prop.Set;
4936 GetDouble(member.initializer.exp, &dValue);
4937 exp.constant = PrintDouble(Set(dValue));
4938 exp.type = constantExp;
4945 else if(!deepMember && type && _class.type == bitClass)
4949 if(value.type == instanceExp && value.instance.data)
4951 unsigned int (*Set)(void *) = (void *)prop.Set;
4952 bits = Set(value.instance.data);
4954 else if(value.type == constantExp)
4960 BitMember bitMember = (BitMember) dataMember;
4963 GetInt(value, &part);
4964 bits = (bits & ~bitMember.mask);
4965 if(!bitMember.dataType)
4966 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
4968 type = bitMember.dataType;
4970 if(type.kind == classType && type._class && type._class.registered)
4972 if(!type._class.registered.dataType)
4973 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4974 type = type._class.registered.dataType;
4982 bits |= ((char)part << bitMember.pos);
4984 bits |= ((unsigned char)part << bitMember.pos);
4988 bits |= ((short)part << bitMember.pos);
4990 bits |= ((unsigned short)part << bitMember.pos);
4995 bits |= ((int)part << bitMember.pos);
4997 bits |= ((unsigned int)part << bitMember.pos);
5001 bits |= ((int64)part << bitMember.pos);
5003 bits |= ((uint64)part << bitMember.pos);
5008 bits |= ((intptr)part << bitMember.pos);
5012 bits |= ((uintptr)part << bitMember.pos);
5018 bits |= ((ssize_t)(intsize)part << bitMember.pos);
5022 bits |= ((size_t) (uintsize)part << bitMember.pos);
5031 if(_class && _class.type == unitClass)
5033 ComputeExpression(member.initializer.exp);
5034 exp.constant = member.initializer.exp.constant;
5035 exp.type = constantExp;
5037 member.initializer.exp.constant = null;
5047 if(_class && _class.type == bitClass)
5049 exp.constant = PrintHexUInt(bits);
5050 exp.type = constantExp;
5052 if(exp.type != instanceExp)
5058 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5060 bool result = false;
5064 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5065 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5069 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5070 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5073 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5074 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5075 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5078 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5079 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5080 result = GetOpFloat(op, &op.f);
5083 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5084 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5085 result = GetOpDouble(op, &op.d);
5088 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5089 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5090 result = GetOpUIntPtr(op, &op.ui64);
5093 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5094 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5095 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5098 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5099 result = isSigned ? GetOpIntPtr(op, &op.i64) : GetOpUIntPtr(op, &op.i64);
5102 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5103 result = isSigned ? GetOpIntSize(op, &op.ui64) : GetOpUIntSize(op, &op.ui64);
5109 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5111 if(exp.op.op == SIZEOF)
5113 FreeExpContents(exp);
5114 exp.type = constantExp;
5115 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5126 // Provide default unary +
5127 Expression exp2 = exp.op.exp2;
5129 FreeExpContents(exp);
5130 FreeType(exp.expType);
5131 FreeType(exp.destType);
5137 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5139 // unary arithmetic increment and decrement
5140 //OPERATOR_ALL(UNARY, ++, Inc)
5141 //OPERATOR_ALL(UNARY, --, Dec)
5144 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5146 // unary logical negation
5148 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5154 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5156 if(Promote(op2, op1.kind, op1.type.isSigned))
5157 op2.kind = op1.kind, op2.ops = op1.ops;
5158 else if(Promote(op1, op2.kind, op2.type.isSigned))
5159 op1.kind = op2.kind, op1.ops = op2.ops;
5163 // binary arithmetic
5165 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5168 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5171 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5174 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5177 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5179 // binary arithmetic assignment
5180 //OPERATOR_ALL(BINARY, =, Asign)
5181 //OPERATOR_ALL(BINARY, +=, AddAsign)
5182 //OPERATOR_ALL(BINARY, -=, SubAsign)
5183 //OPERATOR_ALL(BINARY, *=, MulAsign)
5184 //OPERATOR_ALL(BINARY, /=, DivAsign)
5185 //OPERATOR_ALL(BINARY, %=, ModAsign)
5190 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5194 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5197 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5200 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5203 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5205 // binary bitwise assignment
5206 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5207 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5208 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5209 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5210 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5211 // binary logical equality
5213 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5216 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5220 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5223 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5225 // binary logical relational
5227 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5230 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5233 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5236 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5243 void ComputeExpression(Expression exp)
5245 char expString[10240];
5246 expString[0] = '\0';
5248 PrintExpression(exp, expString);
5255 ComputeInstantiation(exp);
5264 Expression exp1, exp2 = null;
5268 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5271 Expression e = exp.op.exp2;
5273 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5275 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5277 if(e.type == extensionCompoundExp)
5278 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5283 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5285 if(e.type == stringExp && e.string)
5287 char * string = e.string;
5288 int len = strlen(string);
5289 char * tmp = new char[len-2+1];
5290 len = UnescapeString(tmp, string + 1, len - 2);
5292 FreeExpContents(exp);
5293 exp.type = constantExp;
5294 exp.constant = PrintUInt(len + 1);
5298 Type type = e.expType;
5300 FreeExpContents(exp);
5301 exp.type = constantExp;
5302 exp.constant = PrintUInt(ComputeTypeSize(type));
5308 ComputeExpression(exp.op.exp2);
5312 ComputeExpression(exp.op.exp1);
5315 op1 = GetOperand(exp1);
5316 if(op1.type) op1.type.refCount++;
5319 op2 = GetOperand(exp2);
5320 if(op2.type) op2.type.refCount++;
5326 op1 = GetOperand(exp1);
5327 if(op1.type) op1.type.refCount++;
5330 CallOperator(exp, exp1, exp2, op1, op2);
5337 if(exp.op.exp1 && exp.op.exp2)
5342 FreeExpContents(exp);
5343 op1.ops.BitAnd(exp, op1, op2);
5352 FreeExpContents(exp);
5353 op1.ops.Mul(exp, op1, op2);
5362 FreeExpContents(exp);
5363 op1.ops.Add(exp, op1, op2);
5368 // Provide default unary +
5369 Expression exp2 = exp.op.exp2;
5371 FreeExpContents(exp);
5372 FreeType(exp.expType);
5373 FreeType(exp.destType);
5384 FreeExpContents(exp);
5385 op1.ops.Sub(exp, op1, op2);
5392 FreeExpContents(exp);
5393 op1.ops.Neg(exp, op1);
5400 FreeExpContents(exp);
5401 op1.ops.BitNot(exp, op1);
5407 FreeExpContents(exp);
5408 op1.ops.Not(exp, op1);
5411 // Binary only operators
5415 FreeExpContents(exp);
5416 op1.ops.Div(exp, op1, op2);
5422 FreeExpContents(exp);
5423 op1.ops.Mod(exp, op1, op2);
5435 FreeExpContents(exp);
5436 op1.ops.Sma(exp, op1, op2);
5445 FreeExpContents(exp);
5446 op1.ops.Grt(exp, op1, op2);
5455 FreeExpContents(exp);
5456 op1.ops.SmaEqu(exp, op1, op2);
5465 FreeExpContents(exp);
5466 op1.ops.GrtEqu(exp, op1, op2);
5475 FreeExpContents(exp);
5476 op1.ops.Equ(exp, op1, op2);
5485 FreeExpContents(exp);
5486 op1.ops.Nqu(exp, op1, op2);
5493 FreeExpContents(exp);
5494 op1.ops.BitOr(exp, op1, op2);
5500 FreeExpContents(exp);
5501 op1.ops.BitXor(exp, op1, op2);
5509 FreeExpContents(exp);
5510 exp.type = constantExp;
5511 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5515 if(op1.type) FreeType(op1.type);
5516 if(op2.type) FreeType(op2.type);
5520 case extensionExpressionExp:
5523 for(e = exp.list->first; e; e = n)
5528 OldList * list = exp.list;
5529 ComputeExpression(e);
5530 //FreeExpContents(exp);
5531 FreeType(exp.expType);
5532 FreeType(exp.destType);
5549 exp.isConstant = true;
5551 ComputeExpression(exp.index.exp);
5552 if(!exp.index.exp.isConstant)
5553 exp.isConstant = false;
5555 for(e = exp.index.index->first; e; e = e.next)
5557 ComputeExpression(e);
5560 // Check if this type is int
5563 exp.isConstant = false;
5565 exp.expType = Dereference(exp.index.exp.expType);
5571 Expression memberExp = exp.member.exp;
5572 Identifier memberID = exp.member.member;
5575 ComputeExpression(exp.member.exp);
5576 type = exp.member.exp.expType;
5579 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);
5580 Property prop = null;
5581 DataMember member = null;
5582 Class convertTo = null;
5583 if(type.kind == subClassType && exp.member.exp.type == classExp)
5584 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5591 PrintTypeNoConst(type, string, false, true);
5592 classSym = FindClass(string);
5593 _class = classSym ? classSym.registered : null;
5596 if(exp.member.member)
5598 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5600 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5602 if(!prop && !member && _class && exp.member.member)
5604 Symbol classSym = FindClass(exp.member.member.string);
5606 _class = classSym ? classSym.registered : null;
5607 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5614 Type type = prop.dataType;
5615 // TODO: Assuming same base type for units...
5616 if(_class.type == unitClass)
5618 if(type.kind == classType)
5620 Class _class = type._class.registered;
5621 if(_class.type == unitClass)
5623 if(!_class.dataType)
5624 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5625 type = _class.dataType;
5633 float (*Get)(float) = (void *)prop.Get;
5634 GetFloat(exp.member.exp, &value);
5635 exp.constant = PrintFloat(Get ? Get(value) : value);
5636 exp.type = constantExp;
5642 double (*Get)(double);
5643 GetDouble(exp.member.exp, &value);
5646 Get = (void *)prop.Set;
5648 Get = (void *)prop.Get;
5649 exp.constant = PrintDouble(Get ? Get(value) : value);
5650 exp.type = constantExp;
5659 Expression value = exp.member.exp;
5662 ProcessPropertyType(prop);
5664 type = prop.dataType;
5667 // printf("Investigate this\n");
5669 else if(_class.type == structClass)
5675 Class propertyClass = type._class.registered;
5676 if(propertyClass.type == structClass && value.type == instanceExp)
5678 void (*Set)(void *, void *) = (void *)prop.Set;
5679 exp.instance = Instantiation { };
5680 exp.instance.data = new0 byte[_class.structSize];
5681 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5682 exp.instance.loc = exp.loc;
5683 exp.type = instanceExp;
5684 Set(exp.instance.data, value.instance.data);
5685 PopulateInstance(exp.instance);
5692 void (*Set)(void *, int) = (void *)prop.Set;
5694 exp.instance = Instantiation { };
5695 exp.instance.data = new0 byte[_class.structSize];
5696 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5697 exp.instance.loc = exp.loc;
5698 exp.type = instanceExp;
5700 GetInt(value, &intValue);
5702 Set(exp.instance.data, intValue);
5703 PopulateInstance(exp.instance);
5709 void (*Set)(void *, int64) = (void *)prop.Set;
5711 exp.instance = Instantiation { };
5712 exp.instance.data = new0 byte[_class.structSize];
5713 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5714 exp.instance.loc = exp.loc;
5715 exp.type = instanceExp;
5717 GetInt64(value, &intValue);
5719 Set(exp.instance.data, intValue);
5720 PopulateInstance(exp.instance);
5727 void (*Set)(void *, intptr) = (void *)prop.Set;
5729 exp.instance = Instantiation { };
5730 exp.instance.data = new0 byte[_class.structSize];
5731 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5732 exp.instance.loc = exp.loc;
5733 exp.type = instanceExp;
5735 GetIntPtr(value, &intValue);
5737 Set(exp.instance.data, intValue);
5738 PopulateInstance(exp.instance);
5745 void (*Set)(void *, intsize) = (void *)prop.Set;
5747 exp.instance = Instantiation { };
5748 exp.instance.data = new0 byte[_class.structSize];
5749 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5750 exp.instance.loc = exp.loc;
5751 exp.type = instanceExp;
5753 GetIntSize(value, &intValue);
5755 Set(exp.instance.data, intValue);
5756 PopulateInstance(exp.instance);
5762 void (*Set)(void *, double) = (void *)prop.Set;
5764 exp.instance = Instantiation { };
5765 exp.instance.data = new0 byte[_class.structSize];
5766 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5767 exp.instance.loc = exp.loc;
5768 exp.type = instanceExp;
5770 GetDouble(value, &doubleValue);
5772 Set(exp.instance.data, doubleValue);
5773 PopulateInstance(exp.instance);
5778 else if(_class.type == bitClass)
5784 Class propertyClass = type._class.registered;
5785 if(propertyClass.type == structClass && value.instance.data)
5787 unsigned int (*Set)(void *) = (void *)prop.Set;
5788 unsigned int bits = Set(value.instance.data);
5789 exp.constant = PrintHexUInt(bits);
5790 exp.type = constantExp;
5793 else if(_class.type == bitClass)
5796 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5799 GetUInt(exp.member.exp, &value);
5801 exp.constant = PrintHexUInt(bits);
5802 exp.type = constantExp;
5810 if(_class.type == bitClass)
5813 GetUInt(exp.member.exp, &value);
5819 Class _class = type._class.registered;
5820 if(_class.type == structClass)
5822 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5824 exp.instance = Instantiation { };
5825 exp.instance.data = new0 byte[_class.structSize];
5826 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5827 exp.instance.loc = exp.loc;
5828 //exp.instance.fullSet = true;
5829 exp.type = instanceExp;
5830 Get(value, exp.instance.data);
5831 PopulateInstance(exp.instance);
5833 else if(_class.type == bitClass)
5835 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5836 uint64 bits = Get(value);
5837 exp.constant = PrintHexUInt64(bits);
5838 exp.type = constantExp;
5844 else if(_class.type == structClass)
5846 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5851 Class _class = type._class.registered;
5852 if(_class.type == structClass && value)
5854 void (*Get)(void *, void *) = (void *)prop.Get;
5856 exp.instance = Instantiation { };
5857 exp.instance.data = new0 byte[_class.structSize];
5858 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5859 exp.instance.loc = exp.loc;
5860 //exp.instance.fullSet = true;
5861 exp.type = instanceExp;
5862 Get(value, exp.instance.data);
5863 PopulateInstance(exp.instance);
5871 char * value = exp.member.exp.instance.data;
5876 Class _class = type._class.registered;
5877 if(_class.type == normalClass)
5879 void *(*Get)(void *) = (void *)prop.Get;
5881 exp.instance = Instantiation { };
5882 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5883 exp.type = instanceExp;
5884 exp.instance.data = Get(value, exp.instance.data);
5896 exp.isConstant = false;
5904 if(exp.type != ExpressionType::memberExp)
5906 FreeExpression(memberExp);
5907 FreeIdentifier(memberID);
5913 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5914 FreeExpContents(exp);
5915 exp.constant = PrintUInt(ComputeTypeSize(type));
5916 exp.type = constantExp;
5922 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5923 if(classSym && classSym.registered)
5925 if(classSym.registered.fixed)
5927 FreeSpecifier(exp._class);
5928 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5929 exp.type = constantExp;
5933 char className[1024];
5934 strcpy(className, "__ecereClass_");
5935 FullClassNameCat(className, classSym.string, true);
5936 MangleClassName(className);
5938 DeclareClass(classSym, className);
5940 FreeExpContents(exp);
5941 exp.type = pointerExp;
5942 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5943 exp.member.member = MkIdentifier("structSize");
5953 if(exp.type == castExp)
5956 ComputeExpression(exp.cast.exp);
5959 if(e && exp.expType)
5962 type = exp.destType;
5965 if(type.kind == classType)
5967 Class _class = type._class.registered;
5968 if(_class && (_class.type == unitClass || _class.type == bitClass))
5970 if(!_class.dataType)
5971 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5972 type = _class.dataType;
5983 if(GetChar(e, &value))
5985 FreeExpContents(exp);
5986 exp.constant = PrintChar(value);
5987 exp.type = constantExp;
5992 unsigned char value = 0;
5993 if(GetUChar(e, &value))
5995 FreeExpContents(exp);
5996 exp.constant = PrintUChar(value);
5997 exp.type = constantExp;
6005 if(GetShort(e, &value))
6007 FreeExpContents(exp);
6008 exp.constant = PrintShort(value);
6009 exp.type = constantExp;
6014 unsigned short value = 0;
6015 if(GetUShort(e, &value))
6017 FreeExpContents(exp);
6018 exp.constant = PrintUShort(value);
6019 exp.type = constantExp;
6027 if(GetInt(e, &value))
6029 FreeExpContents(exp);
6030 exp.constant = PrintInt(value);
6031 exp.type = constantExp;
6036 unsigned int value = 0;
6037 if(GetUInt(e, &value))
6039 FreeExpContents(exp);
6040 exp.constant = PrintUInt(value);
6041 exp.type = constantExp;
6049 if(GetInt64(e, &value))
6051 FreeExpContents(exp);
6052 exp.constant = PrintInt64(value);
6053 exp.type = constantExp;
6059 if(GetUInt64(e, &value))
6061 FreeExpContents(exp);
6062 exp.constant = PrintUInt64(value);
6063 exp.type = constantExp;
6071 if(GetIntPtr(e, &value))
6073 FreeExpContents(exp);
6074 exp.constant = PrintInt64((int64)value);
6075 exp.type = constantExp;
6081 if(GetUIntPtr(e, &value))
6083 FreeExpContents(exp);
6084 exp.constant = PrintUInt64((uint64)value);
6085 exp.type = constantExp;
6093 if(GetIntSize(e, &value))
6095 FreeExpContents(exp);
6096 exp.constant = PrintInt64((int64)value);
6097 exp.type = constantExp;
6103 if(GetUIntSize(e, &value))
6105 FreeExpContents(exp);
6106 exp.constant = PrintUInt64((uint64)value);
6107 exp.type = constantExp;
6114 if(GetFloat(e, &value))
6116 FreeExpContents(exp);
6117 exp.constant = PrintFloat(value);
6118 exp.type = constantExp;
6125 if(GetDouble(e, &value))
6127 FreeExpContents(exp);
6128 exp.constant = PrintDouble(value);
6129 exp.type = constantExp;
6144 // Caring only about last expression for now...
6145 ComputeExpression(exp.cond.exp->last);
6146 if(exp.cond.elseExp)
6147 ComputeExpression(exp.cond.elseExp);
6149 ComputeExpression(exp.cond.cond);
6151 op1 = GetOperand(exp.cond.cond);
6152 if(op1.type) op1.type.refCount++;
6153 op2 = GetOperand(exp.cond.exp->last);
6154 if(op2.type) op2.type.refCount++;
6155 op3 = GetOperand(exp.cond.elseExp);
6156 if(op3.type) op3.type.refCount++;
6158 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6159 if(op1.type) FreeType(op1.type);
6160 if(op2.type) FreeType(op2.type);
6161 if(op3.type) FreeType(op3.type);
6167 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
6172 OldList converts { };
6175 if(destType.kind == voidType)
6178 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
6182 // for(convert = converts.last; convert; convert = convert.prev)
6183 for(convert = converts.first; convert; convert = convert.next)
6185 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6188 Expression newExp { };
6189 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6191 // TODO: Check this...
6193 newExp.destType = null;
6198 exp.type = memberExp;
6199 exp.addedThis = true;
6200 exp.member.exp = newExp;
6201 FreeType(exp.member.exp.expType);
6203 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6204 exp.member.exp.expType.classObjectType = objectType;
6205 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6206 exp.member.memberType = propertyMember;
6207 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6208 // TESTING THIS... for (int)degrees
6209 exp.needCast = true;
6210 if(exp.expType) exp.expType.refCount++;
6211 ApplyAnyObjectLogic(exp.member.exp);
6216 /*if(exp.isConstant)
6218 // Color { ColorRGB = [exp] };
6219 exp.type = instanceExp;
6220 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6221 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6222 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6226 // If not constant, don't turn it yet into an instantiation
6227 // (Go through the deep members system first)
6228 exp.type = memberExp;
6229 exp.addedThis = true;
6230 exp.member.exp = newExp;
6232 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6233 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6234 newExp.expType._class.registered.type == noHeadClass)
6236 newExp.byReference = true;
6239 FreeType(exp.member.exp.expType);
6240 /*exp.member.exp.expType = convert.convert.dataType;
6241 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6242 exp.member.exp.expType = null;
6243 if(convert.convert.dataType)
6245 exp.member.exp.expType = { };
6246 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6247 exp.member.exp.expType.refCount = 1;
6248 exp.member.exp.expType.classObjectType = objectType;
6249 ApplyAnyObjectLogic(exp.member.exp);
6252 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6253 exp.member.memberType = reverseConversionMember;
6254 exp.expType = convert.resultType ? convert.resultType :
6255 MkClassType(convert.convert._class.fullName);
6256 exp.needCast = true;
6257 if(convert.resultType) convert.resultType.refCount++;
6263 FreeType(exp.expType);
6266 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6267 exp.needCast = true;
6268 if(exp.expType) exp.expType.refCount++;
6272 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6273 exp.needCast = true;
6274 if(convert.resultType)
6275 convert.resultType.refCount++;
6279 if(exp.isConstant && inCompiler)
6280 ComputeExpression(exp);
6282 converts.Free(FreeConvert);
6285 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6287 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6289 if(!result && exp.expType && exp.destType)
6291 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6292 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6293 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6294 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6298 // if(result) CheckTemplateTypes(exp);
6302 void CheckTemplateTypes(Expression exp)
6304 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6306 Expression newExp { };
6310 if(exp.destType) exp.destType.refCount++;
6311 if(exp.expType) exp.expType.refCount++;
6315 switch(exp.expType.kind)
6318 if(exp.destType.classObjectType)
6320 // We need to pass the address, just pass it along (Undo what was done above)
6321 if(exp.destType) exp.destType.refCount--;
6322 if(exp.expType) exp.expType.refCount--;
6327 // If we're looking for value:
6328 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6330 OldList * unionDefs = MkList();
6331 OldList * statements = MkList();
6332 context = PushContext();
6333 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6334 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6335 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6336 exp.type = extensionCompoundExp;
6337 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6338 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6339 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6340 exp.compound.compound.context = context;
6341 PopContext(context);
6346 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6347 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6351 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6353 Expression newExp { };
6357 if(exp.destType) exp.destType.refCount++;
6358 if(exp.expType) exp.expType.refCount++;
6362 switch(exp.expType.kind)
6365 if(exp.destType.classObjectType)
6367 // We need to pass the address, just pass it along (Undo what was done above)
6368 if(exp.destType) exp.destType.refCount--;
6369 if(exp.expType) exp.expType.refCount--;
6374 // If we're looking for value:
6375 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6377 OldList * unionDefs = MkList();
6378 OldList * statements = MkList();
6379 context = PushContext();
6380 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6381 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6382 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6383 exp.type = extensionCompoundExp;
6384 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6385 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6386 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6387 exp.compound.compound.context = context;
6388 PopContext(context);
6393 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6395 exp.type = bracketsExp;
6396 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6397 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6398 ProcessExpressionType(exp.list->first);
6403 exp.type = bracketsExp;
6404 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6405 newExp.needCast = true;
6406 ProcessExpressionType(exp.list->first);
6412 if(exp.expType.kind == templateType)
6414 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6417 FreeType(exp.destType);
6418 FreeType(exp.expType);
6423 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6428 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6429 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6433 char typeString[1024];
6435 OldList * specs = MkList();
6436 typeString[0] = '\0';
6437 PrintType(exp.expType, typeString, false, false);
6438 decl = SpecDeclFromString(typeString, specs, null);
6441 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6442 exp.cast.typeName = MkTypeName(specs, decl);
6443 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6444 exp.cast.exp.needCast = true;
6451 // TODO: The Symbol tree should be reorganized by namespaces
6453 // - Tree of all symbols within (stored without namespace)
6454 // - Tree of sub-namespaces
6456 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6458 int nsLen = strlen(nameSpace);
6460 // Start at the name space prefix
6461 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6463 char * s = symbol.string;
6464 if(!strncmp(s, nameSpace, nsLen))
6466 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6469 for(c = strlen(s)-1; c >= 0; c--)
6474 if(!strcmp(namePart, name))
6476 // TODO: Error on ambiguity
6486 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6489 char nameSpace[1024];
6491 bool gotColon = false;
6493 nameSpace[0] = '\0';
6494 for(c = strlen(name)-1; c >= 0; c--)
6501 namePart = name+c+1;
6502 while(c >= 0 && name[c] == ':') c--;
6505 // Try an exact match first
6506 Symbol symbol = (Symbol)tree.FindString(name);
6510 // Namespace specified
6511 memcpy(nameSpace, name, c + 1);
6514 return ScanWithNameSpace(tree, nameSpace, namePart);
6518 // Looking for a global symbol, e.g. ::Sleep()
6519 Symbol symbol = (Symbol)tree.FindString(namePart);
6524 // Name only (no namespace specified)
6525 Symbol symbol = (Symbol)tree.FindString(namePart);
6528 return ScanWithNameSpace(tree, "", namePart);
6533 static void ProcessDeclaration(Declaration decl);
6535 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6538 //Time startTime = GetTime();
6540 // Optimize this later? Do this before/less?
6542 Symbol symbol = null;
6543 // First, check if the identifier is declared inside the function
6544 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6546 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6548 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6554 strcpy(curName, thisNameSpace);
6555 strcat(curName, "::");
6556 strcat(curName, name);
6557 // Try to resolve in current namespace first
6558 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6561 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6564 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6566 if(symbol || ctx == endContext) break;
6568 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6570 if(symbol.pointerExternal.type == functionExternal)
6572 FunctionDefinition function = symbol.pointerExternal.function;
6574 // Modified this recently...
6575 Context tmpContext = curContext;
6577 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6578 curContext = tmpContext;
6580 symbol.pointerExternal.symbol = symbol;
6583 DeclareType(symbol.type, true, true);
6585 ast->Insert(curExternal.prev, symbol.pointerExternal);
6587 symbol.id = curExternal.symbol.idCode;
6590 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6592 ast->Move(symbol.pointerExternal, curExternal.prev);
6593 symbol.id = curExternal.symbol.idCode;
6597 //findSymbolTotalTime += GetTime() - startTime;
6602 static void GetTypeSpecs(Type type, OldList * specs)
6604 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6609 if(type._class.registered)
6611 if(!type._class.registered.dataType)
6612 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6613 GetTypeSpecs(type._class.registered.dataType, specs);
6617 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6618 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6619 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6620 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6621 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6622 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6623 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6624 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6627 ListAdd(specs, MkSpecifier(INT)); break;
6631 static void PrintArraySize(Type arrayType, char * string)
6636 if(arrayType.enumClass)
6637 strcat(size, arrayType.enumClass.string);
6638 else if(arrayType.arraySizeExp)
6639 PrintExpression(arrayType.arraySizeExp, size);
6641 strcat(string, size);
6644 // WARNING : This function expects a null terminated string since it recursively concatenate...
6645 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6649 if(printConst && type.constant)
6650 strcat(string, "const ");
6655 Symbol c = type._class;
6656 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6657 // look into merging with thisclass ?
6658 if(type.classObjectType == typedObject)
6659 strcat(string, "typed_object");
6660 else if(type.classObjectType == anyObject)
6661 strcat(string, "any_object");
6665 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6667 if(type.byReference)
6668 strcat(string, " &");
6671 case voidType: strcat(string, "void"); break;
6672 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6673 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6674 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6675 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6676 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6677 case _BoolType: strcat(string, "_Bool"); break;
6678 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6679 case floatType: strcat(string, "float"); break;
6680 case doubleType: strcat(string, "double"); break;
6684 strcat(string, "struct ");
6685 strcat(string, type.enumName);
6687 else if(type.typeName)
6688 strcat(string, type.typeName);
6692 strcat(string, "struct { ");
6693 for(member = type.members.first; member; member = member.next)
6695 PrintType(member, string, true, fullName);
6696 strcat(string,"; ");
6704 strcat(string, "union ");
6705 strcat(string, type.enumName);
6707 else if(type.typeName)
6708 strcat(string, type.typeName);
6711 strcat(string, "union ");
6712 strcat(string,"(unnamed)");
6718 strcat(string, "enum ");
6719 strcat(string, type.enumName);
6721 else if(type.typeName)
6722 strcat(string, type.typeName);
6724 strcat(string, "int"); // "enum");
6727 strcat(string, "...");
6730 strcat(string, "subclass(");
6731 strcat(string, type._class ? type._class.string : "int");
6732 strcat(string, ")");
6735 strcat(string, type.templateParameter.identifier.string);
6738 strcat(string, "thisclass");
6741 strcat(string, "__builtin_va_list");
6747 static void PrintName(Type type, char * string, bool fullName)
6749 if(type.name && type.name[0])
6752 strcat(string, type.name);
6755 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6756 if(name) name += 2; else name = type.name;
6757 strcat(string, name);
6762 static void PrintAttribs(Type type, char * string)
6766 if(type.dllExport) strcat(string, "dllexport ");
6767 if(type.attrStdcall) strcat(string, "stdcall ");
6771 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
6773 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6775 Type attrType = null;
6776 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
6777 PrintAttribs(type, string);
6778 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
6779 strcat(string, " const");
6780 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
6781 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6782 strcat(string, " (");
6783 if(type.kind == pointerType)
6785 if(type.type.kind == functionType || type.type.kind == methodType)
6786 PrintAttribs(type.type, string);
6788 if(type.kind == pointerType)
6790 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
6791 strcat(string, "*");
6793 strcat(string, " *");
6795 if(printConst && type.constant && type.kind == pointerType)
6796 strcat(string, " const");
6799 PrintTypeSpecs(type, string, fullName, printConst);
6802 static void PostPrintType(Type type, char * string, bool fullName)
6804 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6805 strcat(string, ")");
6806 if(type.kind == arrayType)
6807 PrintArraySize(type, string);
6808 else if(type.kind == functionType)
6811 strcat(string, "(");
6812 for(param = type.params.first; param; param = param.next)
6814 PrintType(param, string, true, fullName);
6815 if(param.next) strcat(string, ", ");
6817 strcat(string, ")");
6819 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6820 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
6824 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6826 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
6828 PrePrintType(type, string, fullName, null, printConst);
6830 if(type.thisClass || (printName && type.name && type.name[0]))
6831 strcat(string, " ");
6832 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
6834 Symbol _class = type.thisClass;
6835 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
6837 if(type.classObjectType == classPointer)
6838 strcat(string, "class");
6840 strcat(string, type.byReference ? "typed_object&" : "typed_object");
6842 else if(_class && _class.string)
6844 String s = _class.string;
6849 char * name = RSearchString(s, "::", strlen(s), true, false);
6850 if(name) name += 2; else name = s;
6851 strcat(string, name);
6854 strcat(string, "::");
6857 if(printName && type.name)
6858 PrintName(type, string, fullName);
6859 PostPrintType(type, string, fullName);
6860 if(type.bitFieldCount)
6863 sprintf(count, ":%d", type.bitFieldCount);
6864 strcat(string, count);
6868 void PrintType(Type type, char * string, bool printName, bool fullName)
6870 _PrintType(type, string, printName, fullName, true);
6873 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
6875 _PrintType(type, string, printName, fullName, false);
6878 static Type FindMember(Type type, char * string)
6881 for(memberType = type.members.first; memberType; memberType = memberType.next)
6883 if(!memberType.name)
6885 Type subType = FindMember(memberType, string);
6889 else if(!strcmp(memberType.name, string))
6895 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6898 for(memberType = type.members.first; memberType; memberType = memberType.next)
6900 if(!memberType.name)
6902 Type subType = FindMember(memberType, string);
6905 *offset += memberType.offset;
6909 else if(!strcmp(memberType.name, string))
6911 *offset += memberType.offset;
6918 public bool GetParseError() { return parseError; }
6920 Expression ParseExpressionString(char * expression)
6924 fileInput = TempFile { };
6925 fileInput.Write(expression, 1, strlen(expression));
6926 fileInput.Seek(0, start);
6929 parsedExpression = null;
6931 expression_yyparse();
6934 return parsedExpression;
6937 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6939 Identifier id = exp.identifier;
6940 Method method = null;
6941 Property prop = null;
6942 DataMember member = null;
6943 ClassProperty classProp = null;
6945 if(_class && _class.type == enumClass)
6947 NamedLink value = null;
6948 Class enumClass = eSystem_FindClass(privateModule, "enum");
6952 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6954 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6955 for(value = e.values.first; value; value = value.next)
6957 if(!strcmp(value.name, id.string))
6964 FreeExpContents(exp);
6966 exp.type = constantExp;
6967 exp.isConstant = true;
6968 if(!strcmp(baseClass.dataTypeString, "int"))
6969 sprintf(constant, "%d",(int)value.data);
6971 sprintf(constant, "0x%X",(int)value.data);
6972 exp.constant = CopyString(constant);
6973 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6974 exp.expType = MkClassType(baseClass.fullName);
6982 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6984 ProcessMethodType(method);
6991 // TOCHECK: Put it back to what it was...
6992 // methodClass = _class;
6993 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6998 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7001 ProcessPropertyType(prop);
7002 exp.expType = prop.dataType;
7003 if(prop.dataType) prop.dataType.refCount++;
7006 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7008 if(!member.dataType)
7009 member.dataType = ProcessTypeString(member.dataTypeString, false);
7010 exp.expType = member.dataType;
7011 if(member.dataType) member.dataType.refCount++;
7014 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7016 if(!classProp.dataType)
7017 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7019 if(classProp.constant)
7021 FreeExpContents(exp);
7023 exp.isConstant = true;
7024 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7026 //char constant[256];
7027 exp.type = stringExp;
7028 exp.constant = QMkString((char *)classProp.Get(_class));
7033 exp.type = constantExp;
7034 sprintf(constant, "%d", (int)classProp.Get(_class));
7035 exp.constant = CopyString(constant);
7043 exp.expType = classProp.dataType;
7044 if(classProp.dataType) classProp.dataType.refCount++;
7050 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7052 BinaryTree * tree = &nameSpace.functions;
7053 GlobalData data = (GlobalData)tree->FindString(name);
7057 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7059 data = ScanGlobalData(child, name);
7067 static GlobalData FindGlobalData(char * name)
7070 NameSpace * nameSpace;
7071 nameSpace = globalData;
7072 for(c = 0; name[c]; c++)
7074 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7076 NameSpace * newSpace;
7077 char * spaceName = new char[c - start + 1];
7078 strncpy(spaceName, name + start, c - start);
7079 spaceName[c-start] = '\0';
7080 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7084 nameSpace = newSpace;
7085 if(name[c] == ':') c++;
7091 return ScanGlobalData(nameSpace, name + start);
7096 static int definedExpStackPos;
7097 static void * definedExpStack[512];
7099 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7100 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7102 Expression prev = checkedExp.prev, next = checkedExp.next;
7104 FreeExpContents(checkedExp);
7105 FreeType(checkedExp.expType);
7106 FreeType(checkedExp.destType);
7108 *checkedExp = *newExp;
7112 checkedExp.prev = prev;
7113 checkedExp.next = next;
7116 void ApplyAnyObjectLogic(Expression e)
7118 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7120 char debugExpString[4096];
7121 debugExpString[0] = '\0';
7122 PrintExpression(e, debugExpString);
7125 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7127 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7128 //ellipsisDestType = destType;
7131 Type type = e.expType;
7132 Class _class = null;
7133 //Type destType = e.destType;
7135 if(type.kind == classType && type._class && type._class.registered)
7137 _class = type._class.registered;
7139 else if(type.kind == subClassType)
7141 _class = FindClass("ecere::com::Class").registered;
7145 char string[1024] = "";
7148 PrintTypeNoConst(type, string, false, true);
7149 classSym = FindClass(string);
7150 if(classSym) _class = classSym.registered;
7153 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...
7154 (!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))) ||
7155 destType.byReference)))
7157 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7159 Expression checkedExp = e, newExp;
7161 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7163 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7165 if(checkedExp.type == extensionCompoundExp)
7167 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7170 checkedExp = checkedExp.list->last;
7172 else if(checkedExp.type == castExp)
7173 checkedExp = checkedExp.cast.exp;
7176 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7178 newExp = checkedExp.op.exp2;
7179 checkedExp.op.exp2 = null;
7180 FreeExpContents(checkedExp);
7182 if(e.expType && e.expType.passAsTemplate)
7185 ComputeTypeSize(e.expType);
7186 sprintf(size, "%d", e.expType.size);
7187 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7188 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7189 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7192 ReplaceExpContents(checkedExp, newExp);
7193 e.byReference = true;
7195 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7197 Expression checkedExp, newExp;
7200 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7202 e.type == identifierExp ||
7203 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7204 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7205 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7208 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7210 Context context = PushContext();
7212 OldList * specs = MkList();
7213 char typeString[1024];
7214 Expression newExp { };
7216 typeString[0] = '\0';
7219 //if(e.destType) e.destType.refCount++;
7220 // if(exp.expType) exp.expType.refCount++;
7223 newExp.expType = null;
7225 PrintTypeNoConst(e.expType, typeString, false, true);
7226 decl = SpecDeclFromString(typeString, specs, null);
7227 newExp.destType = ProcessType(specs, decl);
7229 curContext = context;
7231 // We need a current compound for this
7235 OldList * stmts = MkList();
7236 e.type = extensionCompoundExp;
7237 sprintf(name, "__internalValue%03X", internalValueCounter++);
7238 if(!curCompound.compound.declarations)
7239 curCompound.compound.declarations = MkList();
7240 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7241 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7242 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7243 e.compound = MkCompoundStmt(null, stmts);
7246 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7249 e.compound = MkCompoundStmt(
7250 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7251 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7253 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7257 Type type = e.destType;
7259 CopyTypeInto(e.destType, type);
7260 e.destType.refCount = 1;
7261 e.destType.classObjectType = none;
7265 e.compound.compound.context = context;
7266 PopContext(context);
7267 curContext = context.parent;
7271 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7273 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7275 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7277 if(checkedExp.type == extensionCompoundExp)
7279 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7282 checkedExp = checkedExp.list->last;
7284 else if(checkedExp.type == castExp)
7285 checkedExp = checkedExp.cast.exp;
7288 Expression operand { };
7289 operand = *checkedExp;
7290 checkedExp.destType = null;
7291 checkedExp.expType = null;
7293 checkedExp.type = opExp;
7294 checkedExp.op.op = '&';
7295 checkedExp.op.exp1 = null;
7296 checkedExp.op.exp2 = operand;
7298 //newExp = MkExpOp(null, '&', checkedExp);
7300 //ReplaceExpContents(checkedExp, newExp);
7307 // If expression type is a simple class, make it an address
7308 // FixReference(e, true);
7311 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7312 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7313 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7315 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"))
7317 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7321 Expression thisExp { };
7324 thisExp.prev = null;
7325 thisExp.next = null;
7328 e.type = bracketsExp;
7329 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7330 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7331 ((Expression)e.list->first).byReference = true;
7333 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7335 e.expType = thisExp.expType;
7336 e.expType.refCount++;
7341 CopyTypeInto(e.expType, thisExp.expType);
7342 e.expType.byReference = false;
7343 e.expType.refCount = 1;
7345 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7346 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7348 e.expType.classObjectType = none;
7353 // TOFIX: Try this for a nice IDE crash!
7355 // The other way around
7358 if(destType && e.expType &&
7359 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7360 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7361 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7363 if(destType.kind == ellipsisType)
7365 Compiler_Error($"Unspecified type\n");
7367 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7369 bool byReference = e.expType.byReference;
7370 Expression thisExp { };
7372 OldList * specs = MkList();
7373 char typeString[1024]; // Watch buffer overruns
7375 ClassObjectType backupClassObjectType;
7376 bool backupByReference;
7378 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7383 backupClassObjectType = type.classObjectType;
7384 backupByReference = type.byReference;
7386 type.classObjectType = none;
7387 type.byReference = false;
7389 typeString[0] = '\0';
7390 PrintType(type, typeString, false, true);
7391 decl = SpecDeclFromString(typeString, specs, null);
7393 type.classObjectType = backupClassObjectType;
7394 type.byReference = backupByReference;
7397 thisExp.prev = null;
7398 thisExp.next = null;
7401 if( ( type.kind == classType && type._class && type._class.registered &&
7402 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7403 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7404 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7405 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7410 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7413 CopyTypeInto(e.expType, type);
7414 e.expType.byReference = false;
7415 e.expType.refCount = 1;
7420 e.cast.typeName = MkTypeName(specs, decl);
7421 e.cast.exp = thisExp;
7422 e.byReference = true;
7426 e.destType = destType;
7427 destType.refCount++;
7432 void ProcessExpressionType(Expression exp)
7434 bool unresolved = false;
7435 Location oldyylloc = yylloc;
7436 bool notByReference = false;
7438 char debugExpString[4096];
7439 debugExpString[0] = '\0';
7440 PrintExpression(exp, debugExpString);
7442 if(!exp || exp.expType)
7445 //eSystem_Logf("%s\n", expString);
7447 // Testing this here
7453 Identifier id = exp.identifier;
7454 if(!id || !topContext) return;
7456 // DOING THIS LATER NOW...
7457 if(id._class && id._class.name)
7459 id.classSym = id._class.symbol; // FindClass(id._class.name);
7460 /* TODO: Name Space Fix ups
7462 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7466 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7468 exp.expType = ProcessTypeString("Module", true);
7471 else */if(strstr(id.string, "__ecereClass") == id.string)
7473 exp.expType = ProcessTypeString("ecere::com::Class", true);
7476 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7478 // Added this here as well
7479 ReplaceClassMembers(exp, thisClass);
7480 if(exp.type != identifierExp)
7482 ProcessExpressionType(exp);
7486 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7491 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7492 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7493 if(!symbol/* && exp.destType*/)
7495 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7501 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7502 if(exp.type != identifierExp)
7504 ProcessExpressionType(exp);
7508 // Static methods called from inside the _class
7509 else if(currentClass && !id._class)
7511 if(ResolveIdWithClass(exp, currentClass, true))
7514 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7518 // If we manage to resolve this symbol
7521 Type type = symbol.type;
7522 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7524 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7526 Context context = SetupTemplatesContext(_class);
7527 type = ReplaceThisClassType(_class);
7528 FinishTemplatesContext(context);
7529 if(type) type.refCount = 0; // We'll be incrementing it right below...
7532 FreeSpecifier(id._class);
7535 id.string = CopyString(symbol.string);
7541 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7542 // Add missing cases here... enum Classes...
7543 exp.isConstant = true;
7545 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7546 if(symbol.isParam || !strcmp(id.string, "this"))
7548 if(_class && _class.type == structClass && !type.declaredWithStruct)
7549 exp.byReference = true;
7551 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7552 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7553 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7554 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7556 Identifier id = exp.identifier;
7557 exp.type = bracketsExp;
7558 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7562 if(symbol.isIterator)
7564 if(symbol.isIterator == 3)
7566 exp.type = bracketsExp;
7567 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7568 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7570 ProcessExpressionType(exp);
7572 else if(symbol.isIterator != 4)
7574 exp.type = memberExp;
7575 exp.member.exp = MkExpIdentifier(exp.identifier);
7576 exp.member.exp.expType = exp.expType;
7577 /*if(symbol.isIterator == 6)
7578 exp.member.member = MkIdentifier("key");
7580 exp.member.member = MkIdentifier("data");
7582 ProcessExpressionType(exp);
7589 DefinedExpression definedExp = null;
7590 if(thisNameSpace && !(id._class && !id._class.name))
7593 strcpy(name, thisNameSpace);
7595 strcat(name, id.string);
7596 definedExp = eSystem_FindDefine(privateModule, name);
7599 definedExp = eSystem_FindDefine(privateModule, id.string);
7603 for(c = 0; c<definedExpStackPos; c++)
7604 if(definedExpStack[c] == definedExp)
7606 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7608 Location backupYylloc = yylloc;
7609 File backInput = fileInput;
7610 definedExpStack[definedExpStackPos++] = definedExp;
7612 fileInput = TempFile { };
7613 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7614 fileInput.Seek(0, start);
7617 parsedExpression = null;
7619 expression_yyparse();
7622 fileInput = backInput;
7624 yylloc = backupYylloc;
7626 if(parsedExpression)
7629 exp.type = bracketsExp;
7630 exp.list = MkListOne(parsedExpression);
7631 parsedExpression.loc = yylloc;
7632 ProcessExpressionType(exp);
7633 definedExpStackPos--;
7636 definedExpStackPos--;
7642 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7648 GlobalData data = null;
7649 if(thisNameSpace && !(id._class && !id._class.name))
7652 strcpy(name, thisNameSpace);
7654 strcat(name, id.string);
7655 data = FindGlobalData(name);
7658 data = FindGlobalData(id.string);
7661 DeclareGlobalData(data);
7662 exp.expType = data.dataType;
7663 if(data.dataType) data.dataType.refCount++;
7666 id.string = CopyString(data.fullName);
7667 FreeSpecifier(id._class);
7674 GlobalFunction function = null;
7675 if(thisNameSpace && !(id._class && !id._class.name))
7678 strcpy(name, thisNameSpace);
7680 strcat(name, id.string);
7681 function = eSystem_FindFunction(privateModule, name);
7684 function = eSystem_FindFunction(privateModule, id.string);
7689 id.string = CopyString(function.name);
7692 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7693 strcpy(name, "__ecereFunction_");
7694 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7695 if(DeclareFunction(function, name))
7698 id.string = CopyString(name);
7700 exp.expType = function.dataType;
7701 if(function.dataType) function.dataType.refCount++;
7703 FreeSpecifier(id._class);
7720 if(!exp.instance._class)
7722 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7724 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7728 //classSym = FindClass(exp.instance._class.fullName);
7729 //_class = classSym ? classSym.registered : null;
7731 ProcessInstantiationType(exp.instance);
7732 exp.isConstant = exp.instance.isConstant;
7735 if(_class.type == unitClass && _class.base.type != systemClass)
7738 Type destType = exp.destType;
7740 exp.destType = MkClassType(_class.base.fullName);
7741 exp.expType = MkClassType(_class.fullName);
7742 CheckExpressionType(exp, exp.destType, true);
7744 exp.destType = destType;
7746 exp.expType = MkClassType(_class.fullName);
7749 if(exp.instance._class)
7751 exp.expType = MkClassType(exp.instance._class.name);
7752 /*if(exp.expType._class && exp.expType._class.registered &&
7753 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7754 exp.expType.byReference = true;*/
7762 char * constant = exp.constant;
7770 if(constant[0] == '\'')
7772 if((int)((byte *)constant)[1] > 127)
7775 unichar ch = UTF8GetChar(constant + 1, &nb);
7776 if(nb < 2) ch = constant[1];
7778 exp.constant = PrintUInt(ch);
7779 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7780 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7781 type._class = FindClass("unichar");
7783 type.isSigned = false;
7787 type.kind = charType;
7788 type.isSigned = true;
7793 char * dot = strchr(constant, '.');
7794 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
7798 exponent = strchr(constant, 'p');
7799 if(!exponent) exponent = strchr(constant, 'P');
7803 exponent = strchr(constant, 'e');
7804 if(!exponent) exponent = strchr(constant, 'E');
7809 if(strchr(constant, 'f') || strchr(constant, 'F'))
7810 type.kind = floatType;
7812 type.kind = doubleType;
7813 type.isSigned = true;
7817 bool isSigned = constant[0] == '-';
7818 int64 i64 = strtoll(constant, null, 0);
7819 uint64 ui64 = strtoull(constant, null, 0);
7820 bool is64Bit = false;
7833 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
7837 else if(constant[0] != '0' || !constant[1])
7840 type.kind = is64Bit ? int64Type : intType;
7841 type.isSigned = isSigned;
7844 exp.isConstant = true;
7845 if(exp.destType && exp.destType.kind == doubleType)
7846 type.kind = doubleType;
7847 else if(exp.destType && exp.destType.kind == floatType)
7848 type.kind = floatType;
7849 else if(exp.destType && exp.destType.kind == int64Type)
7850 type.kind = int64Type;
7856 exp.isConstant = true; // Why wasn't this constant?
7873 ProcessExpressionType(exp._new.size);
7878 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7880 DeclareType(exp.expType.type, false, false);
7884 ProcessExpressionType(exp._renew.size);
7885 ProcessExpressionType(exp._renew.exp);
7890 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7892 DeclareType(exp.expType.type, false, false);
7896 bool assign = false, boolResult = false, boolOps = false;
7897 Type type1 = null, type2 = null;
7898 bool useDestType = false, useSideType = false;
7899 Location oldyylloc = yylloc;
7900 bool useSideUnit = false;
7902 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7911 // Assignment Operators
7925 // boolean Operators
7927 // Expect boolean operators
7929 //boolResult = true;
7933 // Expect boolean operands
7944 // Gives boolean result
7952 // Just added these... testing
7957 // DANGER: Verify units
7962 if(exp.op.op != '*' || exp.op.exp1)
7969 /*// Implement speed etc.
7975 if(exp.op.op == '&')
7977 // Added this here earlier for Iterator address as key
7978 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7980 Identifier id = exp.op.exp2.identifier;
7981 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7982 if(symbol && symbol.isIterator == 2)
7984 exp.type = memberExp;
7985 exp.member.exp = exp.op.exp2;
7986 exp.member.member = MkIdentifier("key");
7988 exp.op.exp2.expType = symbol.type;
7989 symbol.type.refCount++;
7990 ProcessExpressionType(exp);
7994 // exp.op.exp2.usage.usageRef = true;
7998 //dummy.kind = TypeDummy;
8002 if(exp.destType && exp.destType.kind == classType &&
8003 exp.destType._class && exp.destType._class.registered && useDestType &&
8005 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
8006 exp.destType._class.registered.type == enumClass ||
8007 exp.destType._class.registered.type == bitClass
8010 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8012 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8013 exp.op.exp1.destType = exp.destType;
8015 exp.destType.refCount++;
8019 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8020 exp.op.exp1.destType = dummy;
8024 // TESTING THIS HERE...
8025 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8026 ProcessExpressionType(exp.op.exp1);
8027 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8029 if(exp.op.exp1.destType == dummy)
8032 exp.op.exp1.destType = null;
8034 type1 = exp.op.exp1.expType;
8039 char expString[10240];
8040 expString[0] = '\0';
8041 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8045 exp.op.exp2.destType = exp.op.exp1.expType;
8046 if(exp.op.exp1.expType)
8047 exp.op.exp1.expType.refCount++;
8051 exp.op.exp2.destType = exp.destType;
8053 exp.destType.refCount++;
8056 if(type1) type1.refCount++;
8057 exp.expType = type1;
8062 PrintExpression(exp.op.exp2, expString);
8064 if(type1 && type1.kind == pointerType)
8066 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 ||
8067 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8068 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8069 else if(exp.op.op == '=')
8071 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8072 exp.op.exp2.destType = type1;
8079 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8080 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/* ||
8081 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8084 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8085 exp.op.exp2.destType = type1;
8090 if(type1) type1.refCount++;
8091 exp.expType = type1;
8093 else if(exp.destType && exp.destType.kind == classType &&
8094 exp.destType._class && exp.destType._class.registered &&
8096 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
8097 (exp.destType._class.registered.type == enumClass && useDestType))
8100 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8101 exp.op.exp2.destType = exp.destType;
8103 exp.destType.refCount++;
8107 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8108 exp.op.exp2.destType = dummy;
8112 // TESTING THIS HERE... (DANGEROUS)
8113 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8114 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8116 FreeType(exp.op.exp2.destType);
8117 exp.op.exp2.destType = type1;
8120 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8121 // Cannot lose the cast on a sizeof
8122 if(exp.op.op == SIZEOF)
8124 Expression e = exp.op.exp2;
8125 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8127 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8129 if(e.type == extensionCompoundExp)
8130 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8135 if(e.type == castExp && e.cast.exp)
8136 e.cast.exp.needCast = true;
8138 ProcessExpressionType(exp.op.exp2);
8139 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8141 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8143 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)
8145 if(exp.op.op != '=' && type1.type.kind == voidType)
8146 Compiler_Error($"void *: unknown size\n");
8148 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||
8149 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8150 (exp.op.exp2.expType._class.registered.type == normalClass ||
8151 exp.op.exp2.expType._class.registered.type == structClass ||
8152 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8154 if(exp.op.op == ADD_ASSIGN)
8155 Compiler_Error($"cannot add two pointers\n");
8157 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8158 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8160 if(exp.op.op == ADD_ASSIGN)
8161 Compiler_Error($"cannot add two pointers\n");
8165 char type1String[1024];
8166 char type2String[1024];
8167 type1String[0] = '\0';
8168 type2String[0] = '\0';
8170 PrintType(exp.op.exp2.expType, type1String, false, true);
8171 PrintType(type1, type2String, false, true);
8172 ChangeCh(expString, '\n', ' ');
8173 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8177 if(exp.op.exp2.destType == dummy)
8180 exp.op.exp2.destType = null;
8183 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8187 CopyTypeInto(type2, exp.op.exp2.expType);
8188 type2.isSigned = true;
8190 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8192 type2 = { kind = intType };
8194 type2.isSigned = true;
8198 type2 = exp.op.exp2.expType;
8199 if(type2) type2.refCount++;
8203 dummy.kind = voidType;
8205 if(exp.op.op == SIZEOF)
8212 exp.isConstant = true;
8214 // Get type of dereferenced pointer
8215 else if(exp.op.op == '*' && !exp.op.exp1)
8217 exp.expType = Dereference(type2);
8218 if(type2 && type2.kind == classType)
8219 notByReference = true;
8221 else if(exp.op.op == '&' && !exp.op.exp1)
8222 exp.expType = Reference(type2);
8229 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8230 exp.op.exp1.destType = MkClassType("bool");
8231 exp.op.exp1.destType.truth = true;
8232 if(!exp.op.exp1.expType)
8233 ProcessExpressionType(exp.op.exp1);
8235 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8236 FreeType(exp.op.exp1.expType);
8237 exp.op.exp1.expType = MkClassType("bool");
8238 exp.op.exp1.expType.truth = true;
8242 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8243 exp.op.exp2.destType = MkClassType("bool");
8244 exp.op.exp2.destType.truth = true;
8245 if(!exp.op.exp2.expType)
8246 ProcessExpressionType(exp.op.exp2);
8248 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8249 FreeType(exp.op.exp2.expType);
8250 exp.op.exp2.expType = MkClassType("bool");
8251 exp.op.exp2.expType.truth = true;
8254 else if(exp.op.exp1 && exp.op.exp2 &&
8257 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8258 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8259 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8260 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8262 if(type1 && type2 &&
8263 // If either both are class or both are not class
8264 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8266 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8267 exp.op.exp2.destType = type1;
8269 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8270 exp.op.exp1.destType = type2;
8272 // Warning here for adding Radians + Degrees with no destination type
8273 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8274 type1._class.registered && type1._class.registered.type == unitClass &&
8275 type2._class.registered && type2._class.registered.type == unitClass &&
8276 type1._class.registered != type2._class.registered)
8277 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8278 type1._class.string, type2._class.string, type1._class.string);
8280 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8282 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8285 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8287 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8288 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8291 ProcessExpressionType(exp.op.exp1);
8293 if(type2.kind != pointerType)
8295 ProcessExpressionType(classExp);
8297 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8298 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8299 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8301 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8304 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8305 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8306 MkPointer(null, null), null)))),
8307 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8309 if(!exp.op.exp2.expType)
8313 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8317 ProcessExpressionType(exp.op.exp2);
8322 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)))
8324 if(type1.kind != classType && type1.type.kind == voidType)
8325 Compiler_Error($"void *: unknown size\n");
8326 exp.expType = type1;
8327 if(type1) type1.refCount++;
8329 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)))
8331 if(type2.kind != classType && type2.type.kind == voidType)
8332 Compiler_Error($"void *: unknown size\n");
8333 exp.expType = type2;
8334 if(type2) type2.refCount++;
8336 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8337 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8339 Compiler_Warning($"different levels of indirection\n");
8343 bool success = false;
8344 if(type1.kind == pointerType && type2.kind == pointerType)
8346 if(exp.op.op == '+')
8347 Compiler_Error($"cannot add two pointers\n");
8348 else if(exp.op.op == '-')
8350 // Pointer Subtraction gives integer
8351 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8360 if(type1.type.kind == templateType)
8362 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8365 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8367 ProcessExpressionType(classExp);
8369 exp.type = bracketsExp;
8370 exp.list = MkListOne(MkExpOp(
8371 MkExpBrackets(MkListOne(MkExpOp(
8372 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8374 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8376 //MkExpMember(classExp, MkIdentifier("typeSize"))
8378 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8379 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8381 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8384 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8385 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8386 MkPointer(null, null), null)))),
8387 MkExpMember(classExp, MkIdentifier("typeSize")))))
8392 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8401 if(!success && exp.op.exp1.type == constantExp)
8403 // If first expression is constant, try to match that first
8404 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8406 if(exp.expType) FreeType(exp.expType);
8407 exp.expType = exp.op.exp1.destType;
8408 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8411 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8413 if(exp.expType) FreeType(exp.expType);
8414 exp.expType = exp.op.exp2.destType;
8415 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8421 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8423 if(exp.expType) FreeType(exp.expType);
8424 exp.expType = exp.op.exp2.destType;
8425 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8428 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8430 if(exp.expType) FreeType(exp.expType);
8431 exp.expType = exp.op.exp1.destType;
8432 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8438 char expString1[10240];
8439 char expString2[10240];
8442 expString1[0] = '\0';
8443 expString2[0] = '\0';
8448 PrintExpression(exp.op.exp1, expString1);
8449 ChangeCh(expString1, '\n', ' ');
8450 PrintExpression(exp.op.exp2, expString2);
8451 ChangeCh(expString2, '\n', ' ');
8452 PrintType(exp.op.exp1.expType, type1, false, true);
8453 PrintType(exp.op.exp2.expType, type2, false, true);
8456 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8460 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8461 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8463 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8464 // Convert e.g. / 4 into / 4.0
8465 exp.op.exp1.destType = type2._class.registered.dataType;
8466 if(type2._class.registered.dataType)
8467 type2._class.registered.dataType.refCount++;
8468 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8469 exp.expType = type2;
8470 if(type2) type2.refCount++;
8472 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8474 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8475 // Convert e.g. / 4 into / 4.0
8476 exp.op.exp2.destType = type1._class.registered.dataType;
8477 if(type1._class.registered.dataType)
8478 type1._class.registered.dataType.refCount++;
8479 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8480 exp.expType = type1;
8481 if(type1) type1.refCount++;
8487 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8489 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8491 if(!type1._class.registered.dataType)
8492 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8493 exp.op.exp2.destType = type1._class.registered.dataType;
8494 exp.op.exp2.destType.refCount++;
8496 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8499 type2 = exp.op.exp2.destType;
8500 if(type2) type2.refCount++;
8502 exp.expType = type2;
8506 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8508 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8510 if(!type2._class.registered.dataType)
8511 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8512 exp.op.exp1.destType = type2._class.registered.dataType;
8513 exp.op.exp1.destType.refCount++;
8515 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8516 type1 = exp.op.exp1.destType;
8517 exp.expType = type1;
8521 // TESTING THIS NEW CODE
8522 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8524 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8526 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8528 if(exp.expType) FreeType(exp.expType);
8529 exp.expType = exp.op.exp1.expType;
8530 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8535 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8537 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8539 if(exp.expType) FreeType(exp.expType);
8540 exp.expType = exp.op.exp2.expType;
8541 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8549 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8550 exp.op.exp2.destType = type1;
8554 // Maybe this was meant to be an enum...
8555 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8557 Type oldType = exp.op.exp2.expType;
8558 exp.op.exp2.expType = null;
8559 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8562 exp.op.exp2.expType = oldType;
8567 // TESTING THIS HERE... LATEST ADDITION
8568 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8570 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8571 exp.op.exp2.destType = type2._class.registered.dataType;
8572 if(type2._class.registered.dataType)
8573 type2._class.registered.dataType.refCount++;
8574 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8576 //exp.expType = type2._class.registered.dataType; //type2;
8577 //if(type2) type2.refCount++;
8580 // TESTING THIS HERE... LATEST ADDITION
8581 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8583 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8584 exp.op.exp1.destType = type1._class.registered.dataType;
8585 if(type1._class.registered.dataType)
8586 type1._class.registered.dataType.refCount++;
8587 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8588 exp.expType = type1._class.registered.dataType; //type1;
8589 if(type1) type1.refCount++;
8593 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8595 if(exp.expType) FreeType(exp.expType);
8596 exp.expType = exp.op.exp2.destType;
8597 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8599 else if(type1 && type2)
8601 char expString1[10240];
8602 char expString2[10240];
8603 char type1String[1024];
8604 char type2String[1024];
8605 expString1[0] = '\0';
8606 expString2[0] = '\0';
8607 type1String[0] = '\0';
8608 type2String[0] = '\0';
8611 PrintExpression(exp.op.exp1, expString1);
8612 ChangeCh(expString1, '\n', ' ');
8613 PrintExpression(exp.op.exp2, expString2);
8614 ChangeCh(expString2, '\n', ' ');
8615 PrintType(exp.op.exp1.expType, type1String, false, true);
8616 PrintType(exp.op.exp2.expType, type2String, false, true);
8619 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8621 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8623 exp.expType = exp.op.exp1.expType;
8624 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8626 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8628 exp.expType = exp.op.exp2.expType;
8629 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8636 // Maybe this was meant to be an enum...
8637 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8639 Type oldType = exp.op.exp1.expType;
8640 exp.op.exp1.expType = null;
8641 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8644 exp.op.exp1.expType = oldType;
8647 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8648 exp.op.exp1.destType = type2;
8651 // TESTING THIS HERE... LATEST ADDITION
8652 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8654 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8655 exp.op.exp1.destType = type1._class.registered.dataType;
8656 if(type1._class.registered.dataType)
8657 type1._class.registered.dataType.refCount++;
8660 // TESTING THIS HERE... LATEST ADDITION
8661 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8663 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8664 exp.op.exp2.destType = type2._class.registered.dataType;
8665 if(type2._class.registered.dataType)
8666 type2._class.registered.dataType.refCount++;
8670 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8672 if(exp.expType) FreeType(exp.expType);
8673 exp.expType = exp.op.exp1.destType;
8674 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8678 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8680 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8682 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8683 // Convert e.g. / 4 into / 4.0
8684 exp.op.exp1.destType = type2._class.registered.dataType;
8685 if(type2._class.registered.dataType)
8686 type2._class.registered.dataType.refCount++;
8687 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8689 if(exp.op.op == '!')
8691 exp.expType = MkClassType("bool");
8692 exp.expType.truth = true;
8696 exp.expType = type2;
8697 if(type2) type2.refCount++;
8700 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8702 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8704 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8705 // Convert e.g. / 4 into / 4.0
8706 exp.op.exp2.destType = type1._class.registered.dataType;
8707 if(type1._class.registered.dataType)
8708 type1._class.registered.dataType.refCount++;
8709 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8711 exp.expType = type1;
8712 if(type1) type1.refCount++;
8717 if(exp.op.exp1 && !exp.op.exp1.expType)
8719 char expString[10000];
8720 expString[0] = '\0';
8723 PrintExpression(exp.op.exp1, expString);
8724 ChangeCh(expString, '\n', ' ');
8727 Compiler_Error($"couldn't determine type of %s\n", expString);
8729 if(exp.op.exp2 && !exp.op.exp2.expType)
8731 char expString[10240];
8732 expString[0] = '\0';
8735 PrintExpression(exp.op.exp2, expString);
8736 ChangeCh(expString, '\n', ' ');
8739 Compiler_Error($"couldn't determine type of %s\n", expString);
8744 FreeType(exp.expType);
8745 exp.expType = MkClassType("bool");
8746 exp.expType.truth = true;
8749 if(exp.op.op != SIZEOF)
8750 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8751 (!exp.op.exp2 || exp.op.exp2.isConstant);
8753 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8755 DeclareType(exp.op.exp2.expType, false, false);
8766 case extensionExpressionExp:
8769 exp.isConstant = true;
8770 for(e = exp.list->first; e; e = e.next)
8775 FreeType(e.destType);
8776 e.destType = exp.destType;
8777 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8779 ProcessExpressionType(e);
8781 exp.destType.count--;
8782 if(!exp.expType && !e.next)
8784 exp.expType = e.expType;
8785 if(e.expType) e.expType.refCount++;
8788 exp.isConstant = false;
8791 // In case a cast became a member...
8792 e = exp.list->first;
8793 if(!e.next && e.type == memberExp)
8795 // Preserve prev, next
8796 Expression next = exp.next, prev = exp.prev;
8799 FreeType(exp.expType);
8800 FreeType(exp.destType);
8810 ProcessExpressionType(exp);
8817 exp.isConstant = true;
8819 ProcessExpressionType(exp.index.exp);
8820 if(!exp.index.exp.isConstant)
8821 exp.isConstant = false;
8823 if(exp.index.exp.expType)
8825 Type source = exp.index.exp.expType;
8826 if(source.kind == classType && source._class && source._class.registered)
8828 Class _class = source._class.registered;
8829 Class c = _class.templateClass ? _class.templateClass : _class;
8830 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
8832 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8834 if(exp.index.index && exp.index.index->last)
8836 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8842 for(e = exp.index.index->first; e; e = e.next)
8844 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8846 if(e.destType) FreeType(e.destType);
8847 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8849 ProcessExpressionType(e);
8852 // Check if this type is int
8855 exp.isConstant = false;
8859 exp.expType = Dereference(exp.index.exp.expType);
8861 DeclareType(exp.expType, false, false);
8868 Type methodType = null;
8874 PrintExpression(exp.call.exp, name);
8875 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8877 //exp.call.exp.expType = null;
8878 PrintExpression(exp.call.exp, name);
8881 if(exp.call.exp.type == identifierExp)
8883 Expression idExp = exp.call.exp;
8884 Identifier id = idExp.identifier;
8885 if(!strcmp(id.string, "__builtin_frame_address"))
8887 exp.expType = ProcessTypeString("void *", true);
8888 if(exp.call.arguments && exp.call.arguments->first)
8889 ProcessExpressionType(exp.call.arguments->first);
8892 else if(!strcmp(id.string, "__ENDIAN_PAD"))
8894 exp.expType = ProcessTypeString("int", true);
8895 if(exp.call.arguments && exp.call.arguments->first)
8896 ProcessExpressionType(exp.call.arguments->first);
8899 else if(!strcmp(id.string, "Max") ||
8900 !strcmp(id.string, "Min") ||
8901 !strcmp(id.string, "Sgn") ||
8902 !strcmp(id.string, "Abs"))
8904 Expression a = null;
8905 Expression b = null;
8906 Expression tempExp1 = null, tempExp2 = null;
8907 if((!strcmp(id.string, "Max") ||
8908 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8910 a = exp.call.arguments->first;
8911 b = exp.call.arguments->last;
8915 else if(exp.call.arguments->count == 1)
8917 a = exp.call.arguments->first;
8923 exp.call.arguments->Clear();
8924 idExp.identifier = null;
8926 FreeExpContents(exp);
8928 ProcessExpressionType(a);
8930 ProcessExpressionType(b);
8932 exp.type = bracketsExp;
8933 exp.list = MkList();
8935 if(a.expType && (!b || b.expType))
8937 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8939 // Use the simpleStruct name/ids for now...
8942 OldList * specs = MkList();
8943 OldList * decls = MkList();
8945 char temp1[1024], temp2[1024];
8947 GetTypeSpecs(a.expType, specs);
8949 if(a && !a.isConstant && a.type != identifierExp)
8951 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8952 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8953 tempExp1 = QMkExpId(temp1);
8954 tempExp1.expType = a.expType;
8956 a.expType.refCount++;
8957 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8959 if(b && !b.isConstant && b.type != identifierExp)
8961 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8962 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8963 tempExp2 = QMkExpId(temp2);
8964 tempExp2.expType = b.expType;
8966 b.expType.refCount++;
8967 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8970 decl = MkDeclaration(specs, decls);
8971 if(!curCompound.compound.declarations)
8972 curCompound.compound.declarations = MkList();
8973 curCompound.compound.declarations->Insert(null, decl);
8978 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8980 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8982 MkExpCondition(MkExpBrackets(MkListOne(
8983 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8984 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8985 exp.expType = a.expType;
8987 a.expType.refCount++;
8989 else if(!strcmp(id.string, "Abs"))
8992 MkExpCondition(MkExpBrackets(MkListOne(
8993 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8994 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8995 exp.expType = a.expType;
8997 a.expType.refCount++;
8999 else if(!strcmp(id.string, "Sgn"))
9001 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9003 MkExpCondition(MkExpBrackets(MkListOne(
9004 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9005 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9006 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9007 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9008 exp.expType = ProcessTypeString("int", false);
9011 FreeExpression(tempExp1);
9012 if(tempExp2) FreeExpression(tempExp2);
9026 if(!exp.call.exp.destType)
9028 exp.call.exp.destType = dummy;
9031 ProcessExpressionType(exp.call.exp);
9032 if(exp.call.exp.destType == dummy)
9035 exp.call.exp.destType = null;
9040 // Check argument types against parameter types
9041 functionType = exp.call.exp.expType;
9043 if(functionType && functionType.kind == TypeKind::methodType)
9045 methodType = functionType;
9046 functionType = methodType.method.dataType;
9048 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9049 // TOCHECK: Instead of doing this here could this be done per param?
9050 if(exp.call.exp.expType.usedClass)
9052 char typeString[1024];
9053 typeString[0] = '\0';
9055 Symbol back = functionType.thisClass;
9056 // Do not output class specifier here (thisclass was added to this)
9057 functionType.thisClass = null;
9058 PrintType(functionType, typeString, true, true);
9059 functionType.thisClass = back;
9061 if(strstr(typeString, "thisclass"))
9063 OldList * specs = MkList();
9066 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9068 decl = SpecDeclFromString(typeString, specs, null);
9070 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9071 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9072 exp.call.exp.expType.usedClass))
9073 thisClassParams = false;
9075 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9077 Class backupThisClass = thisClass;
9078 thisClass = exp.call.exp.expType.usedClass;
9079 ProcessDeclarator(decl);
9080 thisClass = backupThisClass;
9083 thisClassParams = true;
9085 functionType = ProcessType(specs, decl);
9086 functionType.refCount = 0;
9087 FinishTemplatesContext(context);
9090 FreeList(specs, FreeSpecifier);
9091 FreeDeclarator(decl);
9095 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9097 Type type = functionType.type;
9098 if(!functionType.refCount)
9100 functionType.type = null;
9101 FreeType(functionType);
9103 //methodType = functionType;
9104 functionType = type;
9106 if(functionType && functionType.kind != TypeKind::functionType)
9108 Compiler_Error($"called object %s is not a function\n", name);
9110 else if(functionType)
9112 bool emptyParams = false, noParams = false;
9113 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9114 Type type = functionType.params.first;
9115 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9117 Location oldyylloc = yylloc;
9119 if(!type) emptyParams = true;
9122 if(functionType.extraParam && e && functionType.thisClass)
9124 e.destType = MkClassType(functionType.thisClass.string);
9128 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9129 // Fixed #141 by adding '&& !functionType.extraParam'
9130 if(!functionType.staticMethod && !functionType.extraParam)
9132 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9133 memberExp.member.exp.expType._class)
9135 type = MkClassType(memberExp.member.exp.expType._class.string);
9140 type = functionType.params.first;
9145 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9147 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9148 type.byReference = functionType.byReference;
9149 type.typedByReference = functionType.typedByReference;
9152 // Allow manually passing a class for typed object
9153 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9157 type = functionType.params.first;
9165 if(type && type.kind == voidType)
9168 if(!type.refCount) FreeType(type);
9172 for( ; e; e = e.next)
9174 if(!type && !emptyParams)
9177 if(methodType && methodType.methodClass)
9178 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9179 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9180 noParams ? 0 : functionType.params.count);
9182 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9183 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9184 noParams ? 0 : functionType.params.count);
9188 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9190 Type templatedType = null;
9191 Class _class = methodType.usedClass;
9192 ClassTemplateParameter curParam = null;
9194 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9197 for(sClass = _class; sClass; sClass = sClass.base)
9199 if(sClass.templateClass) sClass = sClass.templateClass;
9201 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9203 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9206 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9208 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9209 id += nextClass.templateParams.count;
9218 if(curParam && _class.templateArgs[id].dataTypeString)
9220 ClassTemplateArgument arg = _class.templateArgs[id];
9222 Context context = SetupTemplatesContext(_class);
9225 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9226 templatedType = ProcessTypeString(arg.dataTypeString, false);
9227 FinishTemplatesContext(context);
9229 e.destType = templatedType;
9232 templatedType.passAsTemplate = true;
9233 // templatedType.refCount++;
9239 if(type) type.refCount++;
9244 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9246 e.destType = type.prev;
9247 e.destType.refCount++;
9252 if(type) type.refCount++;
9255 // Don't reach the end for the ellipsis
9256 if(type && type.kind != ellipsisType)
9258 Type next = type.next;
9259 if(!type.refCount) FreeType(type);
9264 if(type && type.kind != ellipsisType)
9266 if(methodType && methodType.methodClass)
9267 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9268 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9269 functionType.params.count + extra);
9271 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9272 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9273 functionType.params.count + extra);
9276 if(type && !type.refCount) FreeType(type);
9283 kind = TypeKind::functionType;
9286 if(exp.call.exp.type == identifierExp)
9288 char * string = exp.call.exp.identifier.string;
9292 Location oldyylloc = yylloc;
9294 yylloc = exp.call.exp.identifier.loc;
9295 if(strstr(string, "__builtin_") == string)
9299 functionType.returnType = exp.destType;
9300 exp.destType.refCount++;
9304 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9305 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9306 globalContext.symbols.Add((BTNode)symbol);
9307 if(strstr(symbol.string, "::"))
9308 globalContext.hasNameSpace = true;
9313 else if(exp.call.exp.type == memberExp)
9315 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9316 exp.call.exp.member.member.string);*/
9319 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9321 if(!functionType.returnType)
9323 functionType.returnType = Type
9330 if(functionType && functionType.kind == TypeKind::functionType)
9332 exp.expType = functionType.returnType;
9334 if(functionType.returnType)
9335 functionType.returnType.refCount++;
9337 if(!functionType.refCount)
9338 FreeType(functionType);
9341 if(exp.call.arguments)
9343 for(e = exp.call.arguments->first; e; e = e.next)
9345 Type destType = e.destType;
9346 ProcessExpressionType(e);
9354 Location oldyylloc = yylloc;
9356 Expression checkExp = exp.member.exp;
9359 if(checkExp.type == castExp)
9360 checkExp = checkExp.cast.exp;
9361 else if(checkExp.type == bracketsExp)
9362 checkExp = checkExp.list ? checkExp.list->first : null;
9367 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9368 exp.thisPtr = thisPtr;
9370 // DOING THIS LATER NOW...
9371 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9373 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9374 /* TODO: Name Space Fix ups
9375 if(!exp.member.member.classSym)
9376 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9380 ProcessExpressionType(exp.member.exp);
9381 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9382 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9384 exp.isConstant = false;
9387 exp.isConstant = exp.member.exp.isConstant;
9388 type = exp.member.exp.expType;
9392 if(type && (type.kind == templateType))
9394 Class _class = thisClass ? thisClass : currentClass;
9395 ClassTemplateParameter param = null;
9398 for(param = _class.templateParams.first; param; param = param.next)
9400 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9404 if(param && param.defaultArg.member)
9406 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9409 Expression expMember = exp.member.exp;
9411 OldList * specs = MkList();
9412 char thisClassTypeString[1024];
9414 FreeIdentifier(exp.member.member);
9416 ProcessExpressionType(argExp);
9419 char * colon = strstr(param.defaultArg.memberString, "::");
9422 char className[1024];
9425 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9426 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9429 strcpy(thisClassTypeString, _class.fullName);
9432 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9434 exp.expType = ProcessType(specs, decl);
9435 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9437 Class expClass = exp.expType._class.registered;
9438 Class cClass = null;
9443 char templateString[1024];
9444 ClassTemplateParameter param;
9445 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9446 for(cClass = expClass; cClass; cClass = cClass.base)
9449 for(param = cClass.templateParams.first; param; param = param.next)
9453 ClassTemplateArgument arg;
9454 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9455 arg = expClass.templateArgs[id];
9457 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9459 ClassTemplateParameter cParam;
9460 //int p = numParams - sClass.templateParams.count;
9463 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9465 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9467 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9469 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9471 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9472 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9484 strcat(argument, arg.name.string);
9485 strcat(argument, " = ");
9491 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9492 char expString[1024];
9493 OldList * specs = MkList();
9494 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9496 char * string = PrintHexUInt64(arg.expression.ui64);
9497 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9500 ProcessExpressionType(exp);
9501 ComputeExpression(exp);
9502 expString[0] = '\0';
9503 PrintExpression(exp, expString);
9504 strcat(argument, expString);
9506 FreeExpression(exp);
9511 strcat(argument, arg.member.name);
9514 case TemplateParameterType::type:
9516 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9518 if(!strcmp(arg.dataTypeString, "thisclass"))
9519 strcat(argument, thisClassTypeString);
9521 strcat(argument, arg.dataTypeString);
9528 if(paramCount) strcat(templateString, ", ");
9529 if(lastParam != p - 1)
9531 strcat(templateString, param.name);
9532 strcat(templateString, " = ");
9534 strcat(templateString, argument);
9543 int len = strlen(templateString);
9544 if(templateString[len-1] == '>') templateString[len++] = ' ';
9545 templateString[len++] = '>';
9546 templateString[len++] = '\0';
9549 Context context = SetupTemplatesContext(_class);
9550 FreeType(exp.expType);
9551 exp.expType = ProcessTypeString(templateString, false);
9552 FinishTemplatesContext(context);
9556 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9557 exp.type = bracketsExp;
9558 exp.list = MkListOne(MkExpOp(null, '*',
9563 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9564 MkExpBrackets(MkListOne(
9565 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9567 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9569 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9574 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9575 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9577 type = ProcessTemplateParameterType(type.templateParameter);
9580 // TODO: *** This seems to be where we should add method support for all basic types ***
9581 if(type && (type.kind == templateType));
9582 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9583 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
9584 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9585 (type.kind == pointerType && type.type.kind == charType)))
9587 Identifier id = exp.member.member;
9588 TypeKind typeKind = type.kind;
9589 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9590 if(typeKind == subClassType && exp.member.exp.type == classExp)
9592 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9593 typeKind = classType;
9598 if(typeKind == intType || typeKind == enumType)
9599 _class = eSystem_FindClass(privateModule, "int");
9602 if(type.kind == classType && type._class && type._class.registered)
9604 _class = type._class.registered;
9606 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
9608 _class = FindClass("char *").registered;
9610 else if(type.kind == pointerType)
9612 _class = eSystem_FindClass(privateModule, "uintptr");
9613 FreeType(exp.expType);
9614 exp.expType = ProcessTypeString("uintptr", false);
9615 exp.byReference = true;
9619 char string[1024] = "";
9621 PrintTypeNoConst(type, string, false, true);
9622 classSym = FindClass(string);
9623 if(classSym) _class = classSym.registered;
9631 (exp.member.exp.type == identifierExp &&
9632 !strcmp(exp.member.exp.identifier.string, "this"));*/
9633 Property prop = null;
9634 Method method = null;
9635 DataMember member = null;
9636 Property revConvert = null;
9637 ClassProperty classProp = null;
9639 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9640 exp.member.memberType = propertyMember;
9642 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9643 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9645 if(typeKind != subClassType)
9647 // Prioritize data members over properties for "this"
9648 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9650 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9651 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9653 prop = eClass_FindProperty(_class, id.string, privateModule);
9657 if(!member && !prop)
9658 prop = eClass_FindProperty(_class, id.string, privateModule);
9659 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9660 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9661 exp.member.thisPtr = true;
9663 // Prioritize properties over data members otherwise
9666 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9669 prop = eClass_FindProperty(_class, id.string, null);
9670 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9671 member = eClass_FindDataMember(_class, id.string, null, null, null);
9674 if(!prop && !member)
9676 method = eClass_FindMethod(_class, id.string, null);
9679 prop = eClass_FindProperty(_class, id.string, privateModule);
9680 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9681 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9687 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9694 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
9695 method = eClass_FindMethod(_class, id.string, privateModule);
9696 if(!prop && !member && !method)
9698 if(typeKind == subClassType)
9700 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9703 exp.member.memberType = classPropertyMember;
9704 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9708 // Assume this is a class_data member
9709 char structName[1024];
9710 Identifier id = exp.member.member;
9711 Expression classExp = exp.member.exp;
9714 FreeType(classExp.expType);
9715 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9717 strcpy(structName, "__ecereClassData_");
9718 FullClassNameCat(structName, type._class.string, false);
9719 exp.type = pointerExp;
9720 exp.member.member = id;
9722 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9723 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9724 MkExpBrackets(MkListOne(MkExpOp(
9725 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9726 MkExpMember(classExp, MkIdentifier("data"))), '+',
9727 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9732 ProcessExpressionType(exp);
9738 // Check for reverse conversion
9739 // (Convert in an instantiation later, so that we can use
9740 // deep properties system)
9741 Symbol classSym = FindClass(id.string);
9744 Class convertClass = classSym.registered;
9746 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9753 exp.member.memberType = propertyMember;
9755 ProcessPropertyType(prop);
9756 exp.expType = prop.dataType;
9757 if(prop.dataType) prop.dataType.refCount++;
9761 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9763 FreeExpContents(exp);
9764 exp.type = identifierExp;
9765 exp.identifier = MkIdentifier("class");
9766 ProcessExpressionType(exp);
9770 exp.member.memberType = dataMember;
9771 DeclareStruct(_class.fullName, false);
9772 if(!member.dataType)
9774 Context context = SetupTemplatesContext(_class);
9775 member.dataType = ProcessTypeString(member.dataTypeString, false);
9776 FinishTemplatesContext(context);
9778 exp.expType = member.dataType;
9779 if(member.dataType) member.dataType.refCount++;
9783 exp.member.memberType = reverseConversionMember;
9784 exp.expType = MkClassType(revConvert._class.fullName);
9792 exp.type = identifierExp;
9793 exp.identifier = exp.member.member;
9796 exp.member.memberType = methodMember;
9798 if(!method.dataType)
9799 ProcessMethodType(method);
9807 // Tricky spot here... To use instance versus class virtual table
9808 // Put it back to what it was... What did we break?
9810 // Had to put it back for overriding Main of Thread global instance
9812 //exp.expType.methodClass = _class;
9813 exp.expType.methodClass = (id && id._class) ? _class : null;
9815 // Need the actual class used for templated classes
9816 exp.expType.usedClass = _class;
9820 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9822 FreeExpContents(exp);
9823 exp.type = identifierExp;
9824 exp.identifier = MkIdentifier("class");
9825 FreeType(exp.expType);
9826 exp.expType = MkClassType("ecere::com::Class");
9829 yylloc = exp.member.member.loc;
9830 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9832 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9835 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9840 while(tClass && !tClass.templateClass) tClass = tClass.base;
9842 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9845 ClassTemplateParameter curParam = null;
9848 for(sClass = tClass; sClass; sClass = sClass.base)
9851 if(sClass.templateClass) sClass = sClass.templateClass;
9852 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9854 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9856 for(sClass = sClass.base; sClass; sClass = sClass.base)
9857 id += sClass.templateParams.count;
9865 if(curParam && tClass.templateArgs[id].dataTypeString)
9867 ClassTemplateArgument arg = tClass.templateArgs[id];
9868 Context context = SetupTemplatesContext(tClass);
9870 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9871 FreeType(exp.expType);
9872 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9875 if(exp.expType.kind == thisClassType)
9877 FreeType(exp.expType);
9878 exp.expType = ReplaceThisClassType(_class);
9881 if(tClass.templateClass)
9882 exp.expType.passAsTemplate = true;
9883 //exp.expType.refCount++;
9886 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9887 //exp.destType.refCount++;
9889 if(exp.destType.kind == thisClassType)
9891 FreeType(exp.destType);
9892 exp.destType = ReplaceThisClassType(_class);
9896 FinishTemplatesContext(context);
9899 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9900 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9903 ClassTemplateParameter curParam = null;
9906 for(sClass = tClass; sClass; sClass = sClass.base)
9909 if(sClass.templateClass) sClass = sClass.templateClass;
9910 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9912 if(curParam.type == TemplateParameterType::type &&
9913 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9915 for(sClass = sClass.base; sClass; sClass = sClass.base)
9916 id += sClass.templateParams.count;
9926 ClassTemplateArgument arg = tClass.templateArgs[id];
9927 Context context = SetupTemplatesContext(tClass);
9930 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9932 basicType = ProcessTypeString(arg.dataTypeString, false);
9935 if(basicType.kind == thisClassType)
9937 FreeType(basicType);
9938 basicType = ReplaceThisClassType(_class);
9941 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9942 if(tClass.templateClass)
9943 basicType.passAsTemplate = true;
9946 FreeType(exp.expType);
9948 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9949 //exp.expType.refCount++;
9952 exp.destType = exp.expType;
9953 exp.destType.refCount++;
9957 Expression newExp { };
9958 OldList * specs = MkList();
9960 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9962 if(exp.destType) exp.destType.refCount++;
9963 if(exp.expType) exp.expType.refCount++;
9965 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9966 exp.cast.exp = newExp;
9967 //FreeType(exp.expType);
9968 //exp.expType = null;
9969 //ProcessExpressionType(sourceExp);
9972 FinishTemplatesContext(context);
9975 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9977 Class expClass = exp.expType._class.registered;
9980 Class cClass = null;
9985 char templateString[1024];
9986 ClassTemplateParameter param;
9987 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9988 while(cClass != expClass)
9991 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9994 for(param = cClass.templateParams.first; param; param = param.next)
9996 Class cClassCur = null;
9999 ClassTemplateParameter paramCur = null;
10000 ClassTemplateArgument arg;
10001 while(cClassCur != tClass && !paramCur)
10004 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10005 cClassCur = sClassCur;
10007 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10009 if(!strcmp(paramCur.name, param.name))
10017 if(paramCur && paramCur.type == TemplateParameterType::type)
10018 arg = tClass.templateArgs[cp];
10020 arg = expClass.templateArgs[p];
10023 char argument[256];
10024 argument[0] = '\0';
10027 strcat(argument, arg.name.string);
10028 strcat(argument, " = ");
10034 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10035 char expString[1024];
10036 OldList * specs = MkList();
10037 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10039 char * string = PrintHexUInt64(arg.expression.ui64);
10040 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10043 ProcessExpressionType(exp);
10044 ComputeExpression(exp);
10045 expString[0] = '\0';
10046 PrintExpression(exp, expString);
10047 strcat(argument, expString);
10049 FreeExpression(exp);
10054 strcat(argument, arg.member.name);
10057 case TemplateParameterType::type:
10059 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10060 strcat(argument, arg.dataTypeString);
10066 if(paramCount) strcat(templateString, ", ");
10067 if(lastParam != p - 1)
10069 strcat(templateString, param.name);
10070 strcat(templateString, " = ");
10072 strcat(templateString, argument);
10081 int len = strlen(templateString);
10082 if(templateString[len-1] == '>') templateString[len++] = ' ';
10083 templateString[len++] = '>';
10084 templateString[len++] = '\0';
10087 FreeType(exp.expType);
10089 Context context = SetupTemplatesContext(tClass);
10090 exp.expType = ProcessTypeString(templateString, false);
10091 FinishTemplatesContext(context);
10098 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10100 else if(type && (type.kind == structType || type.kind == unionType))
10102 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10105 exp.expType = memberType;
10107 memberType.refCount++;
10112 char expString[10240];
10113 expString[0] = '\0';
10114 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10115 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10118 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10120 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10122 Identifier id = exp.member.member;
10123 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10126 FreeType(exp.expType);
10127 exp.expType = ReplaceThisClassType(_class);
10131 yylloc = oldyylloc;
10134 // Convert x->y into (*x).y
10137 Type destType = exp.destType;
10139 // DOING THIS LATER NOW...
10140 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10142 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10143 /* TODO: Name Space Fix ups
10144 if(!exp.member.member.classSym)
10145 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10149 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10150 exp.type = memberExp;
10153 ProcessExpressionType(exp);
10160 //ComputeExpression(exp);
10162 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10163 if(classSym && classSym.registered)
10165 if(classSym.registered.type == noHeadClass)
10169 DeclareStruct(classSym.string, false);
10170 FreeSpecifier(exp._class);
10171 exp.type = typeSizeExp;
10172 FullClassNameCat(name, classSym.string, false);
10173 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10177 if(classSym.registered.fixed)
10179 FreeSpecifier(exp._class);
10180 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10181 exp.type = constantExp;
10185 char className[1024];
10186 strcpy(className, "__ecereClass_");
10187 FullClassNameCat(className, classSym.string, true);
10188 MangleClassName(className);
10190 DeclareClass(classSym, className);
10192 FreeExpContents(exp);
10193 exp.type = pointerExp;
10194 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10195 exp.member.member = MkIdentifier("structSize");
10205 // exp.isConstant = true;
10210 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10217 exp.isConstant = true;
10219 DeclareType(type, false, false);
10225 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10227 FreeType(exp.cast.exp.destType);
10228 exp.cast.exp.destType = type;
10230 ProcessExpressionType(exp.cast.exp);
10232 exp.expType = type;
10235 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10236 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10238 void * prev = exp.prev, * next = exp.next;
10239 Type expType = exp.cast.exp.destType;
10240 Expression castExp = exp.cast.exp;
10241 Type destType = exp.destType;
10243 if(expType) expType.refCount++;
10245 //FreeType(exp.destType);
10246 FreeType(exp.expType);
10247 FreeTypeName(exp.cast.typeName);
10250 FreeType(exp.expType);
10251 FreeType(exp.destType);
10253 exp.expType = expType;
10254 exp.destType = destType;
10264 exp.isConstant = exp.cast.exp.isConstant;
10269 case extensionInitializerExp:
10271 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10272 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10273 // ProcessInitializer(exp.initializer.initializer, type);
10274 exp.expType = type;
10279 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10280 ProcessExpressionType(exp.vaArg.exp);
10281 exp.expType = type;
10287 exp.isConstant = true;
10289 FreeType(exp.cond.cond.destType);
10290 exp.cond.cond.destType = MkClassType("bool");
10291 exp.cond.cond.destType.truth = true;
10292 ProcessExpressionType(exp.cond.cond);
10293 if(!exp.cond.cond.isConstant)
10294 exp.isConstant = false;
10295 for(e = exp.cond.exp->first; e; e = e.next)
10299 FreeType(e.destType);
10300 e.destType = exp.destType;
10301 if(e.destType) e.destType.refCount++;
10303 ProcessExpressionType(e);
10306 exp.expType = e.expType;
10307 if(e.expType) e.expType.refCount++;
10310 exp.isConstant = false;
10313 FreeType(exp.cond.elseExp.destType);
10314 // Added this check if we failed to find an expType
10315 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10318 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10320 if(exp.cond.elseExp.destType)
10321 exp.cond.elseExp.destType.refCount++;
10322 ProcessExpressionType(exp.cond.elseExp);
10324 // FIXED THIS: Was done before calling process on elseExp
10325 if(!exp.cond.elseExp.isConstant)
10326 exp.isConstant = false;
10329 case extensionCompoundExp:
10331 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10333 Statement last = exp.compound.compound.statements->last;
10334 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10336 ((Expression)last.expressions->last).destType = exp.destType;
10338 exp.destType.refCount++;
10340 ProcessStatement(exp.compound);
10341 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10343 exp.expType.refCount++;
10349 Specifier spec = exp._classExp.specifiers->first;
10350 if(spec && spec.type == nameSpecifier)
10352 exp.expType = MkClassType(spec.name);
10353 exp.expType.kind = subClassType;
10354 exp.byReference = true;
10358 exp.expType = MkClassType("ecere::com::Class");
10359 exp.byReference = true;
10365 Class _class = thisClass ? thisClass : currentClass;
10368 Identifier id = exp.classData.id;
10369 char structName[1024];
10370 Expression classExp;
10371 strcpy(structName, "__ecereClassData_");
10372 FullClassNameCat(structName, _class.fullName, false);
10373 exp.type = pointerExp;
10374 exp.member.member = id;
10375 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10376 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10378 classExp = MkExpIdentifier(MkIdentifier("class"));
10380 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10381 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10382 MkExpBrackets(MkListOne(MkExpOp(
10383 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10384 MkExpMember(classExp, MkIdentifier("data"))), '+',
10385 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10388 ProcessExpressionType(exp);
10396 char * typeString = null;
10397 char typeStringBuf[1024];
10398 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10399 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10401 Class templateClass = exp.destType._class.registered;
10402 typeString = templateClass.templateArgs[2].dataTypeString;
10406 // Guess type from expressions in the array
10408 for(e = exp.list->first; e; e = e.next)
10410 ProcessExpressionType(e);
10413 if(!type) { type = e.expType; type.refCount++; }
10416 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10417 if(!MatchTypeExpression(e, type, null, false))
10423 e = exp.list->first;
10424 ProcessExpressionType(e);
10427 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10428 if(!MatchTypeExpression(e, type, null, false))
10430 FreeType(e.expType);
10441 FreeType(e.expType);
10448 typeStringBuf[0] = '\0';
10449 PrintTypeNoConst(type, typeStringBuf, false, true);
10450 typeString = typeStringBuf;
10458 (Container)& (struct BuiltInContainer)
10460 ._vTbl = class(BuiltInContainer)._vTbl,
10461 ._class = class(BuiltInContainer),
10463 .data = (int[]){ 1, 7, 3, 4, 5 },
10465 .type = class(int),
10468 char templateString[1024];
10469 OldList * initializers = MkList();
10470 OldList * structInitializers = MkList();
10471 OldList * specs = MkList();
10473 Declarator decl = SpecDeclFromString(typeString, specs, null);
10474 sprintf(templateString, "Container<%s>", typeString);
10479 type = ProcessTypeString(typeString, false);
10480 while(e = exp.list->first)
10482 exp.list->Remove(e);
10485 ProcessExpressionType(e);
10486 ListAdd(initializers, MkInitializerAssignment(e));
10492 DeclareStruct("ecere::com::BuiltInContainer", false);
10494 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10495 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10496 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10497 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10498 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10499 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10500 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10501 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10502 MkInitializerList(initializers))));
10503 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10504 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10505 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10506 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10507 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10508 exp.expType = ProcessTypeString(templateString, false);
10509 exp.type = bracketsExp;
10510 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10512 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10513 MkInitializerList(structInitializers)))));
10514 ProcessExpressionType(expExt);
10518 exp.expType = ProcessTypeString("Container", false);
10519 Compiler_Error($"Couldn't determine type of array elements\n");
10525 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10527 FreeType(exp.expType);
10528 exp.expType = ReplaceThisClassType(thisClass);
10531 // Resolve structures here
10532 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10534 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10535 // TODO: Fix members reference...
10538 if(exp.expType.kind != enumType)
10541 String enumName = CopyString(exp.expType.enumName);
10543 // Fixed a memory leak on self-referencing C structs typedefs
10544 // by instantiating a new type rather than simply copying members
10545 // into exp.expType
10546 FreeType(exp.expType);
10547 exp.expType = Type { };
10548 exp.expType.kind = symbol.type.kind;
10549 exp.expType.refCount++;
10550 exp.expType.enumName = enumName;
10552 exp.expType.members = symbol.type.members;
10553 for(member = symbol.type.members.first; member; member = member.next)
10559 for(member = symbol.type.members.first; member; member = member.next)
10561 NamedLink value { name = CopyString(member.name) };
10562 exp.expType.members.Add(value);
10569 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10570 else if(exp.destType && !exp.destType.keepCast)
10572 if(!CheckExpressionType(exp, exp.destType, false))
10574 if(!exp.destType.count || unresolved)
10579 if(exp.destType.kind != ellipsisType)
10585 char expString[10240];
10586 expString[0] = '\0';
10588 PrintType(exp.destType, type2, false, true);
10590 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10592 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10593 else if(exp.type != dummyExp)
10594 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10599 char expString[10240] ;
10600 expString[0] = '\0';
10601 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10604 Compiler_Error($"unresolved identifier %s\n", expString);
10605 else if(exp.type != dummyExp)
10606 Compiler_Error($"couldn't determine type of %s\n", expString);
10617 PrintType(exp.expType, type1, false, true);
10618 PrintType(exp.destType, type2, false, true);
10621 //CheckExpressionType(exp, exp.destType, false);
10623 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10624 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10625 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10628 char expString[10240];
10629 expString[0] = '\0';
10630 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10633 CheckExpressionType(exp, exp.destType, false);
10635 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10636 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10637 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10639 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10640 FreeType(exp.expType);
10641 exp.destType.refCount++;
10642 exp.expType = exp.destType;
10647 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10649 Expression newExp { };
10650 char typeString[1024];
10651 OldList * specs = MkList();
10654 typeString[0] = '\0';
10658 if(exp.expType) exp.expType.refCount++;
10659 if(exp.expType) exp.expType.refCount++;
10660 exp.type = castExp;
10661 newExp.destType = exp.expType;
10663 PrintType(exp.expType, typeString, false, false);
10664 decl = SpecDeclFromString(typeString, specs, null);
10666 exp.cast.typeName = MkTypeName(specs, decl);
10667 exp.cast.exp = newExp;
10670 else if(unresolved)
10672 if(exp.identifier._class && exp.identifier._class.name)
10673 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10674 else if(exp.identifier.string && exp.identifier.string[0])
10675 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10677 else if(!exp.expType && exp.type != dummyExp)
10679 char expString[10240];
10680 expString[0] = '\0';
10681 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10682 Compiler_Error($"couldn't determine type of %s\n", expString);
10685 // Let's try to support any_object & typed_object here:
10687 ApplyAnyObjectLogic(exp);
10689 // Mark nohead classes as by reference, unless we're casting them to an integral type
10690 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10691 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
10692 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
10693 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
10695 exp.byReference = true;
10697 yylloc = oldyylloc;
10700 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10702 // THIS CODE WILL FIND NEXT MEMBER...
10705 *curMember = (*curMember).next;
10707 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10709 *curMember = subMemberStack[--(*subMemberStackPos)];
10710 *curMember = (*curMember).next;
10713 // SKIP ALL PROPERTIES HERE...
10714 while((*curMember) && (*curMember).isProperty)
10715 *curMember = (*curMember).next;
10717 if(subMemberStackPos)
10719 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10721 subMemberStack[(*subMemberStackPos)++] = *curMember;
10723 *curMember = (*curMember).members.first;
10724 while(*curMember && (*curMember).isProperty)
10725 *curMember = (*curMember).next;
10733 if(subMemberStackPos && *subMemberStackPos)
10735 *curMember = subMemberStack[--(*subMemberStackPos)];
10736 *curMember = (*curMember).next;
10740 Class lastCurClass = *curClass;
10742 if(*curClass == _class) break; // REACHED THE END
10744 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10745 *curMember = (*curClass).membersAndProperties.first;
10748 while((*curMember) && (*curMember).isProperty)
10749 *curMember = (*curMember).next;
10750 if(subMemberStackPos)
10752 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10754 subMemberStack[(*subMemberStackPos)++] = *curMember;
10756 *curMember = (*curMember).members.first;
10757 while(*curMember && (*curMember).isProperty)
10758 *curMember = (*curMember).next;
10766 static void ProcessInitializer(Initializer init, Type type)
10770 case expInitializer:
10771 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10773 // TESTING THIS FOR SHUTTING = 0 WARNING
10774 if(init.exp && !init.exp.destType)
10776 FreeType(init.exp.destType);
10777 init.exp.destType = type;
10778 if(type) type.refCount++;
10782 ProcessExpressionType(init.exp);
10783 init.isConstant = init.exp.isConstant;
10789 Expression exp = init.exp;
10790 Instantiation inst = exp.instance;
10791 MembersInit members;
10793 init.type = listInitializer;
10794 init.list = MkList();
10798 for(members = inst.members->first; members; members = members.next)
10800 if(members.type == dataMembersInit)
10803 for(member = members.dataMembers->first; member; member = member.next)
10805 ListAdd(init.list, member.initializer);
10806 member.initializer = null;
10809 // Discard all MembersInitMethod
10812 FreeExpression(exp);
10814 case listInitializer:
10817 Type initializerType = null;
10818 Class curClass = null;
10819 DataMember curMember = null;
10820 DataMember subMemberStack[256];
10821 int subMemberStackPos = 0;
10823 if(type && type.kind == arrayType)
10824 initializerType = Dereference(type);
10825 else if(type && (type.kind == structType || type.kind == unionType))
10826 initializerType = type.members.first;
10828 for(i = init.list->first; i; i = i.next)
10830 if(type && type.kind == classType && type._class && type._class.registered)
10832 // 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)
10833 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10834 // TODO: Generate error on initializing a private data member this way from another module...
10837 if(!curMember.dataType)
10838 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10839 initializerType = curMember.dataType;
10842 ProcessInitializer(i, initializerType);
10843 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10844 initializerType = initializerType.next;
10846 init.isConstant = false;
10849 if(type && type.kind == arrayType)
10850 FreeType(initializerType);
10852 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10854 Compiler_Error($"Assigning list initializer to non list\n");
10861 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10865 case baseSpecifier:
10867 if(spec.specifier == THISCLASS)
10871 spec.type = nameSpecifier;
10872 spec.name = ReplaceThisClass(thisClass);
10873 spec.symbol = FindClass(spec.name);
10874 ProcessSpecifier(spec, declareStruct);
10879 case nameSpecifier:
10881 Symbol symbol = FindType(curContext, spec.name);
10883 DeclareType(symbol.type, true, true);
10884 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10885 DeclareStruct(spec.name, false);
10888 case enumSpecifier:
10893 for(e = spec.list->first; e; e = e.next)
10896 ProcessExpressionType(e.exp);
10901 case structSpecifier:
10902 case unionSpecifier:
10904 if(spec.definitions)
10907 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10909 ProcessClass(spec.definitions, symbol);
10912 for(def = spec.definitions->first; def; def = def.next)
10914 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10915 ProcessDeclaration(def.decl);
10922 case classSpecifier:
10924 Symbol classSym = FindClass(spec.name);
10925 if(classSym && classSym.registered && classSym.registered.type == structClass)
10926 DeclareStruct(spec.name, false);
10934 static void ProcessDeclarator(Declarator decl)
10938 case identifierDeclarator:
10939 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10941 FreeSpecifier(decl.identifier._class);
10942 decl.identifier._class = null;
10945 case arrayDeclarator:
10947 ProcessExpressionType(decl.array.exp);
10948 case structDeclarator:
10949 case bracketsDeclarator:
10950 case functionDeclarator:
10951 case pointerDeclarator:
10952 case extendedDeclarator:
10953 case extendedDeclaratorEnd:
10954 if(decl.declarator)
10955 ProcessDeclarator(decl.declarator);
10956 if(decl.type == functionDeclarator)
10958 Identifier id = GetDeclId(decl);
10959 if(id && id._class)
10963 qualifiers = MkListOne(id._class);
10966 if(!decl.function.parameters)
10967 decl.function.parameters = MkList();
10968 decl.function.parameters->Insert(null, param);
10971 if(decl.function.parameters)
10975 for(param = decl.function.parameters->first; param; param = param.next)
10977 if(param.qualifiers && param.qualifiers->first)
10979 Specifier spec = param.qualifiers->first;
10980 if(spec && spec.specifier == TYPED_OBJECT)
10982 Declarator d = param.declarator;
10985 qualifiers = MkListOne(MkSpecifier(VOID));
10986 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10989 FreeList(param.qualifiers, FreeSpecifier);
10991 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10992 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10994 decl.function.parameters->Insert(param, newParam);
10997 else if(spec && spec.specifier == ANY_OBJECT)
10999 Declarator d = param.declarator;
11001 FreeList(param.qualifiers, FreeSpecifier);
11003 param.qualifiers = MkListOne(MkSpecifier(VOID));
11004 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11006 else if(spec.specifier == THISCLASS)
11010 spec.type = nameSpecifier;
11011 spec.name = ReplaceThisClass(thisClass);
11012 spec.symbol = FindClass(spec.name);
11013 ProcessSpecifier(spec, false);
11018 if(param.declarator)
11019 ProcessDeclarator(param.declarator);
11027 static void ProcessDeclaration(Declaration decl)
11032 case initDeclaration:
11034 bool declareStruct = false;
11036 lineNum = decl.pos.line;
11037 column = decl.pos.col;
11040 if(decl.declarators)
11044 for(d = decl.declarators->first; d; d = d.next)
11046 Type type, subType;
11047 ProcessDeclarator(d.declarator);
11049 type = ProcessType(decl.specifiers, d.declarator);
11053 ProcessInitializer(d.initializer, type);
11055 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11057 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11058 d.initializer.exp.type == instanceExp)
11060 if(type.kind == classType && type._class ==
11061 d.initializer.exp.expType._class)
11063 Instantiation inst = d.initializer.exp.instance;
11064 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11066 d.initializer.exp.instance = null;
11067 if(decl.specifiers)
11068 FreeList(decl.specifiers, FreeSpecifier);
11069 FreeList(decl.declarators, FreeInitDeclarator);
11073 decl.type = instDeclaration;
11078 for(subType = type; subType;)
11080 if(subType.kind == classType)
11082 declareStruct = true;
11085 else if(subType.kind == pointerType)
11087 else if(subType.kind == arrayType)
11088 subType = subType.arrayType;
11098 if(decl.specifiers)
11101 for(s = decl.specifiers->first; s; s = s.next)
11103 ProcessSpecifier(s, declareStruct);
11108 case instDeclaration:
11110 ProcessInstantiationType(decl.inst);
11113 case structDeclaration:
11117 bool declareStruct = false;
11119 if(decl.declarators)
11121 for(d = decl.declarators->first; d; d = d.next)
11123 Type type = ProcessType(decl.specifiers, d.declarator);
11125 ProcessDeclarator(d);
11126 for(subType = type; subType;)
11128 if(subType.kind == classType)
11130 declareStruct = true;
11133 else if(subType.kind == pointerType)
11135 else if(subType.kind == arrayType)
11136 subType = subType.arrayType;
11143 if(decl.specifiers)
11145 for(spec = decl.specifiers->first; spec; spec = spec.next)
11146 ProcessSpecifier(spec, declareStruct);
11153 static FunctionDefinition curFunction;
11155 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11157 char propName[1024], propNameM[1024];
11158 char getName[1024], setName[1024];
11161 DeclareProperty(prop, setName, getName);
11163 // eInstance_FireWatchers(object, prop);
11164 strcpy(propName, "__ecereProp_");
11165 FullClassNameCat(propName, prop._class.fullName, false);
11166 strcat(propName, "_");
11167 // strcat(propName, prop.name);
11168 FullClassNameCat(propName, prop.name, true);
11169 MangleClassName(propName);
11171 strcpy(propNameM, "__ecerePropM_");
11172 FullClassNameCat(propNameM, prop._class.fullName, false);
11173 strcat(propNameM, "_");
11174 // strcat(propNameM, prop.name);
11175 FullClassNameCat(propNameM, prop.name, true);
11176 MangleClassName(propNameM);
11178 if(prop.isWatchable)
11181 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11182 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11183 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11186 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11187 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11188 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11194 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11195 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11196 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11199 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11200 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11201 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11204 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11205 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11206 curFunction.propSet.fireWatchersDone = true;
11209 static void ProcessStatement(Statement stmt)
11213 lineNum = stmt.pos.line;
11214 column = stmt.pos.col;
11219 ProcessStatement(stmt.labeled.stmt);
11222 // This expression should be constant...
11223 if(stmt.caseStmt.exp)
11225 FreeType(stmt.caseStmt.exp.destType);
11226 stmt.caseStmt.exp.destType = curSwitchType;
11227 if(curSwitchType) curSwitchType.refCount++;
11228 ProcessExpressionType(stmt.caseStmt.exp);
11229 ComputeExpression(stmt.caseStmt.exp);
11231 if(stmt.caseStmt.stmt)
11232 ProcessStatement(stmt.caseStmt.stmt);
11236 if(stmt.compound.context)
11241 Statement prevCompound = curCompound;
11242 Context prevContext = curContext;
11244 if(!stmt.compound.isSwitch)
11245 curCompound = stmt;
11246 curContext = stmt.compound.context;
11248 if(stmt.compound.declarations)
11250 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11251 ProcessDeclaration(decl);
11253 if(stmt.compound.statements)
11255 for(s = stmt.compound.statements->first; s; s = s.next)
11256 ProcessStatement(s);
11259 curContext = prevContext;
11260 curCompound = prevCompound;
11264 case expressionStmt:
11267 if(stmt.expressions)
11269 for(exp = stmt.expressions->first; exp; exp = exp.next)
11270 ProcessExpressionType(exp);
11278 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11279 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11280 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11281 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11283 ProcessExpressionType(exp);
11285 if(stmt.ifStmt.stmt)
11286 ProcessStatement(stmt.ifStmt.stmt);
11287 if(stmt.ifStmt.elseStmt)
11288 ProcessStatement(stmt.ifStmt.elseStmt);
11293 Type oldSwitchType = curSwitchType;
11294 if(stmt.switchStmt.exp)
11297 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11307 e.exp.destType = destType;
11310 ProcessExpressionType(exp);
11313 curSwitchType = exp.expType;
11316 ProcessStatement(stmt.switchStmt.stmt);
11317 curSwitchType = oldSwitchType;
11322 if(stmt.whileStmt.exp)
11326 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11327 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11328 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11329 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11331 ProcessExpressionType(exp);
11334 if(stmt.whileStmt.stmt)
11335 ProcessStatement(stmt.whileStmt.stmt);
11340 if(stmt.doWhile.exp)
11344 if(stmt.doWhile.exp->last)
11346 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11347 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11348 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11350 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11352 ProcessExpressionType(exp);
11355 if(stmt.doWhile.stmt)
11356 ProcessStatement(stmt.doWhile.stmt);
11362 if(stmt.forStmt.init)
11363 ProcessStatement(stmt.forStmt.init);
11365 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11367 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11368 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11369 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11372 if(stmt.forStmt.check)
11373 ProcessStatement(stmt.forStmt.check);
11374 if(stmt.forStmt.increment)
11376 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11377 ProcessExpressionType(exp);
11380 if(stmt.forStmt.stmt)
11381 ProcessStatement(stmt.forStmt.stmt);
11386 Identifier id = stmt.forEachStmt.id;
11387 OldList * exp = stmt.forEachStmt.exp;
11388 OldList * filter = stmt.forEachStmt.filter;
11389 Statement block = stmt.forEachStmt.stmt;
11390 char iteratorType[1024];
11393 bool isBuiltin = exp && exp->last &&
11394 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11395 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11396 Expression arrayExp;
11397 char * typeString = null;
11398 int builtinCount = 0;
11400 for(e = exp ? exp->first : null; e; e = e.next)
11404 FreeType(e.destType);
11405 e.destType = ProcessTypeString("Container", false);
11407 if(!isBuiltin || e.next)
11408 ProcessExpressionType(e);
11411 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11412 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11413 eClass_IsDerived(source._class.registered, containerClass)))
11415 Class _class = source ? source._class.registered : null;
11417 Expression expIt = null;
11418 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
11419 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11420 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11421 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11422 stmt.type = compoundStmt;
11424 stmt.compound.context = Context { };
11425 stmt.compound.context.parent = curContext;
11426 curContext = stmt.compound.context;
11428 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11430 Class mapClass = eSystem_FindClass(privateModule, "Map");
11431 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11432 isCustomAVLTree = true;
11433 if(eClass_IsDerived(source._class.registered, avlTreeClass))
11435 else if(eClass_IsDerived(source._class.registered, mapClass))
11438 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11439 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11441 Class listClass = eSystem_FindClass(privateModule, "List");
11443 isList = eClass_IsDerived(source._class.registered, listClass);
11449 OldList * specs = MkList();
11450 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11451 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11452 stmt.compound.declarations = MkListOne(
11453 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11454 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11455 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11456 MkInitializerAssignment(MkExpBrackets(exp))))));
11461 char typeStringBuf[1024];
11463 // TODO: Merge this code?
11464 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11465 if(((Expression)exp->last).type == castExp)
11467 TypeName typeName = ((Expression)exp->last).cast.typeName;
11469 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11472 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11473 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11474 arrayExp.destType._class.registered.templateArgs)
11476 Class templateClass = arrayExp.destType._class.registered;
11477 typeString = templateClass.templateArgs[2].dataTypeString;
11479 else if(arrayExp.list)
11481 // Guess type from expressions in the array
11483 for(e = arrayExp.list->first; e; e = e.next)
11485 ProcessExpressionType(e);
11488 if(!type) { type = e.expType; type.refCount++; }
11491 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11492 if(!MatchTypeExpression(e, type, null, false))
11498 e = arrayExp.list->first;
11499 ProcessExpressionType(e);
11502 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11503 if(!MatchTypeExpression(e, type, null, false))
11505 FreeType(e.expType);
11516 FreeType(e.expType);
11523 typeStringBuf[0] = '\0';
11524 PrintType(type, typeStringBuf, false, true);
11525 typeString = typeStringBuf;
11531 OldList * initializers = MkList();
11533 OldList * specs = MkList();
11538 builtinCount = arrayExp.list->count;
11539 type = ProcessTypeString(typeString, false);
11540 while(e = arrayExp.list->first)
11542 arrayExp.list->Remove(e);
11545 ProcessExpressionType(e);
11546 ListAdd(initializers, MkInitializerAssignment(e));
11549 delete arrayExp.list;
11551 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11552 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11553 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11555 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
11557 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
11558 ), MkInitializerList(initializers)))));
11559 FreeList(exp, FreeExpression);
11563 arrayExp.expType = ProcessTypeString("Container", false);
11564 Compiler_Error($"Couldn't determine type of array elements\n");
11569 OldList * specs = MkList();
11571 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11572 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11573 stmt.compound.declarations = MkListOne(
11574 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11575 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11576 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11577 MkInitializerAssignment(MkExpBrackets(exp))))));
11580 else if(isLinkList && !isList)
11583 OldList * specs = MkList();
11584 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11585 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11586 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11587 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11588 MkInitializerAssignment(MkExpBrackets(exp))))));
11590 /*else if(isCustomAVLTree)
11593 OldList * specs = MkList();
11594 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11595 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11596 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11597 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11598 MkInitializerAssignment(MkExpBrackets(exp))))));
11600 else if(_class.templateArgs)
11603 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11605 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11607 stmt.compound.declarations = MkListOne(
11608 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11609 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11610 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11612 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11616 // Reparent sub-contexts in this statement
11620 if(block.compound.context)
11621 block.compound.context.parent = stmt.compound.context;
11624 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
11625 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
11626 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
11627 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
11630 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
11631 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
11634 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
11635 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
11638 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
11639 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
11642 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
11643 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
11646 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
11647 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
11649 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
11652 case expressionStmt:
11658 case badDeclarationStmt:
11659 case fireWatchersStmt:
11660 case stopWatchingStmt:
11667 block = MkIfStmt(filter, block, null);
11671 stmt.compound.statements = MkListOne(MkForStmt(
11672 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11673 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11674 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11675 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11677 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11678 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11679 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11684 //OldList * specs = MkList();
11685 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11687 sprintf(count, "%d", builtinCount);
11689 stmt.compound.statements = MkListOne(MkForStmt(
11690 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11691 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11692 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11693 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11697 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11698 stmt.compound.statements = MkListOne(MkForStmt(
11699 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11700 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11701 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11702 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11705 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11706 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11707 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11709 else if(isLinkList && !isList)
11711 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11712 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11713 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11714 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11716 stmt.compound.statements = MkListOne(MkForStmt(
11717 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11718 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11719 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11724 OldList * specs = MkList();
11725 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11726 stmt.compound.statements = MkListOne(MkForStmt(
11727 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11728 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11729 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11730 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11731 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11734 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11735 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11736 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11738 /*else if(isCustomAVLTree)
11740 stmt.compound.statements = MkListOne(MkForStmt(
11741 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11742 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11743 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11744 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11747 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11748 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11749 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11753 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11754 MkIdentifier("Next")), null)), block));
11756 ProcessExpressionType(expIt);
11757 if(stmt.compound.declarations->first)
11758 ProcessDeclaration(stmt.compound.declarations->first);
11761 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11763 ProcessStatement(stmt);
11764 curContext = stmt.compound.context.parent;
11769 Compiler_Error($"Expression is not a container\n");
11782 if(stmt.expressions)
11784 for(exp = stmt.expressions->first; exp; exp = exp.next)
11788 if(curFunction && !curFunction.type)
11789 curFunction.type = ProcessType(
11790 curFunction.specifiers, curFunction.declarator);
11791 FreeType(exp.destType);
11792 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11793 if(exp.destType) exp.destType.refCount++;
11795 ProcessExpressionType(exp);
11800 case badDeclarationStmt:
11802 ProcessDeclaration(stmt.decl);
11808 if(stmt.asmStmt.inputFields)
11810 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11811 if(field.expression)
11812 ProcessExpressionType(field.expression);
11814 if(stmt.asmStmt.outputFields)
11816 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11817 if(field.expression)
11818 ProcessExpressionType(field.expression);
11820 if(stmt.asmStmt.clobberedFields)
11822 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11824 if(field.expression)
11825 ProcessExpressionType(field.expression);
11832 PropertyWatch propWatch;
11833 OldList * watches = stmt._watch.watches;
11834 Expression object = stmt._watch.object;
11835 Expression watcher = stmt._watch.watcher;
11837 ProcessExpressionType(watcher);
11839 ProcessExpressionType(object);
11843 if(watcher || thisClass)
11845 External external = curExternal;
11846 Context context = curContext;
11848 stmt.type = expressionStmt;
11849 stmt.expressions = MkList();
11851 curExternal = external.prev;
11853 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11855 ClassFunction func;
11856 char watcherName[1024];
11857 Class watcherClass = watcher ?
11858 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11859 External createdExternal;
11861 // Create a declaration above
11862 External externalDecl = MkExternalDeclaration(null);
11863 ast->Insert(curExternal.prev, externalDecl);
11865 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11866 if(propWatch.deleteWatch)
11867 strcat(watcherName, "_delete");
11871 for(propID = propWatch.properties->first; propID; propID = propID.next)
11873 strcat(watcherName, "_");
11874 strcat(watcherName, propID.string);
11878 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11880 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11881 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11882 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11883 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11884 ProcessClassFunctionBody(func, propWatch.compound);
11885 propWatch.compound = null;
11887 //afterExternal = afterExternal ? afterExternal : curExternal;
11889 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11890 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11892 createdExternal.symbol.idCode = external.symbol.idCode;
11894 curExternal = createdExternal;
11895 ProcessFunction(createdExternal.function);
11898 // Create a declaration above
11900 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11901 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11902 externalDecl.declaration = decl;
11903 if(decl.symbol && !decl.symbol.pointerExternal)
11904 decl.symbol.pointerExternal = externalDecl;
11907 if(propWatch.deleteWatch)
11909 OldList * args = MkList();
11910 ListAdd(args, CopyExpression(object));
11911 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11912 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11913 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11917 Class _class = object.expType._class.registered;
11920 for(propID = propWatch.properties->first; propID; propID = propID.next)
11922 char propName[1024];
11923 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11926 char getName[1024], setName[1024];
11927 OldList * args = MkList();
11929 DeclareProperty(prop, setName, getName);
11931 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11932 strcpy(propName, "__ecereProp_");
11933 FullClassNameCat(propName, prop._class.fullName, false);
11934 strcat(propName, "_");
11935 // strcat(propName, prop.name);
11936 FullClassNameCat(propName, prop.name, true);
11938 ListAdd(args, CopyExpression(object));
11939 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11940 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11941 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11943 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11946 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11951 Compiler_Error($"Invalid watched object\n");
11954 curExternal = external;
11955 curContext = context;
11958 FreeExpression(watcher);
11960 FreeExpression(object);
11961 FreeList(watches, FreePropertyWatch);
11964 Compiler_Error($"No observer specified and not inside a _class\n");
11968 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11970 ProcessStatement(propWatch.compound);
11976 case fireWatchersStmt:
11978 OldList * watches = stmt._watch.watches;
11979 Expression object = stmt._watch.object;
11981 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11982 // printf("%X\n", watches);
11983 // printf("%X\n", stmt._watch.watches);
11985 ProcessExpressionType(object);
11990 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11996 stmt.type = expressionStmt;
11997 stmt.expressions = MkList();
11999 // Check if we're inside a property set
12000 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12002 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12006 //Compiler_Error($"No property specified and not inside a property set\n");
12010 for(propID = watches->first; propID; propID = propID.next)
12012 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12015 CreateFireWatcher(prop, object, stmt);
12018 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12023 // Fire all properties!
12026 for(base = _class; base; base = base.base)
12028 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12030 if(prop.isProperty && prop.isWatchable)
12032 CreateFireWatcher(prop, object, stmt);
12039 FreeExpression(object);
12040 FreeList(watches, FreeIdentifier);
12043 Compiler_Error($"Invalid object specified and not inside a class\n");
12047 case stopWatchingStmt:
12049 OldList * watches = stmt._watch.watches;
12050 Expression object = stmt._watch.object;
12051 Expression watcher = stmt._watch.watcher;
12054 ProcessExpressionType(object);
12056 ProcessExpressionType(watcher);
12059 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12061 if(watcher || thisClass)
12067 stmt.type = expressionStmt;
12068 stmt.expressions = MkList();
12073 // eInstance_StopWatching(object, null, watcher);
12075 ListAdd(args, CopyExpression(object));
12076 ListAdd(args, MkExpConstant("0"));
12077 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12078 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12082 for(propID = watches->first; propID; propID = propID.next)
12084 char propName[1024];
12085 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12088 char getName[1024], setName[1024];
12089 OldList * args = MkList();
12091 DeclareProperty(prop, setName, getName);
12093 // eInstance_StopWatching(object, prop, watcher);
12094 strcpy(propName, "__ecereProp_");
12095 FullClassNameCat(propName, prop._class.fullName, false);
12096 strcat(propName, "_");
12097 // strcat(propName, prop.name);
12098 FullClassNameCat(propName, prop.name, true);
12099 MangleClassName(propName);
12101 ListAdd(args, CopyExpression(object));
12102 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12103 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12104 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12107 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
12112 FreeExpression(object);
12114 FreeExpression(watcher);
12115 FreeList(watches, FreeIdentifier);
12118 Compiler_Error($"Invalid object specified and not inside a class\n");
12121 Compiler_Error($"No observer specified and not inside a class\n");
12128 static void ProcessFunction(FunctionDefinition function)
12130 Identifier id = GetDeclId(function.declarator);
12131 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12132 Type type = symbol ? symbol.type : null;
12133 Class oldThisClass = thisClass;
12134 Context oldTopContext = topContext;
12136 yylloc = function.loc;
12137 // Process thisClass
12139 if(type && type.thisClass)
12141 Symbol classSym = type.thisClass;
12142 Class _class = type.thisClass.registered;
12143 char className[1024];
12144 char structName[1024];
12145 Declarator funcDecl;
12148 bool typedObject = false;
12150 if(_class && !_class.base)
12152 _class = currentClass;
12153 if(_class && !_class.symbol)
12154 _class.symbol = FindClass(_class.fullName);
12155 classSym = _class ? _class.symbol : null;
12156 typedObject = true;
12159 thisClass = _class;
12161 if(inCompiler && _class)
12163 if(type.kind == functionType)
12165 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12167 //TypeName param = symbol.type.params.first;
12168 Type param = symbol.type.params.first;
12169 symbol.type.params.Remove(param);
12170 //FreeTypeName(param);
12173 if(type.classObjectType != classPointer)
12175 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12176 symbol.type.staticMethod = true;
12177 symbol.type.thisClass = null;
12179 // HIGH DANGER: VERIFYING THIS...
12180 symbol.type.extraParam = false;
12184 strcpy(className, "__ecereClass_");
12185 FullClassNameCat(className, _class.fullName, true);
12187 MangleClassName(className);
12190 FullClassNameCat(structName, _class.fullName, false);
12195 funcDecl = GetFuncDecl(function.declarator);
12198 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12200 TypeName param = funcDecl.function.parameters->first;
12201 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12203 funcDecl.function.parameters->Remove(param);
12204 FreeTypeName(param);
12208 // DANGER: Watch for this... Check if it's a Conversion?
12209 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12211 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12212 if(!function.propertyNoThis)
12214 TypeName thisParam;
12216 if(type.classObjectType != classPointer)
12218 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12219 if(!funcDecl.function.parameters)
12220 funcDecl.function.parameters = MkList();
12221 funcDecl.function.parameters->Insert(null, thisParam);
12226 if(type.classObjectType != classPointer)
12228 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12229 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12232 thisParam = TypeName
12234 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12235 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12237 funcDecl.function.parameters->Insert(null, thisParam);
12242 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12244 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12245 funcDecl = GetFuncDecl(initDecl.declarator);
12248 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12250 TypeName param = funcDecl.function.parameters->first;
12251 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12253 funcDecl.function.parameters->Remove(param);
12254 FreeTypeName(param);
12258 if(type.classObjectType != classPointer)
12260 // DANGER: Watch for this... Check if it's a Conversion?
12261 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12263 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12265 if(!funcDecl.function.parameters)
12266 funcDecl.function.parameters = MkList();
12267 funcDecl.function.parameters->Insert(null, thisParam);
12274 // Add this to the context
12277 if(type.classObjectType != classPointer)
12279 thisSymbol = Symbol
12281 string = CopyString("this");
12282 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12284 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12286 if(typedObject && thisSymbol.type)
12288 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12289 thisSymbol.type.byReference = type.byReference;
12290 thisSymbol.type.typedByReference = type.byReference;
12292 thisSymbol = Symbol { string = CopyString("class") };
12293 function.body.compound.context.symbols.Add(thisSymbol);
12299 // Pointer to class data
12301 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12303 DataMember member = null;
12306 for(base = _class; base && base.type != systemClass; base = base.next)
12308 for(member = base.membersAndProperties.first; member; member = member.next)
12309 if(!member.isProperty)
12315 for(member = _class.membersAndProperties.first; member; member = member.next)
12316 if(!member.isProperty)
12320 char pointerName[1024];
12323 Initializer initializer;
12324 Expression exp, bytePtr;
12326 strcpy(pointerName, "__ecerePointer_");
12327 FullClassNameCat(pointerName, _class.fullName, false);
12329 char className[1024];
12330 strcpy(className, "__ecereClass_");
12331 FullClassNameCat(className, classSym.string, true);
12332 MangleClassName(className);
12335 DeclareClass(classSym, className);
12339 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12344 sprintf(string, "%d", _class.offset);
12345 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12349 // ([bytePtr] + [className]->offset)
12350 exp = QBrackets(MkExpOp(bytePtr, '+',
12351 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12354 // (this ? [exp] : 0)
12355 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12359 kind = pointerType;
12360 type = Type { refCount = 1, kind = voidType };
12365 yylloc = function.body.loc;
12366 // ([structName] *) [exp]
12367 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12368 initializer = MkInitializerAssignment(
12369 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12371 // [structName] * [pointerName] = [initializer];
12372 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12375 Context prevContext = curContext;
12376 curContext = function.body.compound.context;
12378 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12379 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12381 curContext = prevContext;
12385 decl.symbol = null;
12387 if(!function.body.compound.declarations)
12388 function.body.compound.declarations = MkList();
12389 function.body.compound.declarations->Insert(null, decl);
12395 // Loop through the function and replace undeclared identifiers
12396 // which are a member of the class (methods, properties or data)
12397 // by "this.[member]"
12404 FreeSpecifier(id._class);
12407 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12409 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12410 id = GetDeclId(initDecl.declarator);
12412 FreeSpecifier(id._class);
12417 topContext = function.body.compound.context;
12419 FunctionDefinition oldFunction = curFunction;
12420 curFunction = function;
12422 ProcessStatement(function.body);
12424 // If this is a property set and no firewatchers has been done yet, add one here
12425 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12427 Statement prevCompound = curCompound;
12428 Context prevContext = curContext;
12430 Statement fireWatchers = MkFireWatchersStmt(null, null);
12431 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12432 ListAdd(function.body.compound.statements, fireWatchers);
12434 curCompound = function.body;
12435 curContext = function.body.compound.context;
12437 ProcessStatement(fireWatchers);
12439 curContext = prevContext;
12440 curCompound = prevCompound;
12444 curFunction = oldFunction;
12447 if(function.declarator)
12449 ProcessDeclarator(function.declarator);
12452 topContext = oldTopContext;
12453 thisClass = oldThisClass;
12456 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12457 static void ProcessClass(OldList definitions, Symbol symbol)
12460 External external = curExternal;
12461 Class regClass = symbol ? symbol.registered : null;
12463 // Process all functions
12464 for(def = definitions.first; def; def = def.next)
12466 if(def.type == functionClassDef)
12468 if(def.function.declarator)
12469 curExternal = def.function.declarator.symbol.pointerExternal;
12471 curExternal = external;
12473 ProcessFunction((FunctionDefinition)def.function);
12475 else if(def.type == declarationClassDef)
12477 if(def.decl.type == instDeclaration)
12479 thisClass = regClass;
12480 ProcessInstantiationType(def.decl.inst);
12486 Class backThisClass = thisClass;
12487 if(regClass) thisClass = regClass;
12488 ProcessDeclaration(def.decl);
12489 thisClass = backThisClass;
12492 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12494 MemberInit defProperty;
12496 // Add this to the context
12497 Symbol thisSymbol = Symbol
12499 string = CopyString("this");
12500 type = regClass ? MkClassType(regClass.fullName) : null;
12502 globalContext.symbols.Add((BTNode)thisSymbol);
12504 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12506 thisClass = regClass;
12507 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12511 globalContext.symbols.Remove((BTNode)thisSymbol);
12512 FreeSymbol(thisSymbol);
12514 else if(def.type == propertyClassDef && def.propertyDef)
12516 PropertyDef prop = def.propertyDef;
12518 // Add this to the context
12520 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12521 globalContext.symbols.Add(thisSymbol);
12524 thisClass = regClass;
12531 string = CopyString("this");
12532 type = MkClassType(regClass.fullName);
12534 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12537 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12538 ProcessStatement(prop.setStmt);
12546 string = CopyString("this");
12547 type = MkClassType(regClass.fullName);
12549 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12552 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12553 ProcessStatement(prop.getStmt);
12561 string = CopyString("this");
12562 type = MkClassType(regClass.fullName);
12564 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12567 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12568 ProcessStatement(prop.issetStmt);
12574 globalContext.symbols.Remove(thisSymbol);
12575 FreeSymbol(thisSymbol);
12578 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12580 PropertyWatch propertyWatch = def.propertyWatch;
12582 thisClass = regClass;
12583 if(propertyWatch.compound)
12587 string = CopyString("this");
12588 type = regClass ? MkClassType(regClass.fullName) : null;
12591 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12593 curExternal = null;
12594 ProcessStatement(propertyWatch.compound);
12601 void DeclareFunctionUtil(String s)
12603 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12608 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12609 strcpy(name, "__ecereFunction_");
12610 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12611 DeclareFunction(function, name);
12615 void ComputeDataTypes()
12619 External after = null;
12621 currentClass = null;
12623 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12625 for(external = ast->first; external; external = external.next)
12627 if(external.type == declarationExternal)
12629 Declaration decl = external.declaration;
12632 OldList * decls = decl.declarators;
12635 InitDeclarator initDecl = decls->first;
12638 Declarator declarator = initDecl.declarator;
12639 if(declarator && declarator.type == identifierDeclarator)
12641 Identifier id = declarator.identifier;
12642 if(id && id.string)
12644 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12646 external.symbol.id = -1001, external.symbol.idCode = -1001;
12657 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12658 ast->Insert(after, temp);
12659 curExternal = temp;
12661 DeclareFunctionUtil("eSystem_New");
12662 DeclareFunctionUtil("eSystem_New0");
12663 DeclareFunctionUtil("eSystem_Renew");
12664 DeclareFunctionUtil("eSystem_Renew0");
12665 DeclareFunctionUtil("eSystem_Delete");
12666 DeclareFunctionUtil("eClass_GetProperty");
12667 DeclareFunctionUtil("eInstance_FireSelfWatchers");
12669 DeclareStruct("ecere::com::Class", false);
12670 DeclareStruct("ecere::com::Instance", false);
12671 DeclareStruct("ecere::com::Property", false);
12672 DeclareStruct("ecere::com::DataMember", false);
12673 DeclareStruct("ecere::com::Method", false);
12674 DeclareStruct("ecere::com::SerialBuffer", false);
12675 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12679 for(external = ast->first; external; external = external.next)
12681 afterExternal = curExternal = external;
12682 if(external.type == functionExternal)
12684 currentClass = external.function._class;
12685 ProcessFunction(external.function);
12687 // There shouldn't be any _class member access here anyways...
12688 else if(external.type == declarationExternal)
12690 currentClass = null;
12691 ProcessDeclaration(external.declaration);
12693 else if(external.type == classExternal)
12695 ClassDefinition _class = external._class;
12696 currentClass = external.symbol.registered;
12697 if(_class.definitions)
12699 ProcessClass(_class.definitions, _class.symbol);
12703 // Free class data...
12704 ast->Remove(external);
12708 else if(external.type == nameSpaceExternal)
12710 thisNameSpace = external.id.string;
12713 currentClass = null;
12714 thisNameSpace = null;
12716 delete temp.symbol;