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)
97 if(type1.passAsTemplate && !type2.passAsTemplate)
99 return type1.isSigned != type2.isSigned;
101 return type1._class != type2._class;
103 return NeedCast(type1.type, type2.type);
105 return true; //false; ????
111 static void ReplaceClassMembers(Expression exp, Class _class)
113 if(exp.type == identifierExp && exp.identifier)
115 Identifier id = exp.identifier;
117 Symbol symbol = null;
118 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
120 // First, check if the identifier is declared inside the function
121 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
123 symbol = (Symbol)ctx.symbols.FindString(id.string);
128 // If it is not, check if it is a member of the _class
129 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
131 Property prop = eClass_FindProperty(_class, id.string, privateModule);
132 Method method = null;
133 DataMember member = null;
134 ClassProperty classProp = null;
137 method = eClass_FindMethod(_class, id.string, privateModule);
140 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
141 if(!prop && !method && !member)
143 classProp = eClass_FindClassProperty(_class, id.string);
145 if(prop || method || member || classProp)
147 // Replace by this.[member]
148 exp.type = memberExp;
149 exp.member.member = id;
150 exp.member.memberType = unresolvedMember;
151 exp.member.exp = QMkExpId("this");
152 //exp.member.exp.loc = exp.loc;
153 exp.addedThis = true;
155 else if(_class && _class.templateParams.first)
158 for(sClass = _class; sClass; sClass = sClass.base)
160 if(sClass.templateParams.first)
162 ClassTemplateParameter param;
163 for(param = sClass.templateParams.first; param; param = param.next)
165 if(param.type == expression && !strcmp(param.name, id.string))
167 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
172 OldList * specs = MkList();
174 FreeIdentifier(exp.member.member);
176 ProcessExpressionType(argExp);
178 decl = SpecDeclFromString(param.dataTypeString, specs, null);
180 exp.expType = ProcessType(specs, decl);
182 // *[expType] *[argExp]
183 exp.type = bracketsExp;
184 exp.list = MkListOne(MkExpOp(null, '*',
185 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
196 ////////////////////////////////////////////////////////////////////////
197 // PRINTING ////////////////////////////////////////////////////////////
198 ////////////////////////////////////////////////////////////////////////
200 public char * PrintInt(int64 result)
203 if(result > MAXINT64)
204 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
206 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
207 return CopyString(temp);
210 public char * PrintUInt(uint64 result)
213 if(result > MAXDWORD)
214 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
215 else if(result > MAXINT)
216 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
218 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
219 return CopyString(temp);
222 public char * PrintInt64(int64 result)
225 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
226 return CopyString(temp);
229 public char * PrintUInt64(uint64 result)
232 if(result > MAXINT64)
233 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
235 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
236 return CopyString(temp);
239 public char * PrintHexUInt(uint64 result)
242 if(result > MAXDWORD)
243 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
245 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
246 return CopyString(temp);
249 public char * PrintHexUInt64(uint64 result)
252 if(result > MAXDWORD)
253 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
255 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
256 return CopyString(temp);
259 public char * PrintShort(short result)
262 sprintf(temp, "%d", (unsigned short)result);
263 return CopyString(temp);
266 public char * PrintUShort(unsigned short result)
270 sprintf(temp, "0x%X", (int)result);
272 sprintf(temp, "%d", result);
273 return CopyString(temp);
276 public char * PrintChar(char result)
279 if(result > 0 && isprint(result))
280 sprintf(temp, "'%c'", result);
282 sprintf(temp, "%d", result);
284 //sprintf(temp, "%#X", result);
285 sprintf(temp, "0x%X", (unsigned char)result);
286 return CopyString(temp);
289 public char * PrintUChar(unsigned char result)
292 sprintf(temp, "0x%X", result);
293 return CopyString(temp);
296 public char * PrintFloat(float result)
299 sprintf(temp, "%.16ff", result);
300 return CopyString(temp);
303 public char * PrintDouble(double result)
306 sprintf(temp, "%.16f", result);
307 return CopyString(temp);
310 ////////////////////////////////////////////////////////////////////////
311 ////////////////////////////////////////////////////////////////////////
313 //public Operand GetOperand(Expression exp);
315 #define GETVALUE(name, t) \
316 public bool Get##name(Expression exp, t * value2) \
318 Operand op2 = GetOperand(exp); \
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 == 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; \
339 // To help the deubugger currently not preprocessing...
342 GETVALUE(Int, HELP(int));
343 GETVALUE(UInt, HELP(unsigned int));
344 GETVALUE(Int64, HELP(int64));
345 GETVALUE(UInt64, HELP(uint64));
346 GETVALUE(IntPtr, HELP(intptr));
347 GETVALUE(UIntPtr, HELP(uintptr));
348 GETVALUE(IntSize, HELP(intsize));
349 GETVALUE(UIntSize, HELP(uintsize));
350 GETVALUE(Short, HELP(short));
351 GETVALUE(UShort, HELP(unsigned short));
352 GETVALUE(Char, HELP(char));
353 GETVALUE(UChar, HELP(unsigned char));
354 GETVALUE(Float, HELP(float));
355 GETVALUE(Double, HELP(double));
357 void ComputeExpression(Expression exp);
359 void ComputeClassMembers(Class _class, bool isMember)
361 DataMember member = isMember ? (DataMember) _class : null;
362 Context context = isMember ? null : SetupTemplatesContext(_class);
363 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
364 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
367 int unionMemberOffset = 0;
371 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
372 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
377 member.memberOffset = 0;
378 if(targetBits < sizeof(void *) * 8)
379 member.structAlignment = 0;
381 else if(targetBits < sizeof(void *) * 8)
382 _class.structAlignment = 0;
384 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
385 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
386 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
388 if(!member && _class.destructionWatchOffset)
389 _class.memberOffset += sizeof(OldList);
391 // To avoid reentrancy...
392 //_class.structSize = -1;
395 DataMember dataMember;
396 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
398 if(!dataMember.isProperty)
400 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
402 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
403 /*if(!dataMember.dataType)
404 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
412 DataMember dataMember;
413 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
415 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
417 if(!isMember && _class.type == bitClass && dataMember.dataType)
419 BitMember bitMember = (BitMember) dataMember;
423 ComputeTypeSize(dataMember.dataType);
425 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
426 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
428 _class.memberOffset = bitMember.pos + bitMember.size;
429 for(d = 0; d<bitMember.size; d++)
435 bitMember.mask = mask << bitMember.pos;
437 else if(dataMember.type == normalMember && dataMember.dataType)
442 // Prevent infinite recursion
443 if(dataMember.dataType.kind != classType ||
444 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
445 _class.type != structClass)))
446 ComputeTypeSize(dataMember.dataType);
448 if(dataMember.dataType.bitFieldCount)
450 bitFields += dataMember.dataType.bitFieldCount;
457 int size = (bitFields + 7) / 8;
461 // TESTING THIS PADDING CODE
464 member.structAlignment = Max(member.structAlignment, alignment);
466 if(member.memberOffset % alignment)
467 member.memberOffset += alignment - (member.memberOffset % alignment);
470 dataMember.offset = member.memberOffset;
471 if(member.type == unionMember)
472 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
475 member.memberOffset += size;
480 // TESTING THIS PADDING CODE
483 _class.structAlignment = Max(_class.structAlignment, alignment);
485 if(_class.memberOffset % alignment)
486 _class.memberOffset += alignment - (_class.memberOffset % alignment);
489 dataMember.offset = _class.memberOffset;
490 _class.memberOffset += size;
494 size = dataMember.dataType.size;
495 alignment = dataMember.dataType.alignment;
500 // TESTING THIS PADDING CODE
503 member.structAlignment = Max(member.structAlignment, alignment);
505 if(member.memberOffset % alignment)
506 member.memberOffset += alignment - (member.memberOffset % alignment);
509 dataMember.offset = member.memberOffset;
510 if(member.type == unionMember)
511 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
514 member.memberOffset += size;
519 // TESTING THIS PADDING CODE
522 _class.structAlignment = Max(_class.structAlignment, alignment);
524 if(_class.memberOffset % alignment)
525 _class.memberOffset += alignment - (_class.memberOffset % alignment);
528 dataMember.offset = _class.memberOffset;
529 _class.memberOffset += size;
536 ComputeClassMembers((Class)dataMember, true);
537 alignment = dataMember.structAlignment;
543 if(member.memberOffset % alignment)
544 member.memberOffset += alignment - (member.memberOffset % alignment);
546 member.structAlignment = Max(member.structAlignment, alignment);
548 dataMember.offset = member.memberOffset;
549 if(member.type == unionMember)
550 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
552 member.memberOffset += dataMember.memberOffset;
558 if(_class.memberOffset % alignment)
559 _class.memberOffset += alignment - (_class.memberOffset % alignment);
560 _class.structAlignment = Max(_class.structAlignment, alignment);
562 dataMember.offset = _class.memberOffset;
563 _class.memberOffset += dataMember.memberOffset;
571 int size = (bitFields + 7) / 8;
575 // TESTING THIS PADDING CODE
578 member.structAlignment = Max(member.structAlignment, alignment);
580 if(member.memberOffset % alignment)
581 member.memberOffset += alignment - (member.memberOffset % alignment);
584 if(member.type == unionMember)
585 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
588 member.memberOffset += size;
593 // TESTING THIS PADDING CODE
596 _class.structAlignment = Max(_class.structAlignment, alignment);
598 if(_class.memberOffset % alignment)
599 _class.memberOffset += alignment - (_class.memberOffset % alignment);
601 _class.memberOffset += size;
606 if(member && member.type == unionMember)
608 member.memberOffset = unionMemberOffset;
613 /*if(_class.type == structClass)
614 _class.size = _class.memberOffset;
618 if(_class.type != bitClass)
621 if(_class.structAlignment)
623 if(_class.memberOffset % _class.structAlignment)
624 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
626 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
630 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
632 if(prop.isProperty && prop.isWatchable)
634 prop.watcherOffset = _class.structSize;
635 _class.structSize += sizeof(OldList);
643 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
645 Class deriv = derivative.data;
647 if(deriv.computeSize)
649 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
650 deriv.offset = /*_class.offset + */_class.structSize;
651 deriv.memberOffset = 0;
652 // ----------------------
654 deriv.structSize = deriv.offset;
656 ComputeClassMembers(deriv, false);
664 FinishTemplatesContext(context);
667 public void ComputeModuleClasses(Module module)
672 for(subModule = module.modules.first; subModule; subModule = subModule.next)
673 ComputeModuleClasses(subModule.data);
674 for(_class = module.classes.first; _class; _class = _class.next)
675 ComputeClassMembers(_class, false);
679 public int ComputeTypeSize(Type type)
681 uint size = type ? type.size : 0;
682 if(!size && type && !type.computing)
684 type.computing = true;
687 case charType: type.alignment = size = sizeof(char); break;
688 case intType: type.alignment = size = sizeof(int); break;
689 case int64Type: type.alignment = size = sizeof(int64); break;
690 case intPtrType: type.alignment = size = targetBits / 8; break;
691 case intSizeType: type.alignment = size = targetBits / 8; break;
692 case longType: type.alignment = size = sizeof(long); break;
693 case shortType: type.alignment = size = sizeof(short); break;
694 case floatType: type.alignment = size = sizeof(float); break;
695 case doubleType: type.alignment = size = sizeof(double); break;
698 Class _class = type._class ? type._class.registered : null;
700 if(_class && _class.type == structClass)
702 // Ensure all members are properly registered
703 ComputeClassMembers(_class, false);
704 type.alignment = _class.structAlignment;
705 size = _class.structSize;
706 if(type.alignment && size % type.alignment)
707 size += type.alignment - (size % type.alignment);
710 else if(_class && (_class.type == unitClass ||
711 _class.type == enumClass ||
712 _class.type == bitClass))
715 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
716 size = type.alignment = ComputeTypeSize(_class.dataType);
719 size = type.alignment = targetBits / 8; // sizeof(Instance *);
722 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
724 if(type.arraySizeExp)
726 ProcessExpressionType(type.arraySizeExp);
727 ComputeExpression(type.arraySizeExp);
728 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType && type.arraySizeExp.expType.kind != enumType &&
729 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
731 Location oldLoc = yylloc;
732 // bool isConstant = type.arraySizeExp.isConstant;
733 char expression[10240];
734 expression[0] = '\0';
735 type.arraySizeExp.expType = null;
736 yylloc = type.arraySizeExp.loc;
738 PrintExpression(type.arraySizeExp, expression);
739 Compiler_Error($"Array size not constant int (%s)\n", expression);
742 GetInt(type.arraySizeExp, &type.arraySize);
744 else if(type.enumClass)
746 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
748 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
755 // Unimplemented auto size
759 size = ComputeTypeSize(type.type) * type.arraySize;
760 type.alignment = type.type.alignment;
766 for(member = type.members.first; member; member = member.next)
768 uint addSize = ComputeTypeSize(member);
770 member.offset = size;
771 if(member.alignment && size % member.alignment)
772 member.offset += member.alignment - (size % member.alignment);
773 size = member.offset;
775 type.alignment = Max(type.alignment, member.alignment);
778 if(type.alignment && size % type.alignment)
779 size += type.alignment - (size % type.alignment);
785 for(member = type.members.first; member; member = member.next)
787 uint addSize = ComputeTypeSize(member);
789 member.offset = size;
790 if(member.alignment && size % member.alignment)
791 member.offset += member.alignment - (size % member.alignment);
792 size = member.offset;
794 type.alignment = Max(type.alignment, member.alignment);
795 size = Max(size, addSize);
797 if(type.alignment && size % type.alignment)
798 size += type.alignment - (size % type.alignment);
803 TemplateParameter param = type.templateParameter;
804 Type baseType = ProcessTemplateParameterType(param);
807 size = ComputeTypeSize(baseType);
808 type.alignment = baseType.alignment;
811 type.alignment = size = sizeof(uint64);
816 type.alignment = size = sizeof(enum { test });
821 type.alignment = size = targetBits / 8; //sizeof(void *);
826 type.computing = false;
832 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
834 // This function is in need of a major review when implementing private members etc.
835 DataMember topMember = isMember ? (DataMember) _class : null;
840 Context context = isMember ? null : SetupTemplatesContext(_class);
842 *addedPadding = false;
844 if(!isMember && _class.base)
846 maxSize = _class.structSize;
847 //if(_class.base.type != systemClass) // Commented out with new Instance _class
849 // DANGER: Testing this noHeadClass here...
850 if(_class.type == structClass || _class.type == noHeadClass)
851 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
853 maxSize -= _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
857 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
859 if(!member.isProperty)
865 if(member.dataTypeString)
867 OldList * specs = MkList(), * decls = MkList();
870 decl = SpecDeclFromString(member.dataTypeString, specs,
871 MkDeclaratorIdentifier(MkIdentifier(member.name)));
872 ListAdd(decls, MkStructDeclarator(decl, null));
873 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
876 member.dataType = ProcessType(specs, decl);
878 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
881 Type type = ProcessType(specs, decl);
882 DeclareType(member.dataType, false, false);
886 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
887 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
888 DeclareStruct(member.dataType._class.string, false);
891 ComputeTypeSize(member.dataType);
892 size = member.dataType.size;
893 alignment = member.dataType.alignment;
897 if(totalSize % alignment)
898 totalSize += alignment - (totalSize % alignment);
907 OldList * specs = MkList(), * list = MkList();
910 AddMembers(list, (Class)member, true, &size, topClass, null);
912 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
913 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
914 alignment = member.structAlignment;
918 if(totalSize % alignment)
919 totalSize += alignment - (totalSize % alignment);
929 if(topMember && topMember.type == unionMember)
930 *retSize = Max(*retSize, totalSize);
932 *retSize += totalSize;
934 else if(totalSize < maxSize && _class.type != systemClass)
937 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
938 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
939 if(totalSize + autoPadding < maxSize)
942 sprintf(sizeString, "%d", maxSize - totalSize);
943 ListAdd(declarations,
944 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
945 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
947 *addedPadding = true;
951 FinishTemplatesContext(context);
952 return topMember ? topMember.memberID : _class.memberID;
955 static int DeclareMembers(Class _class, bool isMember)
957 DataMember topMember = isMember ? (DataMember) _class : null;
960 Context context = isMember ? null : SetupTemplatesContext(_class);
962 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
963 DeclareMembers(_class.base, false);
965 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
967 if(!member.isProperty)
974 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
975 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
976 DeclareStruct(member.dataType._class.string, false);
978 if(!member.dataType && member.dataTypeString)
979 member.dataType = ProcessTypeString(member.dataTypeString, false);
981 DeclareType(member.dataType, false, false);
987 DeclareMembers((Class)member, true);
994 FinishTemplatesContext(context);
996 return topMember ? topMember.memberID : _class.memberID;
999 void DeclareStruct(char * name, bool skipNoHead)
1001 External external = null;
1002 Symbol classSym = FindClass(name);
1004 if(!inCompiler || !classSym) return;
1006 // We don't need any declaration for bit classes...
1007 if(classSym.registered &&
1008 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1011 /*if(classSym.registered.templateClass)
1012 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1015 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1017 // Add typedef struct
1019 OldList * specifiers, * declarators;
1020 OldList * declarations = null;
1021 char structName[1024];
1022 external = (classSym.registered && classSym.registered.type == structClass) ?
1023 classSym.pointerExternal : classSym.structExternal;
1025 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1026 // Moved this one up because DeclareClass done later will need it
1028 classSym.declaring++;
1030 if(strchr(classSym.string, '<'))
1032 if(classSym.registered.templateClass)
1034 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1035 classSym.declaring--;
1041 DeclareMembers(classSym.registered, false);
1044 FullClassNameCat(structName, name, false);
1047 external = MkExternalDeclaration(null);*/
1051 bool addedPadding = false;
1052 classSym.declaredStructSym = true;
1054 declarations = MkList();
1056 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1058 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1059 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1061 if(!declarations->count || (declarations->count == 1 && addedPadding))
1063 FreeList(declarations, FreeClassDef);
1064 declarations = null;
1067 if(skipNoHead || declarations)
1069 if(external && external.declaration)
1071 ((Specifier)external.declaration.specifiers->first).definitions = declarations;
1073 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1076 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1079 if(classSym.structExternal)
1080 ast->Move(classSym.structExternal, curExternal.prev);
1081 ast->Move(classSym.pointerExternal, curExternal.prev);
1083 classSym.id = curExternal.symbol.idCode;
1084 classSym.idCode = curExternal.symbol.idCode;
1085 // external = classSym.pointerExternal;
1086 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1092 external = MkExternalDeclaration(null);
1094 specifiers = MkList();
1095 declarators = MkList();
1096 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1099 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1100 ListAdd(declarators, MkInitDeclarator(d, null));
1102 external.declaration = decl = MkDeclaration(specifiers, declarators);
1103 if(decl.symbol && !decl.symbol.pointerExternal)
1104 decl.symbol.pointerExternal = external;
1106 // For simple classes, keep the declaration as the external to move around
1107 if(classSym.registered && classSym.registered.type == structClass)
1109 char className[1024];
1110 strcpy(className, "__ecereClass_");
1111 FullClassNameCat(className, classSym.string, true);
1112 MangleClassName(className);
1115 DeclareClass(classSym, className);
1117 external.symbol = classSym;
1118 classSym.pointerExternal = external;
1119 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1120 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1124 char className[1024];
1125 strcpy(className, "__ecereClass_");
1126 FullClassNameCat(className, classSym.string, true);
1127 MangleClassName(className);
1129 // TOFIX: TESTING THIS...
1130 classSym.structExternal = external;
1131 DeclareClass(classSym, className);
1132 external.symbol = classSym;
1136 ast->Insert(curExternal ? curExternal.prev : null, external);
1140 classSym.declaring--;
1142 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1144 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1145 // Moved this one up because DeclareClass done later will need it
1148 classSym.declaring++;
1152 if(classSym.registered)
1153 DeclareMembers(classSym.registered, false);
1156 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1159 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1162 if(classSym.structExternal)
1163 ast->Move(classSym.structExternal, curExternal.prev);
1164 ast->Move(classSym.pointerExternal, curExternal.prev);
1166 classSym.id = curExternal.symbol.idCode;
1167 classSym.idCode = curExternal.symbol.idCode;
1168 // external = classSym.pointerExternal;
1169 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1172 classSym.declaring--;
1177 void DeclareProperty(Property prop, char * setName, char * getName)
1179 Symbol symbol = prop.symbol;
1180 char propName[1024];
1182 strcpy(setName, "__ecereProp_");
1183 FullClassNameCat(setName, prop._class.fullName, false);
1184 strcat(setName, "_Set_");
1185 // strcat(setName, prop.name);
1186 FullClassNameCat(setName, prop.name, true);
1188 strcpy(getName, "__ecereProp_");
1189 FullClassNameCat(getName, prop._class.fullName, false);
1190 strcat(getName, "_Get_");
1191 FullClassNameCat(getName, prop.name, true);
1192 // strcat(getName, prop.name);
1194 strcpy(propName, "__ecereProp_");
1195 FullClassNameCat(propName, prop._class.fullName, false);
1196 strcat(propName, "_");
1197 FullClassNameCat(propName, prop.name, true);
1198 // strcat(propName, prop.name);
1200 // To support "char *" property
1201 MangleClassName(getName);
1202 MangleClassName(setName);
1203 MangleClassName(propName);
1205 if(prop._class.type == structClass)
1206 DeclareStruct(prop._class.fullName, false);
1208 if(!symbol || curExternal.symbol.idCode < symbol.id)
1210 bool imported = false;
1211 bool dllImport = false;
1212 if(!symbol || symbol._import)
1217 if(!prop._class.symbol)
1218 prop._class.symbol = FindClass(prop._class.fullName);
1219 classSym = prop._class.symbol;
1220 if(classSym && !classSym._import)
1222 ModuleImport module;
1224 if(prop._class.module)
1225 module = FindModule(prop._class.module);
1227 module = mainModule;
1229 classSym._import = ClassImport
1231 name = CopyString(prop._class.fullName);
1232 isRemote = prop._class.isRemote;
1234 module.classes.Add(classSym._import);
1236 symbol = prop.symbol = Symbol { };
1237 symbol._import = (ClassImport)PropertyImport
1239 name = CopyString(prop.name);
1240 isVirtual = false; //prop.isVirtual;
1241 hasSet = prop.Set ? true : false;
1242 hasGet = prop.Get ? true : false;
1245 classSym._import.properties.Add(symbol._import);
1248 if(prop._class.module != privateModule && prop._class.module.importType != staticImport)
1254 Context context = SetupTemplatesContext(prop._class);
1255 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1256 FinishTemplatesContext(context);
1262 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1265 OldList * specifiers, * declarators;
1270 Declarator typeDecl;
1271 bool simple = false;
1273 specifiers = MkList();
1274 declarators = MkList();
1277 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1278 MkDeclaratorIdentifier(MkIdentifier("this"))));
1280 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1283 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1286 Context context = SetupTemplatesContext(prop._class);
1287 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1288 FinishTemplatesContext(context);
1291 // Make sure the simple _class's type is declared
1292 for(spec = specifiers->first; spec; spec = spec.next)
1294 if(spec.type == nameSpecifier /*SpecifierClass*/)
1296 if((!typeDecl || typeDecl.type == identifierDeclarator))
1298 Symbol classSym = spec.symbol; // FindClass(spec.name);
1299 symbol._class = classSym.registered;
1300 if(classSym.registered && classSym.registered.type == structClass)
1302 DeclareStruct(spec.name, false);
1310 d = PlugDeclarator(typeDecl, d);
1313 ListAdd(params, MkTypeName(specifiers,
1314 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1315 specifiers = MkList();
1318 d = MkDeclaratorFunction(d, params);
1322 specifiers->Insert(null, MkSpecifier(EXTERN));
1323 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1324 specifiers->Insert(null, MkSpecifier(STATIC));
1326 ListAdd(specifiers, MkSpecifier(VOID));
1328 ListAdd(declarators, MkInitDeclarator(d, null));
1330 decl = MkDeclaration(specifiers, declarators);
1332 external = MkExternalDeclaration(decl);
1333 ast->Insert(curExternal.prev, external);
1334 external.symbol = symbol;
1335 symbol.externalGet = external;
1337 ReplaceThisClassSpecifiers(specifiers, prop._class);
1340 FreeDeclarator(typeDecl);
1344 // Move declaration higher...
1345 ast->Move(symbol.externalGet, curExternal.prev);
1352 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1355 OldList * specifiers, * declarators;
1360 Declarator typeDecl;
1362 declarators = MkList();
1365 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1366 if(!prop.conversion || prop._class.type == structClass)
1368 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1369 MkDeclaratorIdentifier(MkIdentifier("this"))));
1372 specifiers = MkList();
1375 Context context = SetupTemplatesContext(prop._class);
1376 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1377 MkDeclaratorIdentifier(MkIdentifier("value")));
1378 FinishTemplatesContext(context);
1380 ListAdd(params, MkTypeName(specifiers, d));
1382 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1385 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1386 d = MkDeclaratorFunction(d, params);
1388 // Make sure the simple _class's type is declared
1389 for(spec = specifiers->first; spec; spec = spec.next)
1391 if(spec.type == nameSpecifier /*SpecifierClass*/)
1393 if((!typeDecl || typeDecl.type == identifierDeclarator))
1395 Symbol classSym = spec.symbol; // FindClass(spec.name);
1396 symbol._class = classSym.registered;
1397 if(classSym.registered && classSym.registered.type == structClass)
1398 DeclareStruct(spec.name, false);
1403 ListAdd(declarators, MkInitDeclarator(d, null));
1405 specifiers = MkList();
1408 specifiers->Insert(null, MkSpecifier(EXTERN));
1409 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1410 specifiers->Insert(null, MkSpecifier(STATIC));
1412 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1413 if(!prop.conversion || prop._class.type == structClass)
1414 ListAdd(specifiers, MkSpecifier(VOID));
1416 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1418 decl = MkDeclaration(specifiers, declarators);
1420 external = MkExternalDeclaration(decl);
1421 ast->Insert(curExternal.prev, external);
1422 external.symbol = symbol;
1423 symbol.externalSet = external;
1425 ReplaceThisClassSpecifiers(specifiers, prop._class);
1429 // Move declaration higher...
1430 ast->Move(symbol.externalSet, curExternal.prev);
1434 // Property (for Watchers)
1435 if(!symbol.externalPtr)
1439 OldList * specifiers = MkList();
1442 specifiers->Insert(null, MkSpecifier(EXTERN));
1444 specifiers->Insert(null, MkSpecifier(STATIC));
1446 ListAdd(specifiers, MkSpecifierName("Property"));
1449 OldList * list = MkList();
1450 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1451 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1455 strcpy(propName, "__ecerePropM_");
1456 FullClassNameCat(propName, prop._class.fullName, false);
1457 strcat(propName, "_");
1458 // strcat(propName, prop.name);
1459 FullClassNameCat(propName, prop.name, true);
1461 MangleClassName(propName);
1463 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1464 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1466 decl = MkDeclaration(specifiers, list);
1469 external = MkExternalDeclaration(decl);
1470 ast->Insert(curExternal.prev, external);
1471 external.symbol = symbol;
1472 symbol.externalPtr = external;
1476 // Move declaration higher...
1477 ast->Move(symbol.externalPtr, curExternal.prev);
1480 symbol.id = curExternal.symbol.idCode;
1484 // ***************** EXPRESSION PROCESSING ***************************
1485 public Type Dereference(Type source)
1490 if(source.kind == pointerType || source.kind == arrayType)
1493 source.type.refCount++;
1495 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1503 // Support dereferencing of no head classes for now...
1504 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1510 Compiler_Error($"cannot dereference type\n");
1515 static Type Reference(Type source)
1531 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1533 Identifier ident = member.identifiers ? member.identifiers->first : null;
1535 DataMember dataMember = null;
1536 Method method = null;
1537 bool freeType = false;
1539 yylloc = member.loc;
1545 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1549 dataMember = *curMember;
1555 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1556 DataMember _subMemberStack[256];
1557 int _subMemberStackPos = 0;
1559 // FILL MEMBER STACK
1561 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1564 dataMember = thisMember;
1565 if(curMember && thisMember.memberAccess == publicAccess)
1567 *curMember = thisMember;
1568 *curClass = thisMember._class;
1569 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
1570 *subMemberStackPos = _subMemberStackPos;
1577 method = eClass_FindMethod(_class, ident.string, privateModule);
1578 if(method && method.type == virtualMethod)
1590 if(!dataMember.dataType && dataMember.dataTypeString)
1592 //Context context = SetupTemplatesContext(dataMember._class);
1593 Context context = SetupTemplatesContext(_class);
1594 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1595 FinishTemplatesContext(context);
1597 type = dataMember.dataType;
1601 // This is for destination type...
1602 if(!method.dataType)
1603 ProcessMethodType(method);
1604 //DeclareMethod(method);
1605 // method.dataType = ((Symbol)method.symbol)->type;
1606 type = method.dataType;
1609 if(ident && ident.next)
1611 for(ident = ident.next; ident && type; ident = ident.next)
1613 if(type.kind == classType)
1615 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1617 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1619 type = dataMember.dataType;
1621 else if(type.kind == structType || type.kind == unionType)
1624 for(memberType = type.members.first; memberType; memberType = memberType.next)
1626 if(!strcmp(memberType.name, ident.string))
1636 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1637 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1640 ClassTemplateParameter curParam = null;
1642 for(sClass = _class; sClass; sClass = sClass.base)
1645 if(sClass.templateClass) sClass = sClass.templateClass;
1646 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1648 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1650 for(sClass = sClass.base; sClass; sClass = sClass.base)
1652 if(sClass.templateClass) sClass = sClass.templateClass;
1653 id += sClass.templateParams.count;
1664 ClassTemplateArgument arg = _class.templateArgs[id];
1665 if(arg.dataTypeString)
1668 type = ProcessTypeString(arg.dataTypeString, false);
1670 if(type && _class.templateClass)
1671 type.passAsTemplate = true;
1677 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1678 exp.destType.refCount++;
1684 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1686 Class expClass = type._class.registered;
1687 Class cClass = null;
1692 char templateString[1024];
1693 ClassTemplateParameter param;
1694 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1695 for(cClass = expClass; cClass; cClass = cClass.base)
1698 if(cClass.templateClass) cClass = cClass.templateClass;
1699 for(param = cClass.templateParams.first; param; param = param.next)
1703 ClassTemplateArgument arg;
1704 for(sClass = cClass.base; sClass; sClass = sClass.base)
1706 if(sClass.templateClass) sClass = sClass.templateClass;
1707 id += sClass.templateParams.count;
1709 arg = expClass.templateArgs[id];
1711 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1713 ClassTemplateParameter cParam;
1714 //int p = numParams - sClass.templateParams.count;
1717 if(sClass.templateClass) sClass = sClass.templateClass;
1719 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1721 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1722 p += nextClass.templateParams.count;
1725 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1727 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1729 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1731 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1732 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1744 strcat(argument, arg.name.string);
1745 strcat(argument, " = ");
1751 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1752 char expString[1024];
1753 OldList * specs = MkList();
1754 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1756 char * string = PrintHexUInt64(arg.expression.ui64);
1757 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1759 ProcessExpressionType(exp);
1760 ComputeExpression(exp);
1761 expString[0] = '\0';
1762 PrintExpression(exp, expString);
1763 strcat(argument, expString);
1765 FreeExpression(exp);
1770 strcat(argument, arg.member.name);
1773 case TemplateParameterType::type:
1775 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1776 strcat(argument, arg.dataTypeString);
1782 if(paramCount) strcat(templateString, ", ");
1783 if(lastParam != p - 1)
1785 strcat(templateString, param.name);
1786 strcat(templateString, " = ");
1788 strcat(templateString, argument);
1797 int len = strlen(templateString);
1798 if(templateString[len-1] == '<')
1802 if(templateString[len-1] == '>')
1803 templateString[len++] = ' ';
1804 templateString[len++] = '>';
1806 templateString[len++] = '\0';
1809 Context context = SetupTemplatesContext(_class);
1810 if(freeType) FreeType(type);
1811 type = ProcessTypeString(templateString, false);
1813 FinishTemplatesContext(context);
1817 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1819 ProcessExpressionType(member.initializer.exp);
1820 if(!member.initializer.exp.expType)
1824 char expString[10240];
1825 expString[0] = '\0';
1826 PrintExpression(member.initializer.exp, expString);
1827 ChangeCh(expString, '\n', ' ');
1828 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1831 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1832 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1834 Compiler_Error($"incompatible instance method %s\n", ident.string);
1837 else if(member.initializer)
1840 FreeType(member.exp.destType);
1841 member.exp.destType = type;
1842 if(member.exp.destType)
1843 member.exp.destType.refCount++;
1844 ProcessExpressionType(member.exp);
1847 ProcessInitializer(member.initializer, type);
1849 if(freeType) FreeType(type);
1853 if(_class && _class.type == unitClass)
1855 if(member.initializer)
1858 FreeType(member.exp.destType);
1859 member.exp.destType = MkClassType(_class.fullName);
1860 ProcessExpressionType(member.initializer, type);
1862 Type type = MkClassType(_class.fullName);
1863 ProcessInitializer(member.initializer, type);
1869 if(member.initializer)
1871 //ProcessExpressionType(member.exp);
1872 ProcessInitializer(member.initializer, null);
1878 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1882 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1884 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1888 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1893 void ProcessInstantiationType(Instantiation inst)
1898 MembersInit members;
1899 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1902 /*if(!inst._class.symbol)
1903 inst._class.symbol = FindClass(inst._class.name);*/
1904 classSym = inst._class.symbol;
1905 _class = classSym ? classSym.registered : null;
1907 // DANGER: Patch for mutex not declaring its struct when not needed
1908 if(!_class || _class.type != noHeadClass)
1909 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1911 afterExternal = afterExternal ? afterExternal : curExternal;
1914 ProcessExpressionType(inst.exp);
1916 inst.isConstant = true;
1919 DataMember curMember = null;
1920 Class curClass = null;
1921 DataMember subMemberStack[256];
1922 int subMemberStackPos = 0;
1924 for(members = inst.members->first; members; members = members.next)
1926 switch(members.type)
1928 case methodMembersInit:
1931 static uint instMethodID = 0;
1932 External external = curExternal;
1933 Context context = curContext;
1934 Declarator declarator = members.function.declarator;
1935 Identifier nameID = GetDeclId(declarator);
1936 char * unmangled = nameID ? nameID.string : null;
1938 External createdExternal = null;
1943 //members.function.dontMangle = true;
1944 strcpy(name, "__ecereInstMeth_");
1945 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
1947 strcat(name, nameID.string);
1949 sprintf(number, "_%08d", instMethodID++);
1950 strcat(name, number);
1951 nameID.string = CopyString(name);
1954 // Do modifications here...
1957 Symbol symbol = declarator.symbol;
1958 Method method = eClass_FindMethod(_class, unmangled, privateModule);
1960 if(method && method.type == virtualMethod)
1962 symbol.method = method;
1963 ProcessMethodType(method);
1965 if(!symbol.type.thisClass)
1967 if(method.dataType.thisClass && currentClass &&
1968 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
1970 if(!currentClass.symbol)
1971 currentClass.symbol = FindClass(currentClass.fullName);
1972 symbol.type.thisClass = currentClass.symbol;
1977 _class.symbol = FindClass(_class.fullName);
1978 symbol.type.thisClass = _class.symbol;
1981 // TESTING THIS HERE:
1982 DeclareType(symbol.type, true, true);
1987 Compiler_Error($"couldn't find virtual method %s in class %s\n",
1988 unmangled, classSym.string);
1992 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
1993 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
1997 FreeSpecifier(nameID._class);
1998 nameID._class = null;
2004 Type type = declarator.symbol.type;
2005 External oldExternal = curExternal;
2007 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2008 // *** It was commented out for problems such as
2010 class VirtualDesktop : Window
2012 clientSize = Size { };
2023 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2025 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2028 if(strcmp(declarator.symbol.string, name))
2030 printf("TOCHECK: Look out for this\n");
2031 delete declarator.symbol.string;
2032 declarator.symbol.string = CopyString(name);
2035 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2037 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2038 excludedSymbols->Remove(declarator.symbol);
2039 globalContext.symbols.Add((BTNode)declarator.symbol);
2040 if(strstr(declarator.symbol.string), "::")
2041 globalContext.hasNameSpace = true;
2046 //curExternal = curExternal.prev;
2047 //afterExternal = afterExternal->next;
2049 //ProcessFunction(afterExternal->function);
2051 //curExternal = afterExternal;
2053 External externalDecl;
2054 externalDecl = MkExternalDeclaration(null);
2055 ast->Insert(oldExternal.prev, externalDecl);
2057 // Which function does this process?
2058 if(createdExternal.function)
2060 ProcessFunction(createdExternal.function);
2062 //curExternal = oldExternal;
2065 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2067 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2068 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2070 //externalDecl = MkExternalDeclaration(decl);
2072 //***** ast->Insert(external.prev, externalDecl);
2073 //ast->Insert(curExternal.prev, externalDecl);
2074 externalDecl.declaration = decl;
2075 if(decl.symbol && !decl.symbol.pointerExternal)
2076 decl.symbol.pointerExternal = externalDecl;
2078 // Trying this out...
2079 declarator.symbol.pointerExternal = externalDecl;
2086 curExternal = declarator.symbol.pointerExternal;
2087 ProcessFunction((FunctionDefinition)members.function);
2089 curExternal = external;
2090 curContext = context;
2094 FreeClassFunction(members.function);
2096 // In this pass, turn this into a MemberInitData
2097 exp = QMkExpId(name);
2098 members.type = dataMembersInit;
2099 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2105 case dataMembersInit:
2107 if(members.dataMembers && classSym)
2110 Location oldyyloc = yylloc;
2111 for(member = members.dataMembers->first; member; member = member.next)
2113 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2114 if(member.initializer && !member.initializer.isConstant)
2115 inst.isConstant = false;
2127 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2129 // OPTIMIZATIONS: TESTING THIS...
2132 if(type.kind == functionType)
2137 for(param = type.params.first; param; param = param.next)
2138 DeclareType(param, declarePointers, true);
2140 DeclareType(type.returnType, declarePointers, true);
2142 else if(type.kind == pointerType && declarePointers)
2143 DeclareType(type.type, declarePointers, false);
2144 else if(type.kind == classType)
2146 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2147 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2149 else if(type.kind == structType || type.kind == unionType)
2152 for(member = type.members.first; member; member = member.next)
2153 DeclareType(member, false, false);
2155 else if(type.kind == arrayType)
2156 DeclareType(type.arrayType, declarePointers, false);
2160 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2162 ClassTemplateArgument * arg = null;
2164 ClassTemplateParameter curParam = null;
2166 for(sClass = _class; sClass; sClass = sClass.base)
2169 if(sClass.templateClass) sClass = sClass.templateClass;
2170 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2172 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2174 for(sClass = sClass.base; sClass; sClass = sClass.base)
2176 if(sClass.templateClass) sClass = sClass.templateClass;
2177 id += sClass.templateParams.count;
2187 arg = &_class.templateArgs[id];
2188 if(arg && param.type == type)
2189 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2194 public Context SetupTemplatesContext(Class _class)
2196 Context context = PushContext();
2197 context.templateTypesOnly = true;
2198 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2200 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2201 for(; param; param = param.next)
2203 if(param.type == type && param.identifier)
2205 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2206 curContext.templateTypes.Add((BTNode)type);
2213 for(sClass = _class; sClass; sClass = sClass.base)
2215 ClassTemplateParameter p;
2216 for(p = sClass.templateParams.first; p; p = p.next)
2218 //OldList * specs = MkList();
2219 //Declarator decl = null;
2220 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2223 TemplateParameter param = p.param;
2227 // ADD DATA TYPE HERE...
2228 p.param = param = TemplateParameter
2230 identifier = MkIdentifier(p.name), type = p.type,
2231 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2234 type = TemplatedType { key = (uintptr)p.name, param = param };
2235 curContext.templateTypes.Add((BTNode)type);
2243 public void FinishTemplatesContext(Context context)
2245 PopContext(context);
2246 FreeContext(context);
2250 public void ProcessMethodType(Method method)
2252 if(!method.dataType)
2254 Context context = SetupTemplatesContext(method._class);
2256 method.dataType = ProcessTypeString(method.dataTypeString, false);
2258 FinishTemplatesContext(context);
2260 if(method.type != virtualMethod && method.dataType)
2262 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2264 if(!method._class.symbol)
2265 method._class.symbol = FindClass(method._class.fullName);
2266 method.dataType.thisClass = method._class.symbol;
2270 // Why was this commented out? Working fine without now...
2273 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2274 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2281 char * par = strstr(type, "(");
2282 char * classOp = null;
2287 for(c = par-type-1; c >= 0; c++)
2289 if(type[c] == ':' && type[c+1] == ':')
2291 classOp = type + c - 1;
2292 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2299 else if(!isspace(type[c]))
2306 int typeLen = strlen(type);
2307 memcpy(temp, classOp, classOpLen);
2308 temp[classOpLen] = '\0';
2310 _class = eSystem_FindClass(module, temp);
2313 method.dataTypeString = new char[typeLen - classOpLen + 1];
2314 memcpy(method.dataTypeString, type, classOp - type);
2315 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2318 method.dataTypeString = type;
2324 public void ProcessPropertyType(Property prop)
2328 Context context = SetupTemplatesContext(prop._class);
2329 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2330 FinishTemplatesContext(context);
2334 public void DeclareMethod(Method method, char * name)
2336 Symbol symbol = method.symbol;
2337 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2339 bool imported = false;
2340 bool dllImport = false;
2342 if(!method.dataType)
2343 method.dataType = ProcessTypeString(method.dataTypeString, false);
2345 if(!symbol || symbol._import || method.type == virtualMethod)
2347 if(!symbol || method.type == virtualMethod)
2350 if(!method._class.symbol)
2351 method._class.symbol = FindClass(method._class.fullName);
2352 classSym = method._class.symbol;
2353 if(!classSym._import)
2355 ModuleImport module;
2357 if(method._class.module && method._class.module.name)
2358 module = FindModule(method._class.module);
2360 module = mainModule;
2361 classSym._import = ClassImport
2363 name = CopyString(method._class.fullName);
2364 isRemote = method._class.isRemote;
2366 module.classes.Add(classSym._import);
2370 symbol = method.symbol = Symbol { };
2374 symbol._import = (ClassImport)MethodImport
2376 name = CopyString(method.name);
2377 isVirtual = method.type == virtualMethod;
2379 classSym._import.methods.Add(symbol._import);
2383 // Set the symbol type
2387 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2389 else if(type.thisClass == (void *)-1)
2391 type.thisClass = null;
2394 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2395 symbol.type = method.dataType;
2396 if(symbol.type) symbol.type.refCount++;
2399 if(!method.thisClass || strcmp(method.thisClass, "void"))
2400 symbol.type.params.Insert(null,
2401 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2404 if(!method.dataType.dllExport)
2407 if(method._class.module != privateModule && method._class.module.importType != staticImport)
2413 if(!method.dataType)
2414 method.dataType = ((Symbol)method.symbol).type;
2415 //ProcessMethodType(method);
2418 if(method.type != virtualMethod && method.dataType)
2419 DeclareType(method.dataType, true, true);
2421 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2423 // We need a declaration here :)
2425 OldList * specifiers, * declarators;
2427 Declarator funcDecl;
2430 specifiers = MkList();
2431 declarators = MkList();
2435 ListAdd(specifiers, MkSpecifier(EXTERN));
2436 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2437 ListAdd(specifiers, MkSpecifier(STATIC));
2439 if(method.type == virtualMethod)
2441 ListAdd(specifiers, MkSpecifier(INT));
2442 d = MkDeclaratorIdentifier(MkIdentifier(name));
2446 d = MkDeclaratorIdentifier(MkIdentifier(name));
2449 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2451 Context context = SetupTemplatesContext(method._class);
2452 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2453 FinishTemplatesContext(context);
2455 funcDecl = GetFuncDecl(d);
2459 Specifier spec, next;
2460 for(spec = specifiers->first; spec; spec = next)
2463 if(spec.type == extendedSpecifier)
2465 specifiers->Remove(spec);
2466 FreeSpecifier(spec);
2471 // Add this parameter if not a static method
2472 if(method.dataType && !method.dataType.staticMethod)
2474 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2476 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2477 TypeName thisParam = MkTypeName(MkListOne(
2478 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2479 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2480 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2481 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2483 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2485 TypeName param = funcDecl.function.parameters->first;
2486 funcDecl.function.parameters->Remove(param);
2487 FreeTypeName(param);
2490 if(!funcDecl.function.parameters)
2491 funcDecl.function.parameters = MkList();
2492 funcDecl.function.parameters->Insert(null, thisParam);
2495 // Make sure we don't have empty parameter declarations for static methods...
2497 else if(!funcDecl.function.parameters)
2499 funcDecl.function.parameters = MkList();
2500 funcDecl.function.parameters->Insert(null,
2501 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2505 ProcessDeclarator(d);
2507 ListAdd(declarators, MkInitDeclarator(d, null));
2509 decl = MkDeclaration(specifiers, declarators);
2511 ReplaceThisClassSpecifiers(specifiers, method._class);
2513 // Keep a different symbol for the function definition than the declaration...
2514 if(symbol.pointerExternal)
2516 Symbol functionSymbol { };
2520 *functionSymbol = *symbol;
2521 functionSymbol.string = CopyString(symbol.string);
2522 if(functionSymbol.type)
2523 functionSymbol.type.refCount++;
2526 excludedSymbols->Add(functionSymbol);
2527 symbol.pointerExternal.symbol = functionSymbol;
2529 external = MkExternalDeclaration(decl);
2531 ast->Insert(curExternal ? curExternal.prev : null, external);
2532 external.symbol = symbol;
2533 symbol.pointerExternal = external;
2537 // Move declaration higher...
2538 ast->Move(symbol.pointerExternal, curExternal.prev);
2541 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2545 char * ReplaceThisClass(Class _class)
2547 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2551 ClassTemplateParameter param;
2554 char className[1024];
2555 strcpy(className, _class.fullName);
2556 for(param = _class.templateParams.first; param; param = param.next)
2558 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2560 if(first) strcat(className, "<");
2561 if(!first) strcat(className, ", ");
2562 if(lastParam + 1 != p)
2564 strcat(className, param.name);
2565 strcat(className, " = ");
2567 strcat(className, param.name);
2575 int len = strlen(className);
2576 if(className[len-1] == '>') className[len++] = ' ';
2577 className[len++] = '>';
2578 className[len++] = '\0';
2580 return CopyString(className);
2583 return CopyString(_class.fullName);
2586 Type ReplaceThisClassType(Class _class)
2588 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2592 ClassTemplateParameter param;
2594 char className[1024];
2595 strcpy(className, _class.fullName);
2597 for(param = _class.templateParams.first; param; param = param.next)
2599 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2601 if(first) strcat(className, "<");
2602 if(!first) strcat(className, ", ");
2603 if(lastParam + 1 != p)
2605 strcat(className, param.name);
2606 strcat(className, " = ");
2608 strcat(className, param.name);
2616 int len = strlen(className);
2617 if(className[len-1] == '>') className[len++] = ' ';
2618 className[len++] = '>';
2619 className[len++] = '\0';
2621 return MkClassType(className);
2622 //return ProcessTypeString(className, false);
2626 return MkClassType(_class.fullName);
2627 //return ProcessTypeString(_class.fullName, false);
2631 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2633 if(specs != null && _class)
2636 for(spec = specs.first; spec; spec = spec.next)
2638 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2640 spec.type = nameSpecifier;
2641 spec.name = ReplaceThisClass(_class);
2642 spec.symbol = FindClass(spec.name); //_class.symbol;
2648 // Returns imported or not
2649 bool DeclareFunction(GlobalFunction function, char * name)
2651 Symbol symbol = function.symbol;
2652 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2654 bool imported = false;
2655 bool dllImport = false;
2657 if(!function.dataType)
2659 function.dataType = ProcessTypeString(function.dataTypeString, false);
2660 if(!function.dataType.thisClass)
2661 function.dataType.staticMethod = true;
2668 ModuleImport module = FindModule(function.module);
2669 // WARNING: This is not added anywhere...
2670 symbol = function.symbol = Symbol { };
2674 if(!function.dataType.dllExport)
2676 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2677 module.functions.Add(symbol._import);
2680 // Set the symbol type
2682 symbol.type = ProcessTypeString(function.dataTypeString, false);
2683 if(!symbol.type.thisClass)
2684 symbol.type.staticMethod = true;
2687 imported = symbol._import ? true : false;
2688 if(imported && function.module != privateModule && function.module.importType != staticImport)
2692 DeclareType(function.dataType, true, true);
2696 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2698 // We need a declaration here :)
2700 OldList * specifiers, * declarators;
2702 Declarator funcDecl;
2705 specifiers = MkList();
2706 declarators = MkList();
2709 ListAdd(specifiers, MkSpecifier(EXTERN));
2712 ListAdd(specifiers, MkSpecifier(STATIC));
2715 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2718 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2720 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2721 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2722 if(function.module.importType == staticImport)
2725 for(spec = specifiers->first; spec; spec = spec.next)
2726 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2728 specifiers->Remove(spec);
2729 FreeSpecifier(spec);
2734 funcDecl = GetFuncDecl(d);
2736 // Make sure we don't have empty parameter declarations for static methods...
2737 if(funcDecl && !funcDecl.function.parameters)
2739 funcDecl.function.parameters = MkList();
2740 funcDecl.function.parameters->Insert(null,
2741 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2744 ListAdd(declarators, MkInitDeclarator(d, null));
2747 Context oldCtx = curContext;
2748 curContext = globalContext;
2749 decl = MkDeclaration(specifiers, declarators);
2750 curContext = oldCtx;
2753 // Keep a different symbol for the function definition than the declaration...
2754 if(symbol.pointerExternal)
2756 Symbol functionSymbol { };
2759 *functionSymbol = *symbol;
2760 functionSymbol.string = CopyString(symbol.string);
2761 if(functionSymbol.type)
2762 functionSymbol.type.refCount++;
2765 excludedSymbols->Add(functionSymbol);
2767 symbol.pointerExternal.symbol = functionSymbol;
2769 external = MkExternalDeclaration(decl);
2771 ast->Insert(curExternal.prev, external);
2772 external.symbol = symbol;
2773 symbol.pointerExternal = external;
2777 // Move declaration higher...
2778 ast->Move(symbol.pointerExternal, curExternal.prev);
2782 symbol.id = curExternal.symbol.idCode;
2785 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2788 void DeclareGlobalData(GlobalData data)
2790 Symbol symbol = data.symbol;
2791 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2796 symbol = data.symbol = Symbol { };
2799 data.dataType = ProcessTypeString(data.dataTypeString, false);
2800 DeclareType(data.dataType, true, true);
2803 if(!symbol.pointerExternal)
2805 // We need a declaration here :)
2807 OldList * specifiers, * declarators;
2811 specifiers = MkList();
2812 declarators = MkList();
2814 ListAdd(specifiers, MkSpecifier(EXTERN));
2815 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2816 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2818 ListAdd(declarators, MkInitDeclarator(d, null));
2820 decl = MkDeclaration(specifiers, declarators);
2821 external = MkExternalDeclaration(decl);
2823 ast->Insert(curExternal.prev, external);
2824 external.symbol = symbol;
2825 symbol.pointerExternal = external;
2829 // Move declaration higher...
2830 ast->Move(symbol.pointerExternal, curExternal.prev);
2834 symbol.id = curExternal.symbol.idCode;
2839 class Conversion : struct
2841 Conversion prev, next;
2847 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2851 // Property convert;
2853 if(source.kind == templateType && dest.kind != templateType)
2855 Type type = ProcessTemplateParameterType(source.templateParameter);
2856 if(type) source = type;
2859 if(dest.kind == templateType && source.kind != templateType)
2861 Type type = ProcessTemplateParameterType(dest.templateParameter);
2862 if(type) dest = type;
2865 if((dest.classObjectType == typedObject && source.classObjectType != anyObject) || (dest.classObjectType == anyObject && source.classObjectType != typedObject))
2870 if(source.classObjectType == anyObject && dest.classObjectType != typedObject)
2875 if((dest.kind == structType && source.kind == structType) ||
2876 (dest.kind == unionType && source.kind == unionType))
2878 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2879 (source.members.first && source.members.first == dest.members.first))
2883 if(dest.kind == ellipsisType && source.kind != voidType)
2886 if(dest.kind == pointerType && dest.type.kind == voidType &&
2887 ((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))
2888 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2890 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2892 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2894 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2895 ((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))
2896 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2898 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2900 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2903 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2905 if(source._class.registered && source._class.registered.type == unitClass)
2907 if(conversions != null)
2909 if(source._class.registered == dest._class.registered)
2914 Class sourceBase, destBase;
2915 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2916 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2917 if(sourceBase == destBase)
2921 // Don't match enum inheriting from other enum if resolving enumeration values
2922 // TESTING: !dest.classObjectType
2923 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2925 (!source._class.registered || source._class.registered.type != enumClass) ||
2926 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2930 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2932 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2933 source._class && source._class.registered && source._class.registered.type != enumClass)
2935 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2943 // JUST ADDED THIS...
2944 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
2949 // Just added this for Straight conversion of ColorAlpha => Color
2950 if(source.kind == classType)
2953 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
2956 for(convert = _class.conversions.first; convert; convert = convert.next)
2958 if(convert.memberAccess == publicAccess || _class.module == privateModule)
2960 Conversion after = (conversions != null) ? conversions.last : null;
2962 if(!convert.dataType)
2963 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
2964 if(MatchTypes(convert.dataType, dest, conversions, null, null, false, true, false, true))
2966 if(!conversions && !convert.Get)
2968 else if(conversions != null)
2970 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
2971 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
2972 (dest.kind != classType || dest._class.registered != _class.base))
2976 Conversion conv { convert = convert, isGet = true };
2977 // conversions.Add(conv);
2978 conversions.Insert(after, conv);
2990 if(dest.kind == classType)
2993 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
2996 for(convert = _class.conversions.first; convert; convert = convert.next)
2998 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3000 // Conversion after = (conversions != null) ? conversions.last : null;
3002 if(!convert.dataType)
3003 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3004 // Just added this equality check to prevent recursion.... Make it safer?
3005 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3006 if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
3008 if(!conversions && !convert.Set)
3010 else if(conversions != null)
3012 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3013 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3014 (source.kind != classType || source._class.registered != _class.base))
3018 // *** Testing this! ***
3019 Conversion conv { convert = convert };
3020 conversions.Add(conv);
3021 //conversions.Insert(after, conv);
3029 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3031 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3032 (source.kind != classType || source._class.registered.type != structClass))
3036 // TESTING THIS... IS THIS OK??
3037 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3039 if(!dest._class.registered.dataType)
3040 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3041 // Only support this for classes...
3042 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3043 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3045 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3054 if(source.kind == classType)
3057 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3060 for(convert = _class.conversions.first; convert; convert = convert.next)
3062 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3064 Conversion after = (conversions != null) ? conversions.last : null;
3066 if(!convert.dataType)
3067 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3068 if(convert.dataType != source && MatchTypes(convert.dataType, dest, conversions, null, null, true, true, false, true))
3070 if(!conversions && !convert.Get)
3072 else if(conversions != null)
3074 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3075 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3076 (dest.kind != classType || dest._class.registered != _class.base))
3080 Conversion conv { convert = convert, isGet = true };
3082 // conversions.Add(conv);
3083 conversions.Insert(after, conv);
3092 // TESTING THIS... IS THIS OK??
3093 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3095 if(!source._class.registered.dataType)
3096 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3097 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, true, false, false))
3105 if(source.kind == classType || source.kind == subClassType)
3107 else if(dest.kind == source.kind &&
3108 (dest.kind != structType && dest.kind != unionType &&
3109 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3111 // RECENTLY ADDED THESE
3112 else if(dest.kind == doubleType && source.kind == floatType)
3114 else if(dest.kind == shortType && source.kind == charType)
3116 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == intSizeType /* Exception here for size_t */))
3118 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3120 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3122 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3124 else if(source.kind == enumType &&
3125 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3127 else if(dest.kind == enumType &&
3128 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3130 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3131 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3133 Type paramSource, paramDest;
3135 if(dest.kind == methodType)
3136 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3137 if(source.kind == methodType)
3138 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3140 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3141 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3142 if(dest.kind == methodType)
3143 dest = dest.method.dataType;
3144 if(source.kind == methodType)
3145 source = source.method.dataType;
3147 paramSource = source.params.first;
3148 if(paramSource && paramSource.kind == voidType) paramSource = null;
3149 paramDest = dest.params.first;
3150 if(paramDest && paramDest.kind == voidType) paramDest = null;
3153 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3154 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3156 // Source thisClass must be derived from destination thisClass
3157 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3158 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3160 if(paramDest && paramDest.kind == classType)
3161 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3163 Compiler_Error($"method class should not take an object\n");
3166 paramDest = paramDest.next;
3168 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3170 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3174 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3176 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3182 // THIS WAS BACKWARDS:
3183 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3184 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3187 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3189 Compiler_Error($"overriding class expected to be derived from method class\n");
3193 paramSource = paramSource.next;
3199 // Source thisClass must be derived from destination thisClass
3200 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3202 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3208 // THIS WAS BACKWARDS TOO??
3209 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3210 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3213 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3215 //Compiler_Error($"overriding class expected to be derived from method class\n");
3223 // Source return type must be derived from destination return type
3224 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3226 Compiler_Warning($"incompatible return type for function\n");
3232 for(; paramDest; paramDest = paramDest.next)
3236 //Compiler_Warning($"not enough parameters\n");
3237 Compiler_Error($"not enough parameters\n");
3241 Type paramDestType = paramDest;
3242 Type paramSourceType = paramSource;
3243 Type type = paramDestType;
3245 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3246 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3247 paramSource.kind != templateType)
3250 ClassTemplateParameter curParam = null;
3252 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3255 if(sClass.templateClass) sClass = sClass.templateClass;
3256 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3258 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3260 for(sClass = sClass.base; sClass; sClass = sClass.base)
3262 if(sClass.templateClass) sClass = sClass.templateClass;
3263 id += sClass.templateParams.count;
3274 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3275 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3279 // paramDest must be derived from paramSource
3280 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3281 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3285 PrintType(paramDest, type, false, true);
3286 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3288 if(paramDestType != paramDest)
3289 FreeType(paramDestType);
3292 if(paramDestType != paramDest)
3293 FreeType(paramDestType);
3296 paramSource = paramSource.next;
3300 Compiler_Error($"too many parameters\n");
3305 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3309 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3310 (source.kind == arrayType || source.kind == pointerType))
3312 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3319 static void FreeConvert(Conversion convert)
3321 if(convert.resultType)
3322 FreeType(convert.resultType);
3325 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3326 char * string, OldList conversions)
3330 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3332 Class _class = link.data;
3333 if(_class.type == enumClass)
3335 OldList converts { };
3337 type.kind = classType;
3340 _class.symbol = FindClass(_class.fullName);
3341 type._class = _class.symbol;
3343 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3346 Class enumClass = eSystem_FindClass(privateModule, "enum");
3350 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3352 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3353 for(value = e.values.first; value; value = value.next)
3355 if(!strcmp(value.name, string))
3360 FreeExpContents(sourceExp);
3361 FreeType(sourceExp.expType);
3363 sourceExp.isConstant = true;
3364 sourceExp.expType = MkClassType(baseClass.fullName);
3368 sourceExp.type = constantExp;
3369 if(!strcmp(baseClass.dataTypeString, "int"))
3370 sprintf(constant, "%d",value.data);
3372 sprintf(constant, "0x%X",value.data);
3373 sourceExp.constant = CopyString(constant);
3374 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3377 while(converts.first)
3379 Conversion convert = converts.first;
3380 converts.Remove(convert);
3381 conversions.Add(convert);
3390 converts.Free(FreeConvert);
3394 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3395 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3400 public bool ModuleVisibility(Module searchIn, Module searchFor)
3402 SubModule subModule;
3404 if(searchFor == searchIn)
3407 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3409 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3411 if(ModuleVisibility(subModule.module, searchFor))
3418 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3422 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3424 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3426 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3429 for(module = mainModule.application.allModules.first; module; module = module.next)
3431 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3437 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3439 Type source = sourceExp.expType;
3440 Type realDest = dest;
3442 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3445 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3447 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3449 Class sourceBase, destBase;
3450 for(sourceBase = source._class.registered;
3451 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3452 sourceBase = sourceBase.base);
3453 for(destBase = dest._class.registered;
3454 destBase && destBase.base && destBase.base.type != systemClass;
3455 destBase = destBase.base);
3456 //if(source._class.registered == dest._class.registered)
3457 if(sourceBase == destBase)
3466 int64 value = MAXINT;
3471 if(sourceExp.type == constantExp)
3474 value = strtoll(sourceExp.constant, null, 0);
3476 value = strtoull(sourceExp.constant, null, 0);
3478 else if(sourceExp.type == opExp && sourceExp.op.op == '-' && !sourceExp.op.exp1 && sourceExp.op.exp2 && sourceExp.op.exp2.type == constantExp)
3481 value = -strtoll(sourceExp.op.exp2.constant, null, 0);
3483 value = -strtoull(sourceExp.op.exp2.constant, null, 0);
3486 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3487 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3490 source = Type { kind = intType, isSigned = false, refCount = 1 };
3493 if(dest.kind == classType)
3495 Class _class = dest._class ? dest._class.registered : null;
3497 if(_class && _class.type == unitClass)
3499 if(source.kind != classType)
3502 Type tempDest, tempSource;
3504 for(; _class.base.type != systemClass; _class = _class.base);
3506 tempDest = tempType;
3508 tempType.kind = classType;
3510 _class.symbol = FindClass(_class.fullName);
3512 tempType._class = _class.symbol;
3513 tempType.truth = dest.truth;
3515 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3517 FreeType(sourceExp.expType);
3518 sourceExp.expType = dest; dest.refCount++;
3520 //sourceExp.expType = MkClassType(_class.fullName);
3528 // Why wasn't there something like this?
3529 if(_class && _class.type == bitClass && source.kind != classType)
3531 if(!dest._class.registered.dataType)
3532 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3533 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3536 FreeType(sourceExp.expType);
3537 source = sourceExp.expType = MkClassType(dest._class.string);
3540 //source.kind = classType;
3541 //source._class = dest._class;
3545 // Adding two enumerations
3547 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3549 if(!source._class.registered.dataType)
3550 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3551 if(!dest._class.registered.dataType)
3552 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3554 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3557 source = sourceExp.expType = MkClassType(dest._class.string);
3560 //source.kind = classType;
3561 //source._class = dest._class;
3565 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3567 OldList * specs = MkList();
3571 ReadString(string, sourceExp.string);
3572 decl = SpecDeclFromString(string, specs, null);
3574 FreeExpContents(sourceExp);
3575 FreeType(sourceExp.expType);
3577 sourceExp.type = classExp;
3578 sourceExp._classExp.specifiers = specs;
3579 sourceExp._classExp.decl = decl;
3580 sourceExp.expType = dest;
3588 else if(source.kind == classType)
3590 Class _class = source._class ? source._class.registered : null;
3592 if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3595 if(dest.kind != classType)
3597 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3598 if(!source._class.registered.dataType)
3599 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3602 dest = MkClassType(source._class.string);
3603 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3604 // dest = MkClassType(source._class.string);
3608 if(dest.kind != classType)
3611 Type tempDest, tempSource;
3613 if(!source._class.registered.dataType)
3614 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3616 for(; _class.base.type != systemClass; _class = _class.base);
3618 tempSource = tempType;
3619 tempType.kind = classType;
3620 tempType._class = FindClass(_class.fullName);
3621 tempType.truth = source.truth;
3622 tempType.classObjectType = source.classObjectType;
3625 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3627 // PUT THIS BACK TESTING UNITS?
3628 if(conversions.last)
3630 ((Conversion)(conversions.last)).resultType = dest;
3634 FreeType(sourceExp.expType);
3635 sourceExp.expType = MkClassType(_class.fullName);
3636 sourceExp.expType.truth = source.truth;
3637 sourceExp.expType.classObjectType = source.classObjectType;
3639 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3641 if(!sourceExp.destType)
3643 FreeType(sourceExp.destType);
3644 sourceExp.destType = sourceExp.expType;
3645 if(sourceExp.expType)
3646 sourceExp.expType.refCount++;
3649 //source = _class.dataType;
3652 // TOCHECK: TESTING THIS NEW CODE
3653 if(!_class.dataType)
3654 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3656 dest = MkClassType(source._class.string);
3657 dest.truth = source.truth;
3658 dest.classObjectType = source.classObjectType;
3661 source = _class.dataType;
3671 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3681 if(source.kind == classType)
3683 Class _class = source._class.registered;
3684 if(_class.type == unitClass)
3686 if(!_class.dataType)
3687 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3688 source = _class.dataType;
3692 if(dest.kind == classType)
3694 Class _class = dest._class ? dest._class.registered : null;
3695 if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
3696 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3698 if(_class.type == normalClass || _class.type == noHeadClass)
3700 Expression newExp { };
3701 *newExp = *sourceExp;
3702 if(sourceExp.destType) sourceExp.destType.refCount++;
3703 if(sourceExp.expType) sourceExp.expType.refCount++;
3704 sourceExp.type = castExp;
3705 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3706 sourceExp.cast.exp = newExp;
3707 FreeType(sourceExp.expType);
3708 sourceExp.expType = null;
3709 ProcessExpressionType(sourceExp);
3711 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3714 FreeType(sourceExp.expType);
3715 sourceExp.expType = dest;
3719 if(inCompiler) FreeType(dest);
3724 if(!_class.dataType)
3725 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3727 dest = _class.dataType;
3731 // Accept lower precision types for units, since we want to keep the unit type
3732 if(dest.kind == doubleType &&
3733 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3734 source.kind == charType))
3736 specs = MkListOne(MkSpecifier(DOUBLE));
3738 else if(dest.kind == floatType &&
3739 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3740 source.kind == doubleType))
3742 specs = MkListOne(MkSpecifier(FLOAT));
3744 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3745 source.kind == floatType || source.kind == doubleType))
3748 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3749 ListAdd(specs, MkSpecifier(INT64));
3751 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3752 source.kind == floatType || source.kind == doubleType))
3755 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3756 ListAdd(specs, MkSpecifier(INT));
3758 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == intType ||
3759 source.kind == floatType || source.kind == doubleType))
3762 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3763 ListAdd(specs, MkSpecifier(SHORT));
3765 else if(dest.kind == charType && (source.kind == charType || source.kind == shortType || source.kind == intType ||
3766 source.kind == floatType || source.kind == doubleType))
3769 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3770 ListAdd(specs, MkSpecifier(CHAR));
3779 else if(dest.kind == doubleType &&
3780 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3781 source.kind == charType))
3783 specs = MkListOne(MkSpecifier(DOUBLE));
3785 else if(dest.kind == floatType &&
3786 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3788 specs = MkListOne(MkSpecifier(FLOAT));
3790 else if(dest.kind == charType && (source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3791 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3794 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3795 ListAdd(specs, MkSpecifier(CHAR));
3797 else if(dest.kind == shortType && (source.kind == enumType || source.kind == charType || source.kind == shortType ||
3798 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3801 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3802 ListAdd(specs, MkSpecifier(SHORT));
3804 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType))
3807 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3808 ListAdd(specs, MkSpecifier(INT));
3810 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3813 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3814 ListAdd(specs, MkSpecifier(INT64));
3816 else if(dest.kind == enumType &&
3817 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3819 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3830 Expression newExp { };
3831 *newExp = *sourceExp;
3834 if(sourceExp.destType) sourceExp.destType.refCount++;
3835 if(sourceExp.expType) sourceExp.expType.refCount++;
3837 sourceExp.type = castExp;
3838 if(realDest.kind == classType)
3840 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3841 FreeList(specs, FreeSpecifier);
3844 sourceExp.cast.typeName = MkTypeName(specs, null);
3845 if(newExp.type == opExp)
3847 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3850 sourceExp.cast.exp = newExp;
3852 FreeType(sourceExp.expType);
3853 sourceExp.expType = null;
3854 ProcessExpressionType(sourceExp);
3857 FreeList(specs, FreeSpecifier);
3865 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
3866 if(sourceExp.type == identifierExp)
3868 Identifier id = sourceExp.identifier;
3869 if(dest.kind == classType)
3871 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3873 Class _class = dest._class.registered;
3874 Class enumClass = eSystem_FindClass(privateModule, "enum");
3877 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
3880 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
3881 for(value = e.values.first; value; value = value.next)
3883 if(!strcmp(value.name, id.string))
3888 FreeExpContents(sourceExp);
3889 FreeType(sourceExp.expType);
3891 sourceExp.isConstant = true;
3892 sourceExp.expType = MkClassType(_class.fullName);
3896 sourceExp.type = constantExp;
3897 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
3898 sprintf(constant, "%d",value.data);
3900 sprintf(constant, "0x%X",value.data);
3901 sourceExp.constant = CopyString(constant);
3902 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
3911 // Loop through all enum classes
3912 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
3919 #define TERTIARY(o, name, m, t, p) \
3920 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
3922 exp.type = constantExp; \
3923 exp.string = p(op1.m ? op2.m : op3.m); \
3925 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3929 #define BINARY(o, name, m, t, p) \
3930 static bool name(Expression exp, Operand op1, Operand op2) \
3933 exp.type = constantExp; \
3934 exp.string = p(op1.m o value2); \
3936 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3940 #define BINARY_DIVIDE(o, name, m, t, p) \
3941 static bool name(Expression exp, Operand op1, Operand op2) \
3944 exp.type = constantExp; \
3945 exp.string = p(value2 ? (op1.m o value2) : 0); \
3947 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3951 #define UNARY(o, name, m, t, p) \
3952 static bool name(Expression exp, Operand op1) \
3954 exp.type = constantExp; \
3955 exp.string = p(o op1.m); \
3957 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3961 #define OPERATOR_ALL(macro, o, name) \
3962 macro(o, Int##name, i, int, PrintInt) \
3963 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
3964 macro(o, Short##name, s, short, PrintShort) \
3965 macro(o, UShort##name, us, unsigned short, PrintUShort) \
3966 macro(o, Char##name, c, char, PrintChar) \
3967 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
3968 macro(o, Float##name, f, float, PrintFloat) \
3969 macro(o, Double##name, d, double, PrintDouble)
3971 #define OPERATOR_INTTYPES(macro, o, name) \
3972 macro(o, Int##name, i, int, PrintInt) \
3973 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
3974 macro(o, Short##name, s, short, PrintShort) \
3975 macro(o, UShort##name, us, unsigned short, PrintUShort) \
3976 macro(o, Char##name, c, char, PrintChar) \
3977 macro(o, UChar##name, uc, unsigned char, PrintUChar)
3980 // binary arithmetic
3981 OPERATOR_ALL(BINARY, +, Add)
3982 OPERATOR_ALL(BINARY, -, Sub)
3983 OPERATOR_ALL(BINARY, *, Mul)
3984 OPERATOR_ALL(BINARY_DIVIDE, /, Div)
3985 OPERATOR_INTTYPES(BINARY_DIVIDE, %, Mod)
3988 OPERATOR_ALL(UNARY, -, Neg)
3990 // unary arithmetic increment and decrement
3991 OPERATOR_ALL(UNARY, ++, Inc)
3992 OPERATOR_ALL(UNARY, --, Dec)
3994 // binary arithmetic assignment
3995 OPERATOR_ALL(BINARY, =, Asign)
3996 OPERATOR_ALL(BINARY, +=, AddAsign)
3997 OPERATOR_ALL(BINARY, -=, SubAsign)
3998 OPERATOR_ALL(BINARY, *=, MulAsign)
3999 OPERATOR_ALL(BINARY_DIVIDE, /=, DivAsign)
4000 OPERATOR_INTTYPES(BINARY_DIVIDE, %=, ModAsign)
4003 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4004 OPERATOR_INTTYPES(BINARY, |, BitOr)
4005 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4006 OPERATOR_INTTYPES(BINARY, <<, LShift)
4007 OPERATOR_INTTYPES(BINARY, >>, RShift)
4010 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4012 // binary bitwise assignment
4013 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4014 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4015 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4016 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4017 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4019 // unary logical negation
4020 OPERATOR_INTTYPES(UNARY, !, Not)
4022 // binary logical equality
4023 OPERATOR_ALL(BINARY, ==, Equ)
4024 OPERATOR_ALL(BINARY, !=, Nqu)
4027 OPERATOR_ALL(BINARY, &&, And)
4028 OPERATOR_ALL(BINARY, ||, Or)
4030 // binary logical relational
4031 OPERATOR_ALL(BINARY, >, Grt)
4032 OPERATOR_ALL(BINARY, <, Sma)
4033 OPERATOR_ALL(BINARY, >=, GrtEqu)
4034 OPERATOR_ALL(BINARY, <=, SmaEqu)
4036 // tertiary condition operator
4037 OPERATOR_ALL(TERTIARY, ?, Cond)
4039 //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
4040 #define OPERATOR_TABLE_ALL(name, type) \
4041 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4043 type##Inc, type##Dec, \
4044 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4045 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4047 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4049 type##Equ, type##Nqu, \
4050 type##And, type##Or, \
4051 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4054 #define OPERATOR_TABLE_INTTYPES(name, type) \
4055 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4057 type##Inc, type##Dec, \
4058 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4059 null, null, null, null, null, \
4061 null, null, null, null, null, \
4063 type##Equ, type##Nqu, \
4064 type##And, type##Or, \
4065 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4068 OPERATOR_TABLE_ALL(int, Int)
4069 OPERATOR_TABLE_ALL(uint, UInt)
4070 OPERATOR_TABLE_ALL(short, Short)
4071 OPERATOR_TABLE_ALL(ushort, UShort)
4072 OPERATOR_TABLE_INTTYPES(float, Float)
4073 OPERATOR_TABLE_INTTYPES(double, Double)
4074 OPERATOR_TABLE_ALL(char, Char)
4075 OPERATOR_TABLE_ALL(uchar, UChar)
4077 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4078 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4079 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4080 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4081 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4082 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4083 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4084 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4086 public void ReadString(char * output, char * string)
4088 int len = strlen(string);
4090 bool quoted = false, escaped = false;
4091 for(c = 0; c<len; c++)
4093 char ch = string[c];
4098 case 'n': output[d] = '\n'; break;
4099 case 't': output[d] = '\t'; break;
4100 case 'a': output[d] = '\a'; break;
4101 case 'b': output[d] = '\b'; break;
4102 case 'f': output[d] = '\f'; break;
4103 case 'r': output[d] = '\r'; break;
4104 case 'v': output[d] = '\v'; break;
4105 case '\\': output[d] = '\\'; break;
4106 case '\"': output[d] = '\"'; break;
4107 default: output[d++] = '\\'; output[d] = ch;
4108 //default: output[d] = ch;
4129 public Operand GetOperand(Expression exp)
4132 Type type = exp.expType;
4135 while(type.kind == classType &&
4136 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4138 if(!type._class.registered.dataType)
4139 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4140 type = type._class.registered.dataType;
4143 op.kind = type.kind;
4144 op.type = exp.expType;
4145 if(exp.isConstant && exp.type == constantExp)
4151 if(exp.constant[0] == '\'')
4152 op.c = exp.constant[1];
4153 else if(type.isSigned)
4155 op.c = (char)strtol(exp.constant, null, 0);
4160 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4168 op.s = (short)strtol(exp.constant, null, 0);
4173 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4181 op.i = (int)strtol(exp.constant, null, 0);
4186 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4194 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4199 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4207 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4212 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4220 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4225 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4231 op.f = (float)strtod(exp.constant, null);
4235 op.d = (double)strtod(exp.constant, null);
4238 //case classType: For when we have operator overloading...
4239 // Pointer additions
4240 //case functionType:
4244 op.ui64 = _strtoui64(exp.constant, null, 0);
4245 op.kind = pointerType;
4255 static void UnusedFunction()
4258 a.OnGetString(0,0,0);
4261 extern int __ecereVMethodID_class_OnGetString;
4264 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4266 DataMember dataMember;
4267 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4269 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4270 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4274 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4276 void * ptr = inst.data + dataMember.offset + offset;
4277 char * result = null;
4278 exp.loc = member.loc = inst.loc;
4279 ((Identifier)member.identifiers->first).loc = inst.loc;
4281 if(!dataMember.dataType)
4282 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4283 type = dataMember.dataType;
4284 if(type.kind == classType)
4286 Class _class = type._class.registered;
4287 if(_class.type == enumClass)
4289 Class enumClass = eSystem_FindClass(privateModule, "enum");
4292 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4294 for(item = e.values.first; item; item = item.next)
4296 if((int)item.data == *(int *)ptr)
4304 exp.identifier = MkIdentifier(result);
4305 exp.type = identifierExp;
4306 exp.destType = MkClassType(_class.fullName);
4307 ProcessExpressionType(exp);
4311 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4313 if(!_class.dataType)
4314 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4315 type = _class.dataType;
4324 FreeExpContents(exp);
4326 exp.constant = PrintFloat(*(float*)ptr);
4327 exp.type = constantExp;
4332 FreeExpContents(exp);
4334 exp.constant = PrintDouble(*(double*)ptr);
4335 exp.type = constantExp;
4340 FreeExpContents(exp);
4342 exp.constant = PrintInt(*(int*)ptr);
4343 exp.type = constantExp;
4348 FreeExpContents(exp);
4350 exp.constant = PrintInt64(*(int64*)ptr);
4351 exp.type = constantExp;
4356 FreeExpContents(exp);
4357 // TODO: This should probably use proper type
4358 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4359 exp.type = constantExp;
4364 FreeExpContents(exp);
4365 // TODO: This should probably use proper type
4366 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4367 exp.type = constantExp;
4371 Compiler_Error($"Unhandled type populating instance\n");
4374 ListAdd(memberList, member);
4377 if(parentDataMember.type == unionMember)
4382 void PopulateInstance(Instantiation inst)
4384 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4385 Class _class = classSym.registered;
4386 DataMember dataMember;
4387 OldList * memberList = MkList();
4388 inst.members = MkListOne(MkMembersInitList(memberList));
4389 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4391 if(!dataMember.isProperty)
4393 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4394 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4398 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4400 void * ptr = inst.data + dataMember.offset;
4401 char * result = null;
4403 exp.loc = member.loc = inst.loc;
4404 ((Identifier)member.identifiers->first).loc = inst.loc;
4406 if(!dataMember.dataType)
4407 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4408 type = dataMember.dataType;
4409 if(type.kind == classType)
4411 Class _class = type._class.registered;
4412 if(_class.type == enumClass)
4414 Class enumClass = eSystem_FindClass(privateModule, "enum");
4417 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4419 for(item = e.values.first; item; item = item.next)
4421 if((int)item.data == *(int *)ptr)
4430 exp.identifier = MkIdentifier(result);
4431 exp.type = identifierExp;
4432 exp.destType = MkClassType(_class.fullName);
4433 ProcessExpressionType(exp);
4436 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4438 if(!_class.dataType)
4439 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4440 type = _class.dataType;
4449 exp.constant = PrintFloat(*(float*)ptr);
4450 exp.type = constantExp;
4455 exp.constant = PrintDouble(*(double*)ptr);
4456 exp.type = constantExp;
4461 exp.constant = PrintInt(*(int*)ptr);
4462 exp.type = constantExp;
4467 exp.constant = PrintInt64(*(int64*)ptr);
4468 exp.type = constantExp;
4473 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4474 exp.type = constantExp;
4478 Compiler_Error($"Unhandled type populating instance\n");
4481 ListAdd(memberList, member);
4487 void ComputeInstantiation(Expression exp)
4489 Instantiation inst = exp.instance;
4490 MembersInit members;
4491 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4492 Class _class = classSym ? classSym.registered : null;
4493 DataMember curMember = null;
4494 Class curClass = null;
4495 DataMember subMemberStack[256];
4496 int subMemberStackPos = 0;
4499 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4501 // Don't recompute the instantiation...
4502 // Non Simple classes will have become constants by now
4506 if(_class.type == normalClass || _class.type == noHeadClass)
4507 inst.data = (byte *)eInstance_New(_class);
4509 inst.data = new0 byte[_class.structSize];
4514 for(members = inst.members->first; members; members = members.next)
4516 switch(members.type)
4518 case dataMembersInit:
4520 if(members.dataMembers)
4523 for(member = members.dataMembers->first; member; member = member.next)
4525 Identifier ident = member.identifiers ? member.identifiers->first : null;
4528 Property prop = null;
4529 DataMember dataMember = null;
4530 Method method = null;
4531 uint dataMemberOffset;
4535 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4538 if(curMember.isProperty)
4539 prop = (Property)curMember;
4542 dataMember = curMember;
4544 // CHANGED THIS HERE
4545 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4546 // dataMemberOffset = dataMember.offset;
4553 prop = eClass_FindProperty(_class, ident.string, privateModule);
4557 if(prop.memberAccess == publicAccess)
4559 curMember = (DataMember)prop;
4560 curClass = prop._class;
4565 DataMember _subMemberStack[256];
4566 int _subMemberStackPos = 0;
4568 // FILL MEMBER STACK
4569 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4574 if(dataMember.memberAccess == publicAccess)
4576 curMember = dataMember;
4577 curClass = dataMember._class;
4578 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
4579 subMemberStackPos = _subMemberStackPos;
4585 if(found && member.initializer && member.initializer.type == expInitializer)
4587 Expression value = member.initializer.exp;
4591 type = prop.dataType;
4595 if(!dataMember.dataType)
4596 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4598 type = dataMember.dataType;
4601 if(ident && ident.next)
4603 // for(; ident && type; ident = ident.next)
4604 for(ident = ident.next; ident && type; ident = ident.next)
4606 if(type.kind == classType)
4608 prop = eClass_FindProperty(type._class.registered,
4609 ident.string, privateModule);
4611 type = prop.dataType;
4614 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4615 ident.string, &dataMemberOffset, privateModule, null, null);
4617 type = dataMember.dataType;
4620 else if(type.kind == structType || type.kind == unionType)
4623 for(memberType = type.members.first; memberType; memberType = memberType.next)
4625 if(!strcmp(memberType.name, ident.string))
4636 FreeType(value.destType);
4637 value.destType = type;
4638 if(type) type.refCount++;
4639 ComputeExpression(value);
4641 if(value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4643 if(type.kind == classType)
4645 Class _class = type._class.registered;
4646 if(_class.type == bitClass || _class.type == unitClass ||
4647 _class.type == enumClass)
4649 if(!_class.dataType)
4650 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4651 type = _class.dataType;
4657 void * ptr = inst.data + dataMemberOffset;
4659 if(value.type == constantExp)
4665 GetInt(value, (int*)ptr);
4670 GetInt64(value, (int64*)ptr);
4675 GetIntPtr(value, (intptr*)ptr);
4680 GetIntSize(value, (intsize*)ptr);
4685 GetFloat(value, (float*)ptr);
4690 GetDouble(value, (double *)ptr);
4695 else if(value.type == instanceExp)
4697 if(type.kind == classType)
4699 Class _class = type._class.registered;
4700 if(_class.type == structClass)
4702 ComputeTypeSize(type);
4703 if(value.instance.data)
4704 memcpy(ptr, value.instance.data, type.size);
4711 if(value.type == instanceExp && value.instance.data)
4713 void (*Set)(void *, void *) = (void *)prop.Set;
4714 Set(inst.data, value.instance.data);
4715 PopulateInstance(inst);
4717 else if(value.type == constantExp)
4723 void (*Set)(void *, double) = (void *)prop.Set;
4724 Set(inst.data, strtod(value.constant, null) );
4729 void (*Set)(void *, float) = (void *)prop.Set;
4730 Set(inst.data, (float)(strtod(value.constant, null)));
4735 void (*Set)(void *, int) = (void *)prop.Set;
4736 Set(inst.data, strtol(value.constant, null, 0));
4741 void (*Set)(void *, int64) = (void *)prop.Set;
4742 Set(inst.data, _strtoi64(value.constant, null, 0));
4747 void (*Set)(void *, intptr) = (void *)prop.Set;
4748 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
4753 void (*Set)(void *, intsize) = (void *)prop.Set;
4754 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
4759 else if(value.type == stringExp)
4762 ReadString(temp, value.string);
4763 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
4767 else if(_class.type == unitClass)
4771 // Only support converting units to units for now...
4772 if(value.type == constantExp)
4774 if(type.kind == classType)
4776 Class _class = type._class.registered;
4777 if(_class.type == unitClass)
4779 if(!_class.dataType)
4780 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4781 type = _class.dataType;
4784 // TODO: Assuming same base type for units...
4790 float (*Set)(float) = (void *)prop.Set;
4791 GetFloat(member.initializer.exp, &fValue);
4792 exp.constant = PrintFloat(Set(fValue));
4793 exp.type = constantExp;
4799 double (*Set)(double) = (void *)prop.Set;
4800 GetDouble(member.initializer.exp, &dValue);
4801 exp.constant = PrintDouble(Set(dValue));
4802 exp.type = constantExp;
4809 else if(_class.type == bitClass)
4813 if(value.type == instanceExp && value.instance.data)
4815 unsigned int (*Set)(void *) = (void *)prop.Set;
4816 bits = Set(value.instance.data);
4818 else if(value.type == constantExp)
4824 BitMember bitMember = (BitMember) dataMember;
4827 GetInt(value, &part);
4828 bits = (bits & ~bitMember.mask);
4829 if(!bitMember.dataType)
4830 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
4832 type = bitMember.dataType;
4834 if(type.kind == classType && type._class && type._class.registered)
4836 if(!type._class.registered.dataType)
4837 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4838 type = type._class.registered.dataType;
4845 bits |= ((char)part << bitMember.pos);
4847 bits |= ((unsigned char)part << bitMember.pos);
4851 bits |= ((short)part << bitMember.pos);
4853 bits |= ((unsigned short)part << bitMember.pos);
4858 bits |= ((int)part << bitMember.pos);
4860 bits |= ((unsigned int)part << bitMember.pos);
4864 bits |= ((int64)part << bitMember.pos);
4866 bits |= ((uint64)part << bitMember.pos);
4871 bits |= ((intptr)part << bitMember.pos);
4875 bits |= ((uintptr)part << bitMember.pos);
4881 bits |= ((ssize_t)(intsize)part << bitMember.pos);
4885 bits |= ((size_t) (uintsize)part << bitMember.pos);
4894 if(_class && _class.type == unitClass)
4896 ComputeExpression(member.initializer.exp);
4897 exp.constant = member.initializer.exp.constant;
4898 exp.type = constantExp;
4900 member.initializer.exp.constant = null;
4910 if(_class && _class.type == bitClass)
4912 exp.constant = PrintHexUInt(bits);
4913 exp.type = constantExp;
4915 if(exp.type != instanceExp)
4921 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
4923 if(exp.op.op == SIZEOF)
4925 FreeExpContents(exp);
4926 exp.type = constantExp;
4927 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
4938 // Provide default unary +
4939 Expression exp2 = exp.op.exp2;
4941 FreeExpContents(exp);
4942 FreeType(exp.expType);
4943 FreeType(exp.destType);
4949 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
4951 // unary arithmetic increment and decrement
4952 //OPERATOR_ALL(UNARY, ++, Inc)
4953 //OPERATOR_ALL(UNARY, --, Dec)
4956 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
4958 // unary logical negation
4960 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
4968 // binary arithmetic
4970 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
4973 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
4976 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
4979 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
4982 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
4984 // binary arithmetic assignment
4985 //OPERATOR_ALL(BINARY, =, Asign)
4986 //OPERATOR_ALL(BINARY, +=, AddAsign)
4987 //OPERATOR_ALL(BINARY, -=, SubAsign)
4988 //OPERATOR_ALL(BINARY, *=, MulAsign)
4989 //OPERATOR_ALL(BINARY, /=, DivAsign)
4990 //OPERATOR_ALL(BINARY, %=, ModAsign)
4995 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
4999 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5002 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5005 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5008 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5010 // binary bitwise assignment
5011 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5012 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5013 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5014 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5015 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5016 // binary logical equality
5018 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5021 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5025 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5028 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5030 // binary logical relational
5032 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5035 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5038 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5041 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5048 void ComputeExpression(Expression exp)
5050 char expString[10240];
5051 expString[0] = '\0';
5053 PrintExpression(exp, expString);
5060 ComputeInstantiation(exp);
5069 Expression exp1, exp2 = null;
5073 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5075 ComputeExpression(exp.op.exp2);
5078 ComputeExpression(exp.op.exp1);
5081 op1 = GetOperand(exp1);
5082 if(op1.type) op1.type.refCount++;
5085 op2 = GetOperand(exp2);
5086 if(op2.type) op2.type.refCount++;
5092 op1 = GetOperand(exp1);
5093 if(op1.type) op1.type.refCount++;
5096 CallOperator(exp, exp1, exp2, op1, op2);
5103 if(exp.op.exp1 && exp.op.exp2)
5108 FreeExpContents(exp);
5109 op1.ops.BitAnd(exp, op1, op2);
5118 FreeExpContents(exp);
5119 op1.ops.Mul(exp, op1, op2);
5128 FreeExpContents(exp);
5129 op1.ops.Add(exp, op1, op2);
5134 // Provide default unary +
5135 Expression exp2 = exp.op.exp2;
5137 FreeExpContents(exp);
5138 FreeType(exp.expType);
5139 FreeType(exp.destType);
5150 FreeExpContents(exp);
5151 op1.ops.Sub(exp, op1, op2);
5158 FreeExpContents(exp);
5159 op1.ops.Neg(exp, op1);
5166 FreeExpContents(exp);
5167 op1.ops.BitNot(exp, op1);
5173 FreeExpContents(exp);
5174 op1.ops.Not(exp, op1);
5177 // Binary only operators
5181 FreeExpContents(exp);
5182 op1.ops.Div(exp, op1, op2);
5188 FreeExpContents(exp);
5189 op1.ops.Mod(exp, op1, op2);
5201 FreeExpContents(exp);
5202 op1.ops.Sma(exp, op1, op2);
5211 FreeExpContents(exp);
5212 op1.ops.Grt(exp, op1, op2);
5221 FreeExpContents(exp);
5222 op1.ops.SmaEqu(exp, op1, op2);
5231 FreeExpContents(exp);
5232 op1.ops.GrtEqu(exp, op1, op2);
5241 FreeExpContents(exp);
5242 op1.ops.Equ(exp, op1, op2);
5251 FreeExpContents(exp);
5252 op1.ops.Nqu(exp, op1, op2);
5259 FreeExpContents(exp);
5260 op1.ops.BitOr(exp, op1, op2);
5266 FreeExpContents(exp);
5267 op1.ops.BitXor(exp, op1, op2);
5275 FreeExpContents(exp);
5276 exp.type = constantExp;
5277 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5281 if(op1.type) FreeType(op1.type);
5282 if(op2.type) FreeType(op2.type);
5286 case extensionExpressionExp:
5289 for(e = exp.list->first; e; e = n)
5294 OldList * list = exp.list;
5295 ComputeExpression(e);
5296 //FreeExpContents(exp);
5297 FreeType(exp.expType);
5298 FreeType(exp.destType);
5315 exp.isConstant = true;
5317 ComputeExpression(exp.index.exp);
5318 if(!exp.index.exp.isConstant)
5319 exp.isConstant = false;
5321 for(e = exp.index.index->first; e; e = e.next)
5323 ComputeExpression(e);
5326 // Check if this type is int
5329 exp.isConstant = false;
5331 exp.expType = Dereference(exp.index.exp.expType);
5337 Expression memberExp = exp.member.exp;
5338 Identifier memberID = exp.member.member;
5341 ComputeExpression(exp.member.exp);
5342 type = exp.member.exp.expType;
5345 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);
5346 Property prop = null;
5347 DataMember member = null;
5348 Class convertTo = null;
5349 if(type.kind == subClassType && exp.member.exp.type == classExp)
5350 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5357 PrintType(type, string, false, true);
5358 classSym = FindClass(string);
5359 _class = classSym ? classSym.registered : null;
5362 if(exp.member.member)
5364 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5366 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5368 if(!prop && !member && _class && exp.member.member)
5370 Symbol classSym = FindClass(exp.member.member.string);
5372 _class = classSym ? classSym.registered : null;
5373 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5380 Type type = prop.dataType;
5381 // TODO: Assuming same base type for units...
5382 if(_class.type == unitClass)
5384 if(type.kind == classType)
5386 Class _class = type._class.registered;
5387 if(_class.type == unitClass)
5389 if(!_class.dataType)
5390 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5391 type = _class.dataType;
5399 float (*Get)(float) = (void *)prop.Get;
5400 GetFloat(exp.member.exp, &value);
5401 exp.constant = PrintFloat(Get ? Get(value) : value);
5402 exp.type = constantExp;
5408 double (*Get)(double);
5409 GetDouble(exp.member.exp, &value);
5412 Get = (void *)prop.Set;
5414 Get = (void *)prop.Get;
5415 exp.constant = PrintDouble(Get ? Get(value) : value);
5416 exp.type = constantExp;
5425 Expression value = exp.member.exp;
5428 ProcessPropertyType(prop);
5430 type = prop.dataType;
5433 // printf("Investigate this\n");
5435 else if(_class.type == structClass)
5441 Class propertyClass = type._class.registered;
5442 if(propertyClass.type == structClass && value.type == instanceExp)
5444 void (*Set)(void *, void *) = (void *)prop.Set;
5445 exp.instance = Instantiation { };
5446 exp.instance.data = new0 byte[_class.structSize];
5447 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5448 exp.instance.loc = exp.loc;
5449 exp.type = instanceExp;
5450 Set(exp.instance.data, value.instance.data);
5451 PopulateInstance(exp.instance);
5458 void (*Set)(void *, int) = (void *)prop.Set;
5460 exp.instance = Instantiation { };
5461 exp.instance.data = new0 byte[_class.structSize];
5462 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5463 exp.instance.loc = exp.loc;
5464 exp.type = instanceExp;
5466 GetInt(value, &intValue);
5468 Set(exp.instance.data, intValue);
5469 PopulateInstance(exp.instance);
5475 void (*Set)(void *, int64) = (void *)prop.Set;
5477 exp.instance = Instantiation { };
5478 exp.instance.data = new0 byte[_class.structSize];
5479 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5480 exp.instance.loc = exp.loc;
5481 exp.type = instanceExp;
5483 GetInt64(value, &intValue);
5485 Set(exp.instance.data, intValue);
5486 PopulateInstance(exp.instance);
5493 void (*Set)(void *, intptr) = (void *)prop.Set;
5495 exp.instance = Instantiation { };
5496 exp.instance.data = new0 byte[_class.structSize];
5497 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5498 exp.instance.loc = exp.loc;
5499 exp.type = instanceExp;
5501 GetIntPtr(value, &intValue);
5503 Set(exp.instance.data, intValue);
5504 PopulateInstance(exp.instance);
5511 void (*Set)(void *, intsize) = (void *)prop.Set;
5513 exp.instance = Instantiation { };
5514 exp.instance.data = new0 byte[_class.structSize];
5515 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5516 exp.instance.loc = exp.loc;
5517 exp.type = instanceExp;
5519 GetIntSize(value, &intValue);
5521 Set(exp.instance.data, intValue);
5522 PopulateInstance(exp.instance);
5528 void (*Set)(void *, double) = (void *)prop.Set;
5530 exp.instance = Instantiation { };
5531 exp.instance.data = new0 byte[_class.structSize];
5532 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5533 exp.instance.loc = exp.loc;
5534 exp.type = instanceExp;
5536 GetDouble(value, &doubleValue);
5538 Set(exp.instance.data, doubleValue);
5539 PopulateInstance(exp.instance);
5544 else if(_class.type == bitClass)
5550 Class propertyClass = type._class.registered;
5551 if(propertyClass.type == structClass && value.instance.data)
5553 unsigned int (*Set)(void *) = (void *)prop.Set;
5554 unsigned int bits = Set(value.instance.data);
5555 exp.constant = PrintHexUInt(bits);
5556 exp.type = constantExp;
5559 else if(_class.type == bitClass)
5562 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5565 GetUInt(exp.member.exp, &value);
5567 exp.constant = PrintHexUInt(bits);
5568 exp.type = constantExp;
5576 if(_class.type == bitClass)
5579 GetUInt(exp.member.exp, &value);
5585 Class _class = type._class.registered;
5586 if(_class.type == structClass)
5588 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5590 exp.instance = Instantiation { };
5591 exp.instance.data = new0 byte[_class.structSize];
5592 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5593 exp.instance.loc = exp.loc;
5594 //exp.instance.fullSet = true;
5595 exp.type = instanceExp;
5596 Get(value, exp.instance.data);
5597 PopulateInstance(exp.instance);
5599 else if(_class.type == bitClass)
5601 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5602 uint64 bits = Get(value);
5603 exp.constant = PrintHexUInt64(bits);
5604 exp.type = constantExp;
5610 else if(_class.type == structClass)
5612 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5617 Class _class = type._class.registered;
5618 if(_class.type == structClass && value)
5620 void (*Get)(void *, void *) = (void *)prop.Get;
5622 exp.instance = Instantiation { };
5623 exp.instance.data = new0 byte[_class.structSize];
5624 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5625 exp.instance.loc = exp.loc;
5626 //exp.instance.fullSet = true;
5627 exp.type = instanceExp;
5628 Get(value, exp.instance.data);
5629 PopulateInstance(exp.instance);
5637 char * value = exp.member.exp.instance.data;
5642 Class _class = type._class.registered;
5643 if(_class.type == normalClass)
5645 void *(*Get)(void *) = (void *)prop.Get;
5647 exp.instance = Instantiation { };
5648 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5649 exp.type = instanceExp;
5650 exp.instance.data = Get(value, exp.instance.data);
5662 exp.isConstant = false;
5670 if(exp.type != ExpressionType::memberExp)
5672 FreeExpression(memberExp);
5673 FreeIdentifier(memberID);
5679 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5680 FreeExpContents(exp);
5681 exp.constant = PrintUInt(ComputeTypeSize(type));
5682 exp.type = constantExp;
5688 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5689 if(classSym && classSym.registered)
5691 if(classSym.registered.fixed)
5693 FreeSpecifier(exp._class);
5694 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5695 exp.type = constantExp;
5699 char className[1024];
5700 strcpy(className, "__ecereClass_");
5701 FullClassNameCat(className, classSym.string, true);
5702 MangleClassName(className);
5704 FreeExpContents(exp);
5705 exp.type = pointerExp;
5706 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5707 exp.member.member = MkIdentifier("structSize");
5717 if(exp.type == castExp)
5720 ComputeExpression(exp.cast.exp);
5723 if(e && exp.expType)
5726 type = exp.destType;
5729 if(type.kind == classType)
5731 Class _class = type._class.registered;
5732 if(_class && (_class.type == unitClass || _class.type == bitClass))
5734 if(!_class.dataType)
5735 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5736 type = _class.dataType;
5747 FreeExpContents(exp);
5748 exp.constant = PrintChar(value);
5749 exp.type = constantExp;
5753 unsigned char value;
5754 GetUChar(e, &value);
5755 FreeExpContents(exp);
5756 exp.constant = PrintUChar(value);
5757 exp.type = constantExp;
5764 GetShort(e, &value);
5765 FreeExpContents(exp);
5766 exp.constant = PrintShort(value);
5767 exp.type = constantExp;
5771 unsigned short value;
5772 GetUShort(e, &value);
5773 FreeExpContents(exp);
5774 exp.constant = PrintUShort(value);
5775 exp.type = constantExp;
5783 FreeExpContents(exp);
5784 exp.constant = PrintInt(value);
5785 exp.type = constantExp;
5791 FreeExpContents(exp);
5792 exp.constant = PrintUInt(value);
5793 exp.type = constantExp;
5800 GetInt64(e, &value);
5801 FreeExpContents(exp);
5802 exp.constant = PrintInt64(value);
5803 exp.type = constantExp;
5808 GetUInt64(e, &value);
5809 FreeExpContents(exp);
5810 exp.constant = PrintUInt64(value);
5811 exp.type = constantExp;
5818 GetIntPtr(e, &value);
5819 FreeExpContents(exp);
5820 exp.constant = PrintInt64((int64)value);
5821 exp.type = constantExp;
5826 GetUIntPtr(e, &value);
5827 FreeExpContents(exp);
5828 exp.constant = PrintUInt64((uint64)value);
5829 exp.type = constantExp;
5836 GetIntSize(e, &value);
5837 FreeExpContents(exp);
5838 exp.constant = PrintInt64((int64)value);
5839 exp.type = constantExp;
5844 GetUIntSize(e, &value);
5845 FreeExpContents(exp);
5846 exp.constant = PrintUInt64((uint64)value);
5847 exp.type = constantExp;
5853 GetFloat(e, &value);
5854 FreeExpContents(exp);
5855 exp.constant = PrintFloat(value);
5856 exp.type = constantExp;
5862 GetDouble(e, &value);
5863 FreeExpContents(exp);
5864 exp.constant = PrintDouble(value);
5865 exp.type = constantExp;
5879 // Caring only about last expression for now...
5880 ComputeExpression(exp.cond.exp->last);
5881 if(exp.cond.elseExp)
5882 ComputeExpression(exp.cond.elseExp);
5884 ComputeExpression(exp.cond.cond);
5886 op1 = GetOperand(exp.cond.cond);
5887 if(op1.type) op1.type.refCount++;
5888 op2 = GetOperand(exp.cond.exp->last);
5889 if(op2.type) op2.type.refCount++;
5890 op3 = GetOperand(exp.cond.elseExp);
5891 if(op3.type) op3.type.refCount++;
5893 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
5894 if(op1.type) FreeType(op1.type);
5895 if(op2.type) FreeType(op2.type);
5896 if(op3.type) FreeType(op3.type);
5902 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
5907 OldList converts { };
5910 if(destType.kind == voidType)
5913 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
5917 // for(convert = converts.last; convert; convert = convert.prev)
5918 for(convert = converts.first; convert; convert = convert.next)
5920 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
5923 Expression newExp { };
5924 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
5926 // TODO: Check this...
5928 newExp.destType = null;
5933 exp.type = memberExp;
5934 exp.addedThis = true;
5935 exp.member.exp = newExp;
5936 FreeType(exp.member.exp.expType);
5938 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
5939 exp.member.exp.expType.classObjectType = objectType;
5940 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
5941 exp.member.memberType = propertyMember;
5942 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
5943 // TESTING THIS... for (int)degrees
5944 exp.needCast = true;
5945 if(exp.expType) exp.expType.refCount++;
5946 ApplyAnyObjectLogic(exp.member.exp);
5951 /*if(exp.isConstant)
5953 // Color { ColorRGB = [exp] };
5954 exp.type = instanceExp;
5955 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
5956 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
5957 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
5961 // If not constant, don't turn it yet into an instantiation
5962 // (Go through the deep members system first)
5963 exp.type = memberExp;
5964 exp.addedThis = true;
5965 exp.member.exp = newExp;
5967 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
5968 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
5969 newExp.expType._class.registered.type == noHeadClass)
5971 newExp.byReference = true;
5974 FreeType(exp.member.exp.expType);
5975 /*exp.member.exp.expType = convert.convert.dataType;
5976 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
5977 exp.member.exp.expType = null;
5978 if(convert.convert.dataType)
5980 exp.member.exp.expType = { };
5981 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
5982 exp.member.exp.expType.refCount = 1;
5983 exp.member.exp.expType.classObjectType = objectType;
5984 ApplyAnyObjectLogic(exp.member.exp);
5987 exp.member.member = MkIdentifier(convert.convert._class.fullName);
5988 exp.member.memberType = reverseConversionMember;
5989 exp.expType = convert.resultType ? convert.resultType :
5990 MkClassType(convert.convert._class.fullName);
5991 exp.needCast = true;
5992 if(convert.resultType) convert.resultType.refCount++;
5998 FreeType(exp.expType);
6001 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6002 exp.needCast = true;
6003 if(exp.expType) exp.expType.refCount++;
6007 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6008 exp.needCast = true;
6009 if(convert.resultType)
6010 convert.resultType.refCount++;
6014 if(exp.isConstant && inCompiler)
6015 ComputeExpression(exp);
6017 converts.Free(FreeConvert);
6020 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6022 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6024 if(!result && exp.expType && exp.destType)
6026 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6027 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6028 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6029 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6033 // if(result) CheckTemplateTypes(exp);
6037 void CheckTemplateTypes(Expression exp)
6039 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6041 Expression newExp { };
6045 if(exp.destType) exp.destType.refCount++;
6046 if(exp.expType) exp.expType.refCount++;
6050 switch(exp.expType.kind)
6053 if(exp.destType.classObjectType)
6055 // We need to pass the address, just pass it along (Undo what was done above)
6056 if(exp.destType) exp.destType.refCount--;
6057 if(exp.expType) exp.expType.refCount--;
6062 // If we're looking for value:
6063 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6065 OldList * unionDefs = MkList();
6066 OldList * statements = MkList();
6067 context = PushContext();
6068 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6069 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6070 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6071 exp.type = extensionCompoundExp;
6072 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6073 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6074 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6075 exp.compound.compound.context = context;
6076 PopContext(context);
6081 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6082 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6086 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6088 Expression newExp { };
6092 if(exp.destType) exp.destType.refCount++;
6093 if(exp.expType) exp.expType.refCount++;
6097 switch(exp.expType.kind)
6100 if(exp.destType.classObjectType)
6102 // We need to pass the address, just pass it along (Undo what was done above)
6103 if(exp.destType) exp.destType.refCount--;
6104 if(exp.expType) exp.expType.refCount--;
6109 // If we're looking for value:
6110 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6112 OldList * unionDefs = MkList();
6113 OldList * statements = MkList();
6114 context = PushContext();
6115 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6116 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6117 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6118 exp.type = extensionCompoundExp;
6119 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6120 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6121 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6122 exp.compound.compound.context = context;
6123 PopContext(context);
6128 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6130 exp.type = bracketsExp;
6131 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6132 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6133 ProcessExpressionType(exp.list->first);
6138 exp.type = bracketsExp;
6139 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6140 newExp.needCast = true;
6141 ProcessExpressionType(exp.list->first);
6147 if(exp.expType.kind == templateType)
6149 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6152 FreeType(exp.destType);
6153 FreeType(exp.expType);
6158 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6163 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6164 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6168 char typeString[1024];
6170 OldList * specs = MkList();
6171 typeString[0] = '\0';
6172 PrintType(exp.expType, typeString, false, false);
6173 decl = SpecDeclFromString(typeString, specs, null);
6176 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6177 exp.cast.typeName = MkTypeName(specs, decl);
6178 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6179 exp.cast.exp.needCast = true;
6186 // TODO: The Symbol tree should be reorganized by namespaces
6188 // - Tree of all symbols within (stored without namespace)
6189 // - Tree of sub-namespaces
6191 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6193 int nsLen = strlen(nameSpace);
6195 // Start at the name space prefix
6196 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6198 char * s = symbol.string;
6199 if(!strncmp(s, nameSpace, nsLen))
6201 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6204 for(c = strlen(s)-1; c >= 0; c--)
6209 if(!strcmp(namePart, name))
6211 // TODO: Error on ambiguity
6221 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6224 char nameSpace[1024];
6226 bool gotColon = false;
6228 nameSpace[0] = '\0';
6229 for(c = strlen(name)-1; c >= 0; c--)
6236 namePart = name+c+1;
6237 while(c >= 0 && name[c] == ':') c--;
6240 // Try an exact match first
6241 Symbol symbol = (Symbol)tree.FindString(name);
6245 // Namespace specified
6246 memcpy(nameSpace, name, c + 1);
6249 return ScanWithNameSpace(tree, nameSpace, namePart);
6253 // Looking for a global symbol, e.g. ::Sleep()
6254 Symbol symbol = (Symbol)tree.FindString(namePart);
6259 // Name only (no namespace specified)
6260 Symbol symbol = (Symbol)tree.FindString(namePart);
6263 return ScanWithNameSpace(tree, "", namePart);
6268 static void ProcessDeclaration(Declaration decl);
6270 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6273 //Time startTime = GetTime();
6275 // Optimize this later? Do this before/less?
6277 Symbol symbol = null;
6278 // First, check if the identifier is declared inside the function
6279 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6281 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6283 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6289 strcpy(curName, thisNameSpace);
6290 strcat(curName, "::");
6291 strcat(curName, name);
6292 // Try to resolve in current namespace first
6293 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6296 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6299 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6301 if(symbol || ctx == endContext) break;
6303 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6305 if(symbol.pointerExternal.type == functionExternal)
6307 FunctionDefinition function = symbol.pointerExternal.function;
6309 // Modified this recently...
6310 Context tmpContext = curContext;
6312 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6313 curContext = tmpContext;
6315 symbol.pointerExternal.symbol = symbol;
6318 DeclareType(symbol.type, true, true);
6320 ast->Insert(curExternal.prev, symbol.pointerExternal);
6322 symbol.id = curExternal.symbol.idCode;
6325 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6327 ast->Move(symbol.pointerExternal, curExternal.prev);
6328 symbol.id = curExternal.symbol.idCode;
6332 //findSymbolTotalTime += GetTime() - startTime;
6337 static void GetTypeSpecs(Type type, OldList * specs)
6339 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6344 if(type._class.registered)
6346 if(!type._class.registered.dataType)
6347 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6348 GetTypeSpecs(type._class.registered.dataType, specs);
6352 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6353 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6354 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6355 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6356 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6357 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6358 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6361 ListAdd(specs, MkSpecifier(INT)); break;
6365 // WARNING : This function expects a null terminated string since it recursively concatenate...
6366 static void _PrintType(Type type, char * string, bool printName, bool printFunction, bool fullName)
6373 if(type._class && type._class.string)
6375 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6376 // look into merging with thisclass ?
6377 if(type.classObjectType == typedObject)
6378 strcat(string, "typed_object");
6380 strcat(string, type._class.string);
6383 if(type._class.registered)
6384 strcat(string, type._class.registered.name);
6386 strcat(string, type._class.string);
6393 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6394 if(funcType && funcType.kind == functionType)
6397 PrintType(funcType.returnType, string, false, fullName);
6398 strcat(string, "(*");
6399 if(printName || funcType.thisClass)
6401 strcat(string, " ");
6402 if(funcType.thisClass)
6404 strcat(string, funcType.thisClass.string);
6405 strcat(string, "::");
6408 strcat(string, type.name);
6410 strcat(string, ")(");
6411 for(param = funcType.params.first; param; param = param.next)
6413 PrintType(param, string, false, fullName);
6414 if(param.next) strcat(string, ", ");
6416 strcat(string, ")");
6420 _PrintType(type.type, string, false /*printName*/, printFunction, fullName);
6421 strcat(string, " *");
6425 case voidType: strcat(string, "void"); break;
6426 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6427 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6428 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6429 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6430 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6431 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6432 case floatType: strcat(string, "float"); break;
6433 case doubleType: strcat(string, "double"); break;
6437 strcat(string, "struct ");
6438 strcat(string, type.enumName);
6440 else if(type.typeName)
6442 strcat(string, type.typeName);
6447 strcat(string, "struct ");
6448 strcat(string,"(unnamed)");
6451 strcat(string, "struct {");
6452 for(member = type.members.first; member; member = member.next)
6454 PrintType(member, string, true, fullName);
6455 strcat(string,"; ");
6463 strcat(string, "union ");
6464 strcat(string, type.enumName);
6466 else if(type.typeName)
6468 strcat(string, type.typeName);
6472 strcat(string, "union ");
6473 strcat(string,"(unnamed)");
6479 strcat(string, "enum ");
6480 strcat(string, type.enumName);
6482 else if(type.typeName)
6484 strcat(string, type.typeName);
6487 strcat(string, "enum");
6494 strcat(string, "dllexport ");
6495 PrintType(type.returnType, string, false, fullName);
6496 strcat(string, " ");
6499 // DANGER: Testing This
6505 strcat(string, type.name);
6508 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6509 if(name) name += 2; else name = type.name;
6510 strcat(string, name);
6518 strcat(string, "(");
6519 for(param = type.params.first; param; param = param.next)
6521 PrintType(param, string, true, fullName);
6522 if(param.next) strcat(string, ", ");
6524 strcat(string, ")");
6531 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6532 if(funcType && funcType.kind == functionType)
6535 PrintType(funcType.returnType, string, false, fullName);
6536 strcat(string, "(*");
6537 if(printName || funcType.thisClass)
6539 strcat(string, " ");
6540 if(funcType.thisClass)
6542 strcat(string, funcType.thisClass.string);
6543 strcat(string, "::");
6546 strcat(string, type.name);
6548 strcat(string, ")(");
6549 for(param = funcType.params.first; param; param = param.next)
6551 PrintType(param, string, false, fullName);
6552 if(param.next) strcat(string, ", ");
6554 strcat(string, ")");
6558 char baseType[1024], size[256];
6559 Type arrayType = type;
6563 while(arrayType.kind == TypeKind::arrayType)
6566 if(arrayType.enumClass)
6567 strcat(size, arrayType.enumClass.string);
6568 else if(arrayType.arraySizeExp)
6569 PrintExpression(arrayType.arraySizeExp, size);
6570 //sprintf(string, "%s[%s]", baseType, size);
6573 arrayType = arrayType.arrayType;
6575 _PrintType(arrayType, baseType, printName, printFunction, fullName);
6576 strcat(string, baseType);
6577 strcat(string, size);
6581 PrintType(type.arrayType, baseType, printName, fullName);
6583 strcpy(size, type.enumClass.string);
6584 else if(type.arraySizeExp)
6585 PrintExpression(type.arraySizeExp, size);
6586 //sprintf(string, "%s[%s]", baseType, size);
6587 strcat(string, baseType);
6588 strcat(string, "[");
6589 strcat(string, size);
6590 strcat(string, "]");
6597 strcat(string, "...");
6600 _PrintType(type.method.dataType, string, false, printFunction, fullName);
6603 strcat(string, "subclass(");
6604 strcat(string, type._class ? type._class.string : "int");
6605 strcat(string, ")");
6608 strcat(string, type.templateParameter.identifier.string);
6611 strcat(string, "thisclass");
6614 strcat(string, "__builtin_va_list");
6617 if(type.name && printName && type.kind != functionType && (type.kind != pointerType || type.type.kind != functionType))
6619 strcat(string, " ");
6620 strcat(string, type.name);
6626 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6628 void PrintType(Type type, char * string, bool printName, bool fullName)
6631 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6632 if(funcType && funcType.kind == functionType && type != funcType)
6634 char typeString[1024];
6637 PrintType(funcType.returnType, string, false, fullName);
6638 strcat(string, "(");
6639 _PrintType(type, string, printName, false, fullName);
6640 strcat(string, ")");
6642 strcat(string, "(");
6643 for(param = funcType.params.first; param; param = param.next)
6645 PrintType(param, string, true, fullName);
6646 if(param.next) strcat(string, ", ");
6648 strcat(string, ")");
6651 _PrintType(type, string, printName, true, fullName);
6652 if(type.bitFieldCount)
6655 sprintf(count, ":%d", type.bitFieldCount);
6656 strcat(string, count);
6660 static Type FindMember(Type type, char * string)
6663 for(memberType = type.members.first; memberType; memberType = memberType.next)
6665 if(!memberType.name)
6667 Type subType = FindMember(memberType, string);
6671 else if(!strcmp(memberType.name, string))
6677 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6680 for(memberType = type.members.first; memberType; memberType = memberType.next)
6682 if(!memberType.name)
6684 Type subType = FindMember(memberType, string);
6687 *offset += memberType.offset;
6691 else if(!strcmp(memberType.name, string))
6693 *offset += memberType.offset;
6700 Expression ParseExpressionString(char * expression)
6702 fileInput = TempFile { };
6703 fileInput.Write(expression, 1, strlen(expression));
6704 fileInput.Seek(0, start);
6707 parsedExpression = null;
6709 expression_yyparse();
6712 return parsedExpression;
6715 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6717 Identifier id = exp.identifier;
6718 Method method = null;
6719 Property prop = null;
6720 DataMember member = null;
6721 ClassProperty classProp = null;
6723 if(_class && _class.type == enumClass)
6725 NamedLink value = null;
6726 Class enumClass = eSystem_FindClass(privateModule, "enum");
6730 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6732 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6733 for(value = e.values.first; value; value = value.next)
6735 if(!strcmp(value.name, id.string))
6742 FreeExpContents(exp);
6744 exp.type = constantExp;
6745 exp.isConstant = true;
6746 if(!strcmp(baseClass.dataTypeString, "int"))
6747 sprintf(constant, "%d",value.data);
6749 sprintf(constant, "0x%X",value.data);
6750 exp.constant = CopyString(constant);
6751 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6752 exp.expType = MkClassType(baseClass.fullName);
6760 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6762 ProcessMethodType(method);
6769 // TOCHECK: Put it back to what it was...
6770 // methodClass = _class;
6771 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6776 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
6779 ProcessPropertyType(prop);
6780 exp.expType = prop.dataType;
6781 if(prop.dataType) prop.dataType.refCount++;
6784 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
6786 if(!member.dataType)
6787 member.dataType = ProcessTypeString(member.dataTypeString, false);
6788 exp.expType = member.dataType;
6789 if(member.dataType) member.dataType.refCount++;
6792 else if((classProp = eClass_FindClassProperty(_class, id.string)))
6794 if(!classProp.dataType)
6795 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
6797 if(classProp.constant)
6799 FreeExpContents(exp);
6801 exp.isConstant = true;
6802 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
6804 //char constant[256];
6805 exp.type = stringExp;
6806 exp.constant = QMkString((char *)classProp.Get(_class));
6811 exp.type = constantExp;
6812 sprintf(constant, "%d", (int)classProp.Get(_class));
6813 exp.constant = CopyString(constant);
6821 exp.expType = classProp.dataType;
6822 if(classProp.dataType) classProp.dataType.refCount++;
6828 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
6830 BinaryTree * tree = &nameSpace.functions;
6831 GlobalData data = (GlobalData)tree->FindString(name);
6835 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
6837 data = ScanGlobalData(child, name);
6845 static GlobalData FindGlobalData(char * name)
6848 NameSpace * nameSpace;
6849 nameSpace = globalData;
6850 for(c = 0; name[c]; c++)
6852 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
6854 NameSpace * newSpace;
6855 char * spaceName = new char[c - start + 1];
6856 strncpy(spaceName, name + start, c - start);
6857 spaceName[c-start] = '\0';
6858 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
6862 nameSpace = newSpace;
6863 if(name[c] == ':') c++;
6869 return ScanGlobalData(nameSpace, name + start);
6874 static int definedExpStackPos;
6875 static void * definedExpStack[512];
6877 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
6878 void ReplaceExpContents(Expression checkedExp, Expression newExp)
6880 Expression prev = checkedExp.prev, next = checkedExp.next;
6882 FreeExpContents(checkedExp);
6883 FreeType(checkedExp.expType);
6884 FreeType(checkedExp.destType);
6886 *checkedExp = *newExp;
6890 checkedExp.prev = prev;
6891 checkedExp.next = next;
6894 void ApplyAnyObjectLogic(Expression e)
6896 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
6897 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
6899 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
6900 //ellipsisDestType = destType;
6903 Type type = e.expType;
6904 Class _class = null;
6905 //Type destType = e.destType;
6907 if(type.kind == classType && type._class && type._class.registered)
6909 _class = type._class.registered;
6911 else if(type.kind == subClassType)
6913 _class = FindClass("ecere::com::Class").registered;
6917 char string[1024] = "";
6920 PrintType(type, string, false, true);
6921 classSym = FindClass(string);
6922 if(classSym) _class = classSym.registered;
6925 if((_class && (_class.type == enumClass || _class.type == unitClass || _class.type == bitClass || _class.type == systemClass) && strcmp(_class.fullName, "class") && strcmp(_class.fullName, "ecere::com::Class")) || // Patched so that class isn't considered SYSTEM...
6926 (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
6927 destType.byReference)))
6929 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
6931 Expression checkedExp = e, newExp;
6933 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6935 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6937 if(checkedExp.type == extensionCompoundExp)
6939 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6942 checkedExp = checkedExp.list->last;
6944 else if(checkedExp.type == castExp)
6945 checkedExp = checkedExp.cast.exp;
6948 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
6950 newExp = checkedExp.op.exp2;
6951 checkedExp.op.exp2 = null;
6952 FreeExpContents(checkedExp);
6954 if(e.expType && e.expType.passAsTemplate)
6957 ComputeTypeSize(e.expType);
6958 sprintf(size, "%d", e.expType.size);
6959 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
6960 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
6961 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
6964 ReplaceExpContents(checkedExp, newExp);
6965 e.byReference = true;
6967 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
6969 Expression checkedExp, newExp;
6972 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
6974 e.type == identifierExp ||
6975 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
6976 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
6977 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
6980 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
6982 Context context = PushContext();
6984 OldList * specs = MkList();
6985 char typeString[1024];
6986 Expression newExp { };
6988 typeString[0] = '\0';
6991 //if(e.destType) e.destType.refCount++;
6992 // if(exp.expType) exp.expType.refCount++;
6995 newExp.expType = null;
6997 PrintType(e.expType, typeString, false, true);
6998 decl = SpecDeclFromString(typeString, specs, null);
6999 newExp.destType = ProcessType(specs, decl);
7001 curContext = context;
7002 e.type = extensionCompoundExp;
7004 // We need a current compound for this
7008 OldList * stmts = MkList();
7009 sprintf(name, "__internalValue%03X", internalValueCounter++);
7010 if(!curCompound.compound.declarations)
7011 curCompound.compound.declarations = MkList();
7012 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7013 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7014 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7015 e.compound = MkCompoundStmt(null, stmts);
7018 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7021 e.compound = MkCompoundStmt(
7022 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7023 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7025 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7029 Type type = e.destType;
7031 CopyTypeInto(e.destType, type);
7032 e.destType.refCount = 1;
7033 e.destType.classObjectType = none;
7037 e.compound.compound.context = context;
7038 PopContext(context);
7039 curContext = context.parent;
7043 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7045 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7047 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7049 if(checkedExp.type == extensionCompoundExp)
7051 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7054 checkedExp = checkedExp.list->last;
7056 else if(checkedExp.type == castExp)
7057 checkedExp = checkedExp.cast.exp;
7060 Expression operand { };
7061 operand = *checkedExp;
7062 checkedExp.destType = null;
7063 checkedExp.expType = null;
7065 checkedExp.type = opExp;
7066 checkedExp.op.op = '&';
7067 checkedExp.op.exp1 = null;
7068 checkedExp.op.exp2 = operand;
7070 //newExp = MkExpOp(null, '&', checkedExp);
7072 //ReplaceExpContents(checkedExp, newExp);
7079 // If expression type is a simple class, make it an address
7080 // FixReference(e, true);
7083 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7084 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7085 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7087 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
7089 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7093 Expression thisExp { };
7096 thisExp.prev = null;
7097 thisExp.next = null;
7100 e.type = bracketsExp;
7101 e.list = MkListOne(MkExpOp(null, '*', MkExpBrackets(MkListOne(thisExp))));
7102 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7103 ((Expression)e.list->first).byReference = true;
7105 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7107 e.expType = thisExp.expType;
7108 e.expType.refCount++;
7113 CopyTypeInto(e.expType, thisExp.expType);
7114 e.expType.byReference = false;
7115 e.expType.refCount = 1;
7117 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7118 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7120 e.expType.classObjectType = none;
7125 // TOFIX: Try this for a nice IDE crash!
7127 // The other way around
7130 if(destType && e.expType &&
7131 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7132 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7133 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7135 if(destType.kind == ellipsisType)
7137 Compiler_Error($"Unspecified type\n");
7139 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7141 bool byReference = e.expType.byReference;
7142 Expression thisExp { };
7144 OldList * specs = MkList();
7145 char typeString[1024]; // Watch buffer overruns
7147 ClassObjectType backupClassObjectType;
7149 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7154 backupClassObjectType = type.classObjectType;
7156 type.classObjectType = none;
7158 typeString[0] = '\0';
7159 PrintType(type, typeString, false, true);
7160 decl = SpecDeclFromString(typeString, specs, null);
7162 type.classObjectType = backupClassObjectType;
7165 thisExp.prev = null;
7166 thisExp.next = null;
7169 if( ( type.kind == classType && type._class && type._class.registered && strcmp(type._class.registered.fullName, "ecere::com::Instance") &&
7170 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7171 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7172 (type.kind != pointerType && type.kind != arrayType && type.kind != classType) ||
7173 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7178 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7183 e.cast.typeName = MkTypeName(specs, decl);
7184 e.cast.exp = thisExp;
7185 e.byReference = true;
7188 e.destType = destType;
7190 destType.refCount++;
7195 void ProcessExpressionType(Expression exp)
7197 bool unresolved = false;
7198 Location oldyylloc = yylloc;
7199 bool notByReference = false;
7201 char debugExpString[4096];
7202 debugExpString[0] = '\0';
7203 PrintExpression(exp, debugExpString);
7205 if(!exp || exp.expType)
7208 //eSystem_Logf("%s\n", expString);
7210 // Testing this here
7216 Identifier id = exp.identifier;
7219 // DOING THIS LATER NOW...
7220 if(id._class && id._class.name)
7222 id.classSym = id._class.symbol; // FindClass(id._class.name);
7223 /* TODO: Name Space Fix ups
7225 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7229 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7231 exp.expType = ProcessTypeString("Module", true);
7234 else */if(strstr(id.string, "__ecereClass") == id.string)
7236 exp.expType = ProcessTypeString("ecere::com::Class", true);
7239 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7241 // Added this here as well
7242 ReplaceClassMembers(exp, thisClass);
7243 if(exp.type != identifierExp)
7245 ProcessExpressionType(exp);
7249 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7254 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7255 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7256 if(!symbol/* && exp.destType*/)
7258 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7264 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7265 if(exp.type != identifierExp)
7267 ProcessExpressionType(exp);
7271 // Static methods called from inside the _class
7272 else if(currentClass && !id._class)
7274 if(ResolveIdWithClass(exp, currentClass, true))
7277 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7281 // If we manage to resolve this symbol
7284 Type type = symbol.type;
7285 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7287 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7289 Context context = SetupTemplatesContext(_class);
7290 type = ReplaceThisClassType(_class);
7291 FinishTemplatesContext(context);
7292 if(type) type.refCount = 0; // We'll be incrementing it right below...
7295 FreeSpecifier(id._class);
7298 id.string = CopyString(symbol.string);
7304 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7305 // Add missing cases here... enum Classes...
7306 exp.isConstant = true;
7308 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7309 if(symbol.isParam || !strcmp(id.string, "this"))
7311 if(_class && _class.type == structClass)
7312 exp.byReference = true;
7314 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7315 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7316 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7317 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7319 Identifier id = exp.identifier;
7320 exp.type = bracketsExp;
7321 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7325 if(symbol.isIterator)
7327 if(symbol.isIterator == 3)
7329 exp.type = bracketsExp;
7330 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7331 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7333 ProcessExpressionType(exp);
7335 else if(symbol.isIterator != 4)
7337 exp.type = memberExp;
7338 exp.member.exp = MkExpIdentifier(exp.identifier);
7339 exp.member.exp.expType = exp.expType;
7340 /*if(symbol.isIterator == 6)
7341 exp.member.member = MkIdentifier("key");
7343 exp.member.member = MkIdentifier("data");
7345 ProcessExpressionType(exp);
7352 DefinedExpression definedExp = null;
7353 if(thisNameSpace && !(id._class && !id._class.name))
7356 strcpy(name, thisNameSpace);
7358 strcat(name, id.string);
7359 definedExp = eSystem_FindDefine(privateModule, name);
7362 definedExp = eSystem_FindDefine(privateModule, id.string);
7366 for(c = 0; c<definedExpStackPos; c++)
7367 if(definedExpStack[c] == definedExp)
7369 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7371 Location backupYylloc = yylloc;
7372 definedExpStack[definedExpStackPos++] = definedExp;
7373 fileInput = TempFile { };
7374 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7375 fileInput.Seek(0, start);
7378 parsedExpression = null;
7380 expression_yyparse();
7383 yylloc = backupYylloc;
7385 if(parsedExpression)
7388 exp.type = bracketsExp;
7389 exp.list = MkListOne(parsedExpression);
7390 parsedExpression.loc = yylloc;
7391 ProcessExpressionType(exp);
7392 definedExpStackPos--;
7395 definedExpStackPos--;
7401 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7407 GlobalData data = null;
7408 if(thisNameSpace && !(id._class && !id._class.name))
7411 strcpy(name, thisNameSpace);
7413 strcat(name, id.string);
7414 data = FindGlobalData(name);
7417 data = FindGlobalData(id.string);
7420 DeclareGlobalData(data);
7421 exp.expType = data.dataType;
7422 if(data.dataType) data.dataType.refCount++;
7425 id.string = CopyString(data.fullName);
7426 FreeSpecifier(id._class);
7433 GlobalFunction function = null;
7434 if(thisNameSpace && !(id._class && !id._class.name))
7437 strcpy(name, thisNameSpace);
7439 strcat(name, id.string);
7440 function = eSystem_FindFunction(privateModule, name);
7443 function = eSystem_FindFunction(privateModule, id.string);
7448 id.string = CopyString(function.name);
7451 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7452 strcpy(name, "__ecereFunction_");
7453 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7454 if(DeclareFunction(function, name))
7457 id.string = CopyString(name);
7459 exp.expType = function.dataType;
7460 if(function.dataType) function.dataType.refCount++;
7462 FreeSpecifier(id._class);
7479 if(!exp.instance._class)
7481 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7483 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7487 //classSym = FindClass(exp.instance._class.fullName);
7488 //_class = classSym ? classSym.registered : null;
7490 ProcessInstantiationType(exp.instance);
7491 exp.isConstant = exp.instance.isConstant;
7494 if(_class.type == unitClass && _class.base.type != systemClass)
7497 Type destType = exp.destType;
7499 exp.destType = MkClassType(_class.base.fullName);
7500 exp.expType = MkClassType(_class.fullName);
7501 CheckExpressionType(exp, exp.destType, true);
7503 exp.destType = destType;
7505 exp.expType = MkClassType(_class.fullName);
7508 if(exp.instance._class)
7510 exp.expType = MkClassType(exp.instance._class.name);
7511 /*if(exp.expType._class && exp.expType._class.registered &&
7512 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7513 exp.expType.byReference = true;*/
7528 if(exp.constant[0] == '\'')
7530 if((int)((byte *)exp.constant)[1] > 127)
7533 unichar ch = UTF8GetChar(exp.constant + 1, &nb);
7534 if(nb < 2) ch = exp.constant[1];
7535 delete exp.constant;
7536 exp.constant = PrintUInt(ch);
7537 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7538 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7539 type._class = FindClass("unichar");
7541 type.isSigned = false;
7545 type.kind = charType;
7546 type.isSigned = true;
7549 else if(strchr(exp.constant, '.'))
7551 char ch = exp.constant[strlen(exp.constant)-1];
7553 type.kind = floatType;
7555 type.kind = doubleType;
7556 type.isSigned = true;
7560 if(exp.constant[0] == '0' && exp.constant[1])
7561 type.isSigned = false;
7562 else if(strchr(exp.constant, 'L') || strchr(exp.constant, 'l'))
7563 type.isSigned = false;
7564 else if(strtoll(exp.constant, null, 0) > MAXINT)
7565 type.isSigned = false;
7567 type.isSigned = true;
7568 type.kind = intType;
7570 exp.isConstant = true;
7576 exp.isConstant = true; // Why wasn't this constant?
7592 ProcessExpressionType(exp._new.size);
7597 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7599 DeclareType(exp.expType.type, false, false);
7603 ProcessExpressionType(exp._renew.size);
7604 ProcessExpressionType(exp._renew.exp);
7609 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7611 DeclareType(exp.expType.type, false, false);
7615 bool assign = false, boolResult = false, boolOps = false;
7616 Type type1 = null, type2 = null;
7617 bool useDestType = false, useSideType = false;
7618 Location oldyylloc = yylloc;
7619 bool useSideUnit = false;
7621 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7630 // Assignment Operators
7644 // boolean Operators
7646 // Expect boolean operators
7648 //boolResult = true;
7652 // Expect boolean operands
7663 // Gives boolean result
7671 // Just added these... testing
7676 // DANGER: Verify units
7681 if(exp.op.op != '*' || exp.op.exp1)
7688 /*// Implement speed etc.
7694 if(exp.op.op == '&')
7696 // Added this here earlier for Iterator address as key
7697 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7699 Identifier id = exp.op.exp2.identifier;
7700 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7701 if(symbol && symbol.isIterator == 2)
7703 exp.type = memberExp;
7704 exp.member.exp = exp.op.exp2;
7705 exp.member.member = MkIdentifier("key");
7707 exp.op.exp2.expType = symbol.type;
7708 symbol.type.refCount++;
7709 ProcessExpressionType(exp);
7713 // exp.op.exp2.usage.usageRef = true;
7717 //dummy.kind = TypeDummy;
7721 if(exp.destType && exp.destType.kind == classType &&
7722 exp.destType._class && exp.destType._class.registered && useDestType &&
7724 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
7725 exp.destType._class.registered.type == enumClass ||
7726 exp.destType._class.registered.type == bitClass
7729 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
7731 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7732 exp.op.exp1.destType = exp.destType;
7734 exp.destType.refCount++;
7738 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7739 exp.op.exp1.destType = dummy;
7743 // TESTING THIS HERE...
7744 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
7745 ProcessExpressionType(exp.op.exp1);
7746 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
7748 if(exp.op.exp1.destType == dummy)
7751 exp.op.exp1.destType = null;
7753 type1 = exp.op.exp1.expType;
7758 char expString[10240];
7759 expString[0] = '\0';
7760 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
7764 exp.op.exp2.destType = exp.op.exp1.expType;
7765 if(exp.op.exp1.expType)
7766 exp.op.exp1.expType.refCount++;
7770 exp.op.exp2.destType = exp.destType;
7772 exp.destType.refCount++;
7775 if(type1) type1.refCount++;
7776 exp.expType = type1;
7781 PrintExpression(exp.op.exp2, expString);
7783 if(type1 && type1.kind == pointerType)
7785 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 ||
7786 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
7787 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
7788 else if(exp.op.op == '=')
7790 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7791 exp.op.exp2.destType = type1;
7798 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
7799 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/* ||
7800 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
7803 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7804 exp.op.exp2.destType = type1;
7809 if(type1) type1.refCount++;
7810 exp.expType = type1;
7812 else if(exp.destType && exp.destType.kind == classType &&
7813 exp.destType._class && exp.destType._class.registered &&
7815 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
7816 (exp.destType._class.registered.type == enumClass && useDestType))
7819 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7820 exp.op.exp2.destType = exp.destType;
7822 exp.destType.refCount++;
7826 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7827 exp.op.exp2.destType = dummy;
7831 // TESTING THIS HERE... (DANGEROUS)
7832 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
7833 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
7835 FreeType(exp.op.exp2.destType);
7836 exp.op.exp2.destType = type1;
7839 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
7840 ProcessExpressionType(exp.op.exp2);
7841 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
7843 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
7845 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)
7847 if(exp.op.op != '=' && type1.type.kind == voidType)
7848 Compiler_Error($"void *: unknown size\n");
7850 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||
7851 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
7852 (exp.op.exp2.expType._class.registered.type == normalClass ||
7853 exp.op.exp2.expType._class.registered.type == structClass ||
7854 exp.op.exp2.expType._class.registered.type == noHeadClass)))
7856 if(exp.op.op == ADD_ASSIGN)
7857 Compiler_Error($"cannot add two pointers\n");
7859 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
7860 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
7862 if(exp.op.op == ADD_ASSIGN)
7863 Compiler_Error($"cannot add two pointers\n");
7867 char type1String[1024];
7868 char type2String[1024];
7869 type1String[0] = '\0';
7870 type2String[0] = '\0';
7872 PrintType(exp.op.exp2.expType, type1String, false, true);
7873 PrintType(type1, type2String, false, true);
7874 ChangeCh(expString, '\n', ' ');
7875 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
7879 if(exp.op.exp2.destType == dummy)
7882 exp.op.exp2.destType = null;
7885 type2 = exp.op.exp2.expType;
7888 dummy.kind = voidType;
7890 if(exp.op.op == SIZEOF)
7897 exp.isConstant = true;
7899 // Get type of dereferenced pointer
7900 else if(exp.op.op == '*' && !exp.op.exp1)
7902 exp.expType = Dereference(type2);
7903 if(type2 && type2.kind == classType)
7904 notByReference = true;
7906 else if(exp.op.op == '&' && !exp.op.exp1)
7907 exp.expType = Reference(type2);
7914 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7915 exp.op.exp1.destType = MkClassType("bool");
7916 exp.op.exp1.destType.truth = true;
7917 if(!exp.op.exp1.expType)
7918 ProcessExpressionType(exp.op.exp1);
7920 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
7921 FreeType(exp.op.exp1.expType);
7922 exp.op.exp1.expType = MkClassType("bool");
7923 exp.op.exp1.expType.truth = true;
7927 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7928 exp.op.exp2.destType = MkClassType("bool");
7929 exp.op.exp2.destType.truth = true;
7930 if(!exp.op.exp2.expType)
7931 ProcessExpressionType(exp.op.exp2);
7933 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
7934 FreeType(exp.op.exp2.expType);
7935 exp.op.exp2.expType = MkClassType("bool");
7936 exp.op.exp2.expType.truth = true;
7939 else if(exp.op.exp1 && exp.op.exp2 &&
7942 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
7943 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
7944 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
7945 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
7947 if(type1 && type2 &&
7948 // If either both are class or both are not class
7949 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
7951 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7952 exp.op.exp2.destType = type1;
7954 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7955 exp.op.exp1.destType = type2;
7957 // Warning here for adding Radians + Degrees with no destination type
7958 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
7959 type1._class.registered && type1._class.registered.type == unitClass &&
7960 type2._class.registered && type2._class.registered.type == unitClass &&
7961 type1._class.registered != type2._class.registered)
7962 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
7963 type1._class.string, type2._class.string, type1._class.string);
7965 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
7967 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7970 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7972 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
7973 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
7976 ProcessExpressionType(exp.op.exp1);
7978 if(type2.kind != pointerType)
7980 ProcessExpressionType(classExp);
7982 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
7983 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
7984 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
7986 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
7989 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
7990 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
7991 MkPointer(null, null), null)))),
7992 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
7994 if(!exp.op.exp2.expType)
7995 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
7997 ProcessExpressionType(exp.op.exp2);
8002 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)))
8004 if(type1.kind != classType && type1.type.kind == voidType)
8005 Compiler_Error($"void *: unknown size\n");
8006 exp.expType = type1;
8007 if(type1) type1.refCount++;
8009 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)))
8011 if(type2.kind != classType && type2.type.kind == voidType)
8012 Compiler_Error($"void *: unknown size\n");
8013 exp.expType = type2;
8014 if(type2) type2.refCount++;
8016 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8017 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8019 Compiler_Warning($"different levels of indirection\n");
8023 bool success = false;
8024 if(type1.kind == pointerType && type2.kind == pointerType)
8026 if(exp.op.op == '+')
8027 Compiler_Error($"cannot add two pointers\n");
8028 else if(exp.op.op == '-')
8030 // Pointer Subtraction gives integer
8031 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8040 if(type1.type.kind == templateType)
8042 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8045 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8047 ProcessExpressionType(classExp);
8049 exp.type = bracketsExp;
8050 exp.list = MkListOne(MkExpOp(
8051 MkExpBrackets(MkListOne(MkExpOp(
8052 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8054 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8056 //MkExpMember(classExp, MkIdentifier("typeSize"))
8058 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8059 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8061 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8064 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8065 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8066 MkPointer(null, null), null)))),
8067 MkExpMember(classExp, MkIdentifier("typeSize")))))
8072 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8081 if(!success && exp.op.exp1.type == constantExp)
8083 // If first expression is constant, try to match that first
8084 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8086 if(exp.expType) FreeType(exp.expType);
8087 exp.expType = exp.op.exp1.destType;
8088 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8091 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8093 if(exp.expType) FreeType(exp.expType);
8094 exp.expType = exp.op.exp2.destType;
8095 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8101 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8103 if(exp.expType) FreeType(exp.expType);
8104 exp.expType = exp.op.exp2.destType;
8105 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8108 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8110 if(exp.expType) FreeType(exp.expType);
8111 exp.expType = exp.op.exp1.destType;
8112 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8118 char expString1[10240];
8119 char expString2[10240];
8122 expString1[0] = '\0';
8123 expString2[0] = '\0';
8128 PrintExpression(exp.op.exp1, expString1);
8129 ChangeCh(expString1, '\n', ' ');
8130 PrintExpression(exp.op.exp2, expString2);
8131 ChangeCh(expString2, '\n', ' ');
8132 PrintType(exp.op.exp1.expType, type1, false, true);
8133 PrintType(exp.op.exp2.expType, type2, false, true);
8136 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8140 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8141 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8143 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8144 // Convert e.g. / 4 into / 4.0
8145 exp.op.exp1.destType = type2._class.registered.dataType;
8146 if(type2._class.registered.dataType)
8147 type2._class.registered.dataType.refCount++;
8148 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8149 exp.expType = type2;
8150 if(type2) type2.refCount++;
8152 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8154 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8155 // Convert e.g. / 4 into / 4.0
8156 exp.op.exp2.destType = type1._class.registered.dataType;
8157 if(type1._class.registered.dataType)
8158 type1._class.registered.dataType.refCount++;
8159 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8160 exp.expType = type1;
8161 if(type1) type1.refCount++;
8167 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8169 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8171 if(!type1._class.registered.dataType)
8172 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8173 exp.op.exp2.destType = type1._class.registered.dataType;
8174 exp.op.exp2.destType.refCount++;
8176 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8177 type2 = exp.op.exp2.destType;
8179 exp.expType = type2;
8183 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8185 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8187 if(!type2._class.registered.dataType)
8188 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8189 exp.op.exp1.destType = type2._class.registered.dataType;
8190 exp.op.exp1.destType.refCount++;
8192 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8193 type1 = exp.op.exp1.destType;
8194 exp.expType = type1;
8198 // TESTING THIS NEW CODE
8199 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8201 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8203 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8205 if(exp.expType) FreeType(exp.expType);
8206 exp.expType = exp.op.exp1.expType;
8207 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8212 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8214 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8216 if(exp.expType) FreeType(exp.expType);
8217 exp.expType = exp.op.exp2.expType;
8218 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8226 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8227 exp.op.exp2.destType = type1;
8231 // Maybe this was meant to be an enum...
8232 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8234 Type oldType = exp.op.exp2.expType;
8235 exp.op.exp2.expType = null;
8236 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8239 exp.op.exp2.expType = oldType;
8244 // TESTING THIS HERE... LATEST ADDITION
8245 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8247 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8248 exp.op.exp2.destType = type2._class.registered.dataType;
8249 if(type2._class.registered.dataType)
8250 type2._class.registered.dataType.refCount++;
8251 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8253 //exp.expType = type2._class.registered.dataType; //type2;
8254 //if(type2) type2.refCount++;
8257 // TESTING THIS HERE... LATEST ADDITION
8258 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8260 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8261 exp.op.exp1.destType = type1._class.registered.dataType;
8262 if(type1._class.registered.dataType)
8263 type1._class.registered.dataType.refCount++;
8264 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8265 exp.expType = type1._class.registered.dataType; //type1;
8266 if(type1) type1.refCount++;
8270 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8272 if(exp.expType) FreeType(exp.expType);
8273 exp.expType = exp.op.exp2.destType;
8274 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8276 else if(type1 && type2)
8278 char expString1[10240];
8279 char expString2[10240];
8280 char type1String[1024];
8281 char type2String[1024];
8282 expString1[0] = '\0';
8283 expString2[0] = '\0';
8284 type1String[0] = '\0';
8285 type2String[0] = '\0';
8288 PrintExpression(exp.op.exp1, expString1);
8289 ChangeCh(expString1, '\n', ' ');
8290 PrintExpression(exp.op.exp2, expString2);
8291 ChangeCh(expString2, '\n', ' ');
8292 PrintType(exp.op.exp1.expType, type1String, false, true);
8293 PrintType(exp.op.exp2.expType, type2String, false, true);
8296 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8298 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8300 exp.expType = exp.op.exp1.expType;
8301 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8303 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8305 exp.expType = exp.op.exp2.expType;
8306 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8313 // Maybe this was meant to be an enum...
8314 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8316 Type oldType = exp.op.exp1.expType;
8317 exp.op.exp1.expType = null;
8318 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8321 exp.op.exp1.expType = oldType;
8324 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8325 exp.op.exp1.destType = type2;
8328 // TESTING THIS HERE... LATEST ADDITION
8329 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8331 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8332 exp.op.exp1.destType = type1._class.registered.dataType;
8333 if(type1._class.registered.dataType)
8334 type1._class.registered.dataType.refCount++;
8337 // TESTING THIS HERE... LATEST ADDITION
8338 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8340 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8341 exp.op.exp2.destType = type2._class.registered.dataType;
8342 if(type2._class.registered.dataType)
8343 type2._class.registered.dataType.refCount++;
8347 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8349 if(exp.expType) FreeType(exp.expType);
8350 exp.expType = exp.op.exp1.destType;
8351 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8355 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8357 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8359 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8360 // Convert e.g. / 4 into / 4.0
8361 exp.op.exp1.destType = type2._class.registered.dataType;
8362 if(type2._class.registered.dataType)
8363 type2._class.registered.dataType.refCount++;
8364 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8366 if(exp.op.op == '!')
8368 exp.expType = MkClassType("bool");
8369 exp.expType.truth = true;
8373 exp.expType = type2;
8374 if(type2) type2.refCount++;
8377 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8379 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8381 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8382 // Convert e.g. / 4 into / 4.0
8383 exp.op.exp2.destType = type1._class.registered.dataType;
8384 if(type1._class.registered.dataType)
8385 type1._class.registered.dataType.refCount++;
8386 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8388 exp.expType = type1;
8389 if(type1) type1.refCount++;
8394 if(exp.op.exp1 && !exp.op.exp1.expType)
8396 char expString[10000];
8397 expString[0] = '\0';
8400 PrintExpression(exp.op.exp1, expString);
8401 ChangeCh(expString, '\n', ' ');
8404 Compiler_Error($"couldn't determine type of %s\n", expString);
8406 if(exp.op.exp2 && !exp.op.exp2.expType)
8408 char expString[10240];
8409 expString[0] = '\0';
8412 PrintExpression(exp.op.exp2, expString);
8413 ChangeCh(expString, '\n', ' ');
8416 Compiler_Error($"couldn't determine type of %s\n", expString);
8421 FreeType(exp.expType);
8422 exp.expType = MkClassType("bool");
8423 exp.expType.truth = true;
8426 if(exp.op.op != SIZEOF)
8427 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8428 (!exp.op.exp2 || exp.op.exp2.isConstant);
8430 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8432 DeclareType(exp.op.exp2.expType, false, false);
8441 case extensionExpressionExp:
8444 exp.isConstant = true;
8445 for(e = exp.list->first; e; e = e.next)
8450 FreeType(e.destType);
8451 e.destType = exp.destType;
8452 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8454 ProcessExpressionType(e);
8456 exp.destType.count--;
8457 if(!exp.expType && !e.next)
8459 exp.expType = e.expType;
8460 if(e.expType) e.expType.refCount++;
8463 exp.isConstant = false;
8466 // In case a cast became a member...
8467 e = exp.list->first;
8468 if(!e.next && e.type == memberExp)
8470 // Preserve prev, next
8471 Expression next = exp.next, prev = exp.prev;
8474 FreeType(exp.expType);
8475 FreeType(exp.destType);
8485 ProcessExpressionType(exp);
8492 exp.isConstant = true;
8494 ProcessExpressionType(exp.index.exp);
8495 if(!exp.index.exp.isConstant)
8496 exp.isConstant = false;
8498 if(exp.index.exp.expType)
8500 Type source = exp.index.exp.expType;
8501 if(source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
8502 eClass_IsDerived(source._class.registered, containerClass) &&
8503 source._class.registered.templateArgs)
8505 Class _class = source._class.registered;
8506 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8508 if(exp.index.index && exp.index.index->last)
8510 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8515 for(e = exp.index.index->first; e; e = e.next)
8517 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8519 if(e.destType) FreeType(e.destType);
8520 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8522 ProcessExpressionType(e);
8525 // Check if this type is int
8528 exp.isConstant = false;
8532 exp.expType = Dereference(exp.index.exp.expType);
8534 DeclareType(exp.expType, false, false);
8541 Type methodType = null;
8547 PrintExpression(exp.call.exp, name);
8548 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8550 //exp.call.exp.expType = null;
8551 PrintExpression(exp.call.exp, name);
8554 if(exp.call.exp.type == identifierExp)
8556 Expression idExp = exp.call.exp;
8557 Identifier id = idExp.identifier;
8558 if(!strcmp(id.string, "__builtin_frame_address"))
8560 exp.expType = ProcessTypeString("void *", true);
8561 if(exp.call.arguments && exp.call.arguments->first)
8562 ProcessExpressionType(exp.call.arguments->first);
8565 else if(!strcmp(id.string, "__ENDIAN_PAD"))
8567 exp.expType = ProcessTypeString("int", true);
8568 if(exp.call.arguments && exp.call.arguments->first)
8569 ProcessExpressionType(exp.call.arguments->first);
8572 else if(!strcmp(id.string, "Max") ||
8573 !strcmp(id.string, "Min") ||
8574 !strcmp(id.string, "Sgn") ||
8575 !strcmp(id.string, "Abs"))
8577 Expression a = null;
8578 Expression b = null;
8579 Expression tempExp1 = null, tempExp2 = null;
8580 if((!strcmp(id.string, "Max") ||
8581 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8583 a = exp.call.arguments->first;
8584 b = exp.call.arguments->last;
8588 else if(exp.call.arguments->count == 1)
8590 a = exp.call.arguments->first;
8596 exp.call.arguments->Clear();
8597 idExp.identifier = null;
8599 FreeExpContents(exp);
8601 ProcessExpressionType(a);
8603 ProcessExpressionType(b);
8605 exp.type = bracketsExp;
8606 exp.list = MkList();
8608 if(a.expType && (!b || b.expType))
8610 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8612 // Use the simpleStruct name/ids for now...
8615 OldList * specs = MkList();
8616 OldList * decls = MkList();
8618 char temp1[1024], temp2[1024];
8620 GetTypeSpecs(a.expType, specs);
8622 if(a && !a.isConstant && a.type != identifierExp)
8624 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8625 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8626 tempExp1 = QMkExpId(temp1);
8627 tempExp1.expType = a.expType;
8629 a.expType.refCount++;
8630 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8632 if(b && !b.isConstant && b.type != identifierExp)
8634 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8635 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8636 tempExp2 = QMkExpId(temp2);
8637 tempExp2.expType = b.expType;
8639 b.expType.refCount++;
8640 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8643 decl = MkDeclaration(specs, decls);
8644 if(!curCompound.compound.declarations)
8645 curCompound.compound.declarations = MkList();
8646 curCompound.compound.declarations->Insert(null, decl);
8651 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8653 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8655 MkExpCondition(MkExpBrackets(MkListOne(
8656 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8657 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8658 exp.expType = a.expType;
8660 a.expType.refCount++;
8662 else if(!strcmp(id.string, "Abs"))
8665 MkExpCondition(MkExpBrackets(MkListOne(
8666 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8667 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8668 exp.expType = a.expType;
8670 a.expType.refCount++;
8672 else if(!strcmp(id.string, "Sgn"))
8674 // ((!(a))?(0):(((a)<0)?(-1):(1)))
8676 MkExpCondition(MkExpBrackets(MkListOne(
8677 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
8678 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
8679 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8680 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
8681 exp.expType = ProcessTypeString("int", false);
8684 FreeExpression(tempExp1);
8685 if(tempExp2) FreeExpression(tempExp2);
8699 if(!exp.call.exp.destType)
8701 exp.call.exp.destType = dummy;
8704 ProcessExpressionType(exp.call.exp);
8705 if(exp.call.exp.destType == dummy)
8708 exp.call.exp.destType = null;
8713 // Check argument types against parameter types
8714 functionType = exp.call.exp.expType;
8716 if(functionType && functionType.kind == TypeKind::methodType)
8718 methodType = functionType;
8719 functionType = methodType.method.dataType;
8721 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
8722 // TOCHECK: Instead of doing this here could this be done per param?
8723 if(exp.call.exp.expType.usedClass)
8725 char typeString[1024];
8726 typeString[0] = '\0';
8727 PrintType(functionType, typeString, true, true);
8728 if(strstr(typeString, "thisclass"))
8730 OldList * specs = MkList();
8733 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
8735 decl = SpecDeclFromString(typeString, specs, null);
8737 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
8738 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
8739 exp.call.exp.expType.usedClass))
8740 thisClassParams = false;
8742 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
8744 Class backupThisClass = thisClass;
8745 thisClass = exp.call.exp.expType.usedClass;
8746 ProcessDeclarator(decl);
8747 thisClass = backupThisClass;
8750 thisClassParams = true;
8752 functionType = ProcessType(specs, decl);
8753 functionType.refCount = 0;
8754 FinishTemplatesContext(context);
8757 FreeList(specs, FreeSpecifier);
8758 FreeDeclarator(decl);
8762 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
8764 Type type = functionType.type;
8765 if(!functionType.refCount)
8767 functionType.type = null;
8768 FreeType(functionType);
8770 //methodType = functionType;
8771 functionType = type;
8773 if(functionType && functionType.kind != TypeKind::functionType)
8775 Compiler_Error($"called object %s is not a function\n", name);
8777 else if(functionType)
8779 bool emptyParams = false, noParams = false;
8780 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
8781 Type type = functionType.params.first;
8782 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
8784 Location oldyylloc = yylloc;
8786 if(!type) emptyParams = true;
8789 if(functionType.extraParam && e && functionType.thisClass)
8791 e.destType = MkClassType(functionType.thisClass.string);
8795 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
8796 if(!functionType.staticMethod)
8798 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
8799 memberExp.member.exp.expType._class)
8801 type = MkClassType(memberExp.member.exp.expType._class.string);
8806 type = functionType.params.first;
8811 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
8813 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
8818 type = functionType.params.first;
8826 if(type && type.kind == voidType)
8829 if(!type.refCount) FreeType(type);
8833 for( ; e; e = e.next)
8835 if(!type && !emptyParams)
8838 if(methodType && methodType.methodClass)
8839 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
8840 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
8841 noParams ? 0 : functionType.params.count);
8843 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
8844 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
8845 noParams ? 0 : functionType.params.count);
8849 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
8851 Type templatedType = null;
8852 Class _class = methodType.usedClass;
8853 ClassTemplateParameter curParam = null;
8855 if(_class && _class.templateArgs /*&& _class.templateClass*/)
8858 for(sClass = _class; sClass; sClass = sClass.base)
8860 if(sClass.templateClass) sClass = sClass.templateClass;
8862 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
8864 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
8867 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
8869 if(nextClass.templateClass) nextClass = nextClass.templateClass;
8870 id += nextClass.templateParams.count;
8879 if(curParam && _class.templateArgs[id].dataTypeString)
8881 ClassTemplateArgument arg = _class.templateArgs[id];
8883 Context context = SetupTemplatesContext(_class);
8886 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
8887 templatedType = ProcessTypeString(arg.dataTypeString, false);
8888 FinishTemplatesContext(context);
8890 e.destType = templatedType;
8893 templatedType.passAsTemplate = true;
8894 // templatedType.refCount++;
8900 if(type) type.refCount++;
8906 if(type) type.refCount++;
8908 // Don't reach the end for the ellipsis
8909 if(type && type.kind != ellipsisType)
8911 Type next = type.next;
8912 if(!type.refCount) FreeType(type);
8917 if(type && type.kind != ellipsisType)
8919 if(methodType && methodType.methodClass)
8920 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
8921 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
8922 functionType.params.count + extra);
8924 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
8925 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
8926 functionType.params.count + extra);
8929 if(type && !type.refCount) FreeType(type);
8936 kind = TypeKind::functionType;
8939 if(exp.call.exp.type == identifierExp)
8941 char * string = exp.call.exp.identifier.string;
8945 Location oldyylloc = yylloc;
8947 yylloc = exp.call.exp.identifier.loc;
8948 if(strstr(string, "__builtin_") == string);
8950 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
8951 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
8952 globalContext.symbols.Add((BTNode)symbol);
8953 if(strstr(symbol.string, "::"))
8954 globalContext.hasNameSpace = true;
8959 else if(exp.call.exp.type == memberExp)
8961 /*Compiler_Warning($"%s undefined; assuming returning int\n",
8962 exp.call.exp.member.member.string);*/
8965 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
8967 if(!functionType.returnType)
8969 functionType.returnType = Type
8976 if(functionType && functionType.kind == TypeKind::functionType)
8978 exp.expType = functionType.returnType;
8980 if(functionType.returnType)
8981 functionType.returnType.refCount++;
8983 if(!functionType.refCount)
8984 FreeType(functionType);
8987 if(exp.call.arguments)
8989 for(e = exp.call.arguments->first; e; e = e.next)
8991 Type destType = e.destType;
8992 ProcessExpressionType(e);
9000 Location oldyylloc = yylloc;
9001 bool thisPtr = (exp.member.exp && exp.member.exp.type == identifierExp && !strcmp(exp.member.exp.identifier.string, "this"));
9002 exp.thisPtr = thisPtr;
9004 // DOING THIS LATER NOW...
9005 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9007 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9008 /* TODO: Name Space Fix ups
9009 if(!exp.member.member.classSym)
9010 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9014 ProcessExpressionType(exp.member.exp);
9015 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9016 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9018 exp.isConstant = false;
9021 exp.isConstant = exp.member.exp.isConstant;
9022 type = exp.member.exp.expType;
9026 if(type && (type.kind == templateType))
9028 Class _class = thisClass ? thisClass : currentClass;
9029 ClassTemplateParameter param = null;
9032 for(param = _class.templateParams.first; param; param = param.next)
9034 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9038 if(param && param.defaultArg.member)
9040 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9043 Expression expMember = exp.member.exp;
9045 OldList * specs = MkList();
9046 char thisClassTypeString[1024];
9048 FreeIdentifier(exp.member.member);
9050 ProcessExpressionType(argExp);
9053 char * colon = strstr(param.defaultArg.memberString, "::");
9056 char className[1024];
9059 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9060 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9063 strcpy(thisClassTypeString, _class.fullName);
9066 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9068 exp.expType = ProcessType(specs, decl);
9069 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9071 Class expClass = exp.expType._class.registered;
9072 Class cClass = null;
9077 char templateString[1024];
9078 ClassTemplateParameter param;
9079 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9080 for(cClass = expClass; cClass; cClass = cClass.base)
9083 for(param = cClass.templateParams.first; param; param = param.next)
9087 ClassTemplateArgument arg;
9088 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9089 arg = expClass.templateArgs[id];
9091 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9093 ClassTemplateParameter cParam;
9094 //int p = numParams - sClass.templateParams.count;
9097 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9099 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9101 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9103 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9105 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9106 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9118 strcat(argument, arg.name.string);
9119 strcat(argument, " = ");
9125 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9126 char expString[1024];
9127 OldList * specs = MkList();
9128 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9130 char * string = PrintHexUInt64(arg.expression.ui64);
9131 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9133 ProcessExpressionType(exp);
9134 ComputeExpression(exp);
9135 expString[0] = '\0';
9136 PrintExpression(exp, expString);
9137 strcat(argument, expString);
9139 FreeExpression(exp);
9144 strcat(argument, arg.member.name);
9147 case TemplateParameterType::type:
9149 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9151 if(!strcmp(arg.dataTypeString, "thisclass"))
9152 strcat(argument, thisClassTypeString);
9154 strcat(argument, arg.dataTypeString);
9161 if(paramCount) strcat(templateString, ", ");
9162 if(lastParam != p - 1)
9164 strcat(templateString, param.name);
9165 strcat(templateString, " = ");
9167 strcat(templateString, argument);
9176 int len = strlen(templateString);
9177 if(templateString[len-1] == '>') templateString[len++] = ' ';
9178 templateString[len++] = '>';
9179 templateString[len++] = '\0';
9182 Context context = SetupTemplatesContext(_class);
9183 FreeType(exp.expType);
9184 exp.expType = ProcessTypeString(templateString, false);
9185 FinishTemplatesContext(context);
9189 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9190 exp.type = bracketsExp;
9191 exp.list = MkListOne(MkExpOp(null, '*',
9196 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9197 MkExpBrackets(MkListOne(
9198 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9200 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9202 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9207 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9208 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9210 type = ProcessTemplateParameterType(type.templateParameter);
9214 if(type && (type.kind == templateType));
9215 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9217 Identifier id = exp.member.member;
9218 TypeKind typeKind = type.kind;
9219 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9220 if(typeKind == subClassType && exp.member.exp.type == classExp)
9222 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9223 typeKind = classType;
9226 if(id && (typeKind == intType || typeKind == enumType))
9227 _class = eSystem_FindClass(privateModule, "int");
9232 (exp.member.exp.type == identifierExp &&
9233 !strcmp(exp.member.exp.identifier.string, "this"));*/
9234 Property prop = null;
9235 Method method = null;
9236 DataMember member = null;
9237 Property revConvert = null;
9238 ClassProperty classProp = null;
9240 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9241 exp.member.memberType = propertyMember;
9243 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9244 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9246 if(typeKind != subClassType)
9248 // Prioritize data members over properties for "this"
9249 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9251 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9252 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9254 prop = eClass_FindProperty(_class, id.string, privateModule);
9258 if(!member && !prop)
9259 prop = eClass_FindProperty(_class, id.string, privateModule);
9260 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9261 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9262 exp.member.thisPtr = true;
9264 // Prioritize properties over data members otherwise
9267 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9270 prop = eClass_FindProperty(_class, id.string, null);
9271 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9272 member = eClass_FindDataMember(_class, id.string, null, null, null);
9275 if(!prop && !member)
9277 method = eClass_FindMethod(_class, id.string, null);
9280 prop = eClass_FindProperty(_class, id.string, privateModule);
9281 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9282 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9288 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9295 if(!prop && !member)
9296 method = eClass_FindMethod(_class, id.string, privateModule);
9297 if(!prop && !member && !method)
9299 if(typeKind == subClassType)
9301 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9304 exp.member.memberType = classPropertyMember;
9305 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9309 // Assume this is a class_data member
9310 char structName[1024];
9311 Identifier id = exp.member.member;
9312 Expression classExp = exp.member.exp;
9315 FreeType(classExp.expType);
9316 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9318 strcpy(structName, "__ecereClassData_");
9319 FullClassNameCat(structName, type._class.string, false);
9320 exp.type = pointerExp;
9321 exp.member.member = id;
9323 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9324 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9325 MkExpBrackets(MkListOne(MkExpOp(
9326 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9327 MkExpMember(classExp, MkIdentifier("data"))), '+',
9328 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9333 ProcessExpressionType(exp);
9339 // Check for reverse conversion
9340 // (Convert in an instantiation later, so that we can use
9341 // deep properties system)
9342 Symbol classSym = FindClass(id.string);
9345 Class convertClass = classSym.registered;
9347 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9354 exp.member.memberType = propertyMember;
9356 ProcessPropertyType(prop);
9357 exp.expType = prop.dataType;
9358 if(prop.dataType) prop.dataType.refCount++;
9362 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9364 FreeExpContents(exp);
9365 exp.type = identifierExp;
9366 exp.identifier = MkIdentifier("class");
9367 ProcessExpressionType(exp);
9371 exp.member.memberType = dataMember;
9372 DeclareStruct(_class.fullName, false);
9373 if(!member.dataType)
9375 Context context = SetupTemplatesContext(_class);
9376 member.dataType = ProcessTypeString(member.dataTypeString, false);
9377 FinishTemplatesContext(context);
9379 exp.expType = member.dataType;
9380 if(member.dataType) member.dataType.refCount++;
9384 exp.member.memberType = reverseConversionMember;
9385 exp.expType = MkClassType(revConvert._class.fullName);
9393 exp.type = identifierExp;
9394 exp.identifier = exp.member.member;
9397 exp.member.memberType = methodMember;
9399 if(!method.dataType)
9400 ProcessMethodType(method);
9408 // Tricky spot here... To use instance versus class virtual table
9409 // Put it back to what it was... What did we break?
9411 // Had to put it back for overriding Main of Thread global instance
9413 //exp.expType.methodClass = _class;
9414 exp.expType.methodClass = (id && id._class) ? _class : null;
9416 // Need the actual class used for templated classes
9417 exp.expType.usedClass = _class;
9421 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9423 FreeExpContents(exp);
9424 exp.type = identifierExp;
9425 exp.identifier = MkIdentifier("class");
9426 ProcessExpressionType(exp);
9429 yylloc = exp.member.member.loc;
9430 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9432 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9435 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9440 while(tClass && !tClass.templateClass) tClass = tClass.base;
9442 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9445 ClassTemplateParameter curParam = null;
9448 for(sClass = tClass; sClass; sClass = sClass.base)
9451 if(sClass.templateClass) sClass = sClass.templateClass;
9452 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9454 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9456 for(sClass = sClass.base; sClass; sClass = sClass.base)
9457 id += sClass.templateParams.count;
9465 if(curParam && tClass.templateArgs[id].dataTypeString)
9467 ClassTemplateArgument arg = tClass.templateArgs[id];
9468 Context context = SetupTemplatesContext(tClass);
9470 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9471 FreeType(exp.expType);
9472 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9475 if(exp.expType.kind == thisClassType)
9477 FreeType(exp.expType);
9478 exp.expType = ReplaceThisClassType(_class);
9481 if(tClass.templateClass)
9482 exp.expType.passAsTemplate = true;
9483 //exp.expType.refCount++;
9486 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9487 //exp.destType.refCount++;
9489 if(exp.destType.kind == thisClassType)
9491 FreeType(exp.destType);
9492 exp.destType = ReplaceThisClassType(_class);
9496 FinishTemplatesContext(context);
9499 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9500 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9503 ClassTemplateParameter curParam = null;
9506 for(sClass = tClass; sClass; sClass = sClass.base)
9509 if(sClass.templateClass) sClass = sClass.templateClass;
9510 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9512 if(curParam.type == TemplateParameterType::type &&
9513 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9515 for(sClass = sClass.base; sClass; sClass = sClass.base)
9516 id += sClass.templateParams.count;
9526 ClassTemplateArgument arg = tClass.templateArgs[id];
9527 Context context = SetupTemplatesContext(tClass);
9530 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9532 basicType = ProcessTypeString(arg.dataTypeString, false);
9535 if(basicType.kind == thisClassType)
9537 FreeType(basicType);
9538 basicType = ReplaceThisClassType(_class);
9541 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9542 if(tClass.templateClass)
9543 basicType.passAsTemplate = true;
9546 FreeType(exp.expType);
9548 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9549 //exp.expType.refCount++;
9552 exp.destType = exp.expType;
9553 exp.destType.refCount++;
9557 Expression newExp { };
9558 OldList * specs = MkList();
9560 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9562 if(exp.destType) exp.destType.refCount++;
9563 if(exp.expType) exp.expType.refCount++;
9565 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9566 exp.cast.exp = newExp;
9567 //FreeType(exp.expType);
9568 //exp.expType = null;
9569 //ProcessExpressionType(sourceExp);
9572 FinishTemplatesContext(context);
9575 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9577 Class expClass = exp.expType._class.registered;
9580 Class cClass = null;
9585 char templateString[1024];
9586 ClassTemplateParameter param;
9587 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9588 while(cClass != expClass)
9591 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9594 for(param = cClass.templateParams.first; param; param = param.next)
9596 Class cClassCur = null;
9599 ClassTemplateParameter paramCur = null;
9600 ClassTemplateArgument arg;
9601 while(cClassCur != tClass && !paramCur)
9604 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
9605 cClassCur = sClassCur;
9607 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
9609 if(!strcmp(paramCur.name, param.name))
9617 if(paramCur && paramCur.type == TemplateParameterType::type)
9618 arg = tClass.templateArgs[cp];
9620 arg = expClass.templateArgs[p];
9627 strcat(argument, arg.name.string);
9628 strcat(argument, " = ");
9634 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9635 char expString[1024];
9636 OldList * specs = MkList();
9637 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9639 char * string = PrintHexUInt64(arg.expression.ui64);
9640 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9642 ProcessExpressionType(exp);
9643 ComputeExpression(exp);
9644 expString[0] = '\0';
9645 PrintExpression(exp, expString);
9646 strcat(argument, expString);
9648 FreeExpression(exp);
9653 strcat(argument, arg.member.name);
9656 case TemplateParameterType::type:
9658 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9659 strcat(argument, arg.dataTypeString);
9665 if(paramCount) strcat(templateString, ", ");
9666 if(lastParam != p - 1)
9668 strcat(templateString, param.name);
9669 strcat(templateString, " = ");
9671 strcat(templateString, argument);
9680 int len = strlen(templateString);
9681 if(templateString[len-1] == '>') templateString[len++] = ' ';
9682 templateString[len++] = '>';
9683 templateString[len++] = '\0';
9686 FreeType(exp.expType);
9688 Context context = SetupTemplatesContext(tClass);
9689 exp.expType = ProcessTypeString(templateString, false);
9690 FinishTemplatesContext(context);
9697 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
9699 else if(type && (type.kind == structType || type.kind == unionType))
9701 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
9704 exp.expType = memberType;
9706 memberType.refCount++;
9711 char expString[10240];
9712 expString[0] = '\0';
9713 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
9714 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
9717 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
9719 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9721 Identifier id = exp.member.member;
9722 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9725 FreeType(exp.expType);
9726 exp.expType = ReplaceThisClassType(_class);
9733 // Convert x->y into (*x).y
9736 Type destType = exp.destType;
9738 // DOING THIS LATER NOW...
9739 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9741 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9742 /* TODO: Name Space Fix ups
9743 if(!exp.member.member.classSym)
9744 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
9748 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
9749 exp.type = memberExp;
9752 ProcessExpressionType(exp);
9759 //ComputeExpression(exp);
9761 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
9762 if(classSym && classSym.registered)
9764 if(classSym.registered.type == noHeadClass)
9768 DeclareStruct(classSym.string, false);
9769 FreeSpecifier(exp._class);
9770 exp.type = typeSizeExp;
9771 FullClassNameCat(name, classSym.string, false);
9772 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
9776 if(classSym.registered.fixed)
9778 FreeSpecifier(exp._class);
9779 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
9780 exp.type = constantExp;
9784 char className[1024];
9785 strcpy(className, "__ecereClass_");
9786 FullClassNameCat(className, classSym.string, true);
9787 MangleClassName(className);
9789 DeclareClass(classSym, className);
9791 FreeExpContents(exp);
9792 exp.type = pointerExp;
9793 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
9794 exp.member.member = MkIdentifier("structSize");
9804 // exp.isConstant = true;
9809 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
9816 exp.isConstant = true;
9818 DeclareType(type, false, false);
9824 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
9826 FreeType(exp.cast.exp.destType);
9827 exp.cast.exp.destType = type;
9829 ProcessExpressionType(exp.cast.exp);
9834 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
9835 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
9837 void * prev = exp.prev, * next = exp.next;
9838 Type expType = exp.cast.exp.destType;
9839 Expression castExp = exp.cast.exp;
9840 Type destType = exp.destType;
9842 if(expType) expType.refCount++;
9844 //FreeType(exp.destType);
9845 FreeType(exp.expType);
9846 FreeTypeName(exp.cast.typeName);
9849 FreeType(exp.expType);
9850 FreeType(exp.destType);
9852 exp.expType = expType;
9853 exp.destType = destType;
9863 exp.isConstant = exp.cast.exp.isConstant;
9868 case extensionInitializerExp:
9870 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
9873 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
9874 // ProcessInitializer(exp.initializer.initializer, type);
9880 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
9881 ProcessExpressionType(exp.vaArg.exp);
9889 exp.isConstant = true;
9891 FreeType(exp.cond.cond.destType);
9892 exp.cond.cond.destType = MkClassType("bool");
9893 exp.cond.cond.destType.truth = true;
9894 ProcessExpressionType(exp.cond.cond);
9895 if(!exp.cond.cond.isConstant)
9896 exp.isConstant = false;
9897 for(e = exp.cond.exp->first; e; e = e.next)
9901 FreeType(e.destType);
9902 e.destType = exp.destType;
9903 if(e.destType) e.destType.refCount++;
9905 ProcessExpressionType(e);
9908 exp.expType = e.expType;
9909 if(e.expType) e.expType.refCount++;
9912 exp.isConstant = false;
9915 FreeType(exp.cond.elseExp.destType);
9916 // Added this check if we failed to find an expType
9917 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
9920 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
9922 if(exp.cond.elseExp.destType)
9923 exp.cond.elseExp.destType.refCount++;
9924 ProcessExpressionType(exp.cond.elseExp);
9926 // FIXED THIS: Was done before calling process on elseExp
9927 if(!exp.cond.elseExp.isConstant)
9928 exp.isConstant = false;
9931 case extensionCompoundExp:
9933 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
9935 Statement last = exp.compound.compound.statements->last;
9936 if(last.type == expressionStmt && last.expressions && last.expressions->last)
9938 ((Expression)last.expressions->last).destType = exp.destType;
9940 exp.destType.refCount++;
9942 ProcessStatement(exp.compound);
9943 exp.expType = ((Expression)last.expressions->last).expType;
9944 if(((Expression)last.expressions->last).expType)
9945 exp.expType.refCount++;
9951 Specifier spec = exp._classExp.specifiers->first;
9952 if(spec && spec.type == nameSpecifier)
9954 exp.expType = MkClassType(spec.name);
9955 exp.expType.kind = subClassType;
9956 exp.byReference = true;
9960 exp.expType = MkClassType("ecere::com::Class");
9961 exp.byReference = true;
9967 Class _class = thisClass ? thisClass : currentClass;
9970 Identifier id = exp.classData.id;
9971 char structName[1024];
9972 Expression classExp;
9973 strcpy(structName, "__ecereClassData_");
9974 FullClassNameCat(structName, _class.fullName, false);
9975 exp.type = pointerExp;
9976 exp.member.member = id;
9977 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
9978 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
9980 classExp = MkExpIdentifier(MkIdentifier("class"));
9982 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9983 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9984 MkExpBrackets(MkListOne(MkExpOp(
9985 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9986 MkExpMember(classExp, MkIdentifier("data"))), '+',
9987 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
9990 ProcessExpressionType(exp);
9998 char * typeString = null;
9999 char typeStringBuf[1024];
10000 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10001 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10003 Class templateClass = exp.destType._class.registered;
10004 typeString = templateClass.templateArgs[2].dataTypeString;
10008 // Guess type from expressions in the array
10010 for(e = exp.list->first; e; e = e.next)
10012 ProcessExpressionType(e);
10015 if(!type) { type = e.expType; type.refCount++; }
10018 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10019 if(!MatchTypeExpression(e, type, null, false))
10025 e = exp.list->first;
10026 ProcessExpressionType(e);
10029 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10030 if(!MatchTypeExpression(e, type, null, false))
10032 FreeType(e.expType);
10043 FreeType(e.expType);
10050 typeStringBuf[0] = '\0';
10051 PrintType(type, typeStringBuf, false, true);
10052 typeString = typeStringBuf;
10060 (Container)& (struct BuiltInContainer)
10062 ._vTbl = class(BuiltInContainer)._vTbl,
10063 ._class = class(BuiltInContainer),
10065 .data = (int[]){ 1, 7, 3, 4, 5 },
10067 .type = class(int),
10070 char templateString[1024];
10071 OldList * initializers = MkList();
10072 OldList * structInitializers = MkList();
10073 OldList * specs = MkList();
10075 Declarator decl = SpecDeclFromString(typeString, specs, null);
10076 sprintf(templateString, "Container<%s>", typeString);
10081 type = ProcessTypeString(typeString, false);
10082 while(e = exp.list->first)
10084 exp.list->Remove(e);
10087 ProcessExpressionType(e);
10088 ListAdd(initializers, MkInitializerAssignment(e));
10094 DeclareStruct("ecere::com::BuiltInContainer", false);
10096 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10097 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10098 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10099 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10100 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10101 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10102 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10103 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10104 MkInitializerList(initializers))));
10105 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10106 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10107 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10108 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10109 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10110 exp.expType = ProcessTypeString(templateString, false);
10111 exp.type = bracketsExp;
10112 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10114 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10115 MkInitializerList(structInitializers)))));
10116 ProcessExpressionType(expExt);
10120 exp.expType = ProcessTypeString("Container", false);
10121 Compiler_Error($"Couldn't determine type of array elements\n");
10127 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10129 FreeType(exp.expType);
10130 exp.expType = ReplaceThisClassType(thisClass);
10133 // Resolve structures here
10134 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10136 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10137 // TODO: Fix members reference...
10140 if(exp.expType.kind != enumType)
10143 String enumName = CopyString(exp.expType.enumName);
10145 // Fixed a memory leak on self-referencing C structs typedefs
10146 // by instantiating a new type rather than simply copying members
10147 // into exp.expType
10148 FreeType(exp.expType);
10149 exp.expType = Type { };
10150 exp.expType.kind = symbol.type.kind;
10151 exp.expType.refCount++;
10152 exp.expType.enumName = enumName;
10154 exp.expType.members = symbol.type.members;
10155 for(member = symbol.type.members.first; member; member = member.next)
10161 for(member = symbol.type.members.first; member; member = member.next)
10163 NamedLink value { name = CopyString(member.name) };
10164 exp.expType.members.Add(value);
10171 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10172 else if(exp.destType && !exp.destType.keepCast)
10174 if(!CheckExpressionType(exp, exp.destType, false))
10176 if(!exp.destType.count || unresolved)
10181 if(exp.destType.kind != ellipsisType)
10187 char expString[10240];
10188 expString[0] = '\0';
10190 PrintType(exp.destType, type2, false, true);
10192 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10194 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10195 else if(exp.type != dummyExp)
10196 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10201 char expString[10240] ;
10202 expString[0] = '\0';
10203 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10206 Compiler_Error($"unresolved identifier %s\n", expString);
10207 else if(exp.type != dummyExp)
10208 Compiler_Error($"couldn't determine type of %s\n", expString);
10219 PrintType(exp.expType, type1, false, true);
10220 PrintType(exp.destType, type2, false, true);
10223 //CheckExpressionType(exp, exp.destType, false);
10225 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10226 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10227 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10230 char expString[10240];
10231 expString[0] = '\0';
10232 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10235 CheckExpressionType(exp, exp.destType, false);
10237 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10238 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10239 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10241 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10242 FreeType(exp.expType);
10243 exp.destType.refCount++;
10244 exp.expType = exp.destType;
10249 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10251 Expression newExp { };
10252 char typeString[1024];
10253 OldList * specs = MkList();
10256 typeString[0] = '\0';
10260 if(exp.expType) exp.expType.refCount++;
10261 if(exp.expType) exp.expType.refCount++;
10262 exp.type = castExp;
10263 newExp.destType = exp.expType;
10265 PrintType(exp.expType, typeString, false, false);
10266 decl = SpecDeclFromString(typeString, specs, null);
10268 exp.cast.typeName = MkTypeName(specs, decl);
10269 exp.cast.exp = newExp;
10272 else if(unresolved)
10274 if(exp.identifier._class && exp.identifier._class.name)
10275 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10276 else if(exp.identifier.string && exp.identifier.string[0])
10277 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10279 else if(!exp.expType && exp.type != dummyExp)
10281 char expString[10240];
10282 expString[0] = '\0';
10283 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10284 Compiler_Error($"couldn't determine type of %s\n", expString);
10287 // Let's try to support any_object & typed_object here:
10288 ApplyAnyObjectLogic(exp);
10290 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10291 exp.expType._class.registered.type == noHeadClass)
10293 exp.byReference = true;
10295 /*else if(!notByReference && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10296 exp.destType._class.registered.type == noHeadClass)
10298 exp.byReference = true;
10300 yylloc = oldyylloc;
10303 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10305 // THIS CODE WILL FIND NEXT MEMBER...
10308 *curMember = (*curMember).next;
10310 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10312 *curMember = subMemberStack[--(*subMemberStackPos)];
10313 *curMember = (*curMember).next;
10316 // SKIP ALL PROPERTIES HERE...
10317 while((*curMember) && (*curMember).isProperty)
10318 *curMember = (*curMember).next;
10320 if(subMemberStackPos)
10322 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10324 subMemberStack[(*subMemberStackPos)++] = *curMember;
10326 *curMember = (*curMember).members.first;
10327 while(*curMember && (*curMember).isProperty)
10328 *curMember = (*curMember).next;
10336 if(subMemberStackPos && *subMemberStackPos)
10338 *curMember = subMemberStack[--(*subMemberStackPos)];
10339 *curMember = (*curMember).next;
10343 Class lastCurClass = *curClass;
10345 if(*curClass == _class) break; // REACHED THE END
10347 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10348 *curMember = (*curClass).membersAndProperties.first;
10351 while((*curMember) && (*curMember).isProperty)
10352 *curMember = (*curMember).next;
10353 if(subMemberStackPos)
10355 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10357 subMemberStack[(*subMemberStackPos)++] = *curMember;
10359 *curMember = (*curMember).members.first;
10360 while(*curMember && (*curMember).isProperty)
10361 *curMember = (*curMember).next;
10369 static void ProcessInitializer(Initializer init, Type type)
10373 case expInitializer:
10374 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10376 // TESTING THIS FOR SHUTTING = 0 WARNING
10377 if(init.exp && !init.exp.destType)
10379 FreeType(init.exp.destType);
10380 init.exp.destType = type;
10381 if(type) type.refCount++;
10385 ProcessExpressionType(init.exp);
10386 init.isConstant = init.exp.isConstant;
10392 Expression exp = init.exp;
10393 Instantiation inst = exp.instance;
10394 MembersInit members;
10396 init.type = listInitializer;
10397 init.list = MkList();
10401 for(members = inst.members->first; members; members = members.next)
10403 if(members.type == dataMembersInit)
10406 for(member = members.dataMembers->first; member; member = member.next)
10408 ListAdd(init.list, member.initializer);
10409 member.initializer = null;
10412 // Discard all MembersInitMethod
10415 FreeExpression(exp);
10417 case listInitializer:
10420 Type initializerType = null;
10421 Class curClass = null;
10422 DataMember curMember = null;
10423 DataMember subMemberStack[256];
10424 int subMemberStackPos = 0;
10426 if(type && type.kind == arrayType)
10427 initializerType = Dereference(type);
10428 else if(type && (type.kind == structType || type.kind == unionType))
10429 initializerType = type.members.first;
10431 for(i = init.list->first; i; i = i.next)
10433 if(type && type.kind == classType && type._class && type._class.registered)
10435 // 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)
10436 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10437 // TODO: Generate error on initializing a private data member this way from another module...
10440 if(!curMember.dataType)
10441 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10442 initializerType = curMember.dataType;
10445 ProcessInitializer(i, initializerType);
10446 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10447 initializerType = initializerType.next;
10449 init.isConstant = false;
10452 if(type && type.kind == arrayType)
10453 FreeType(initializerType);
10455 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10457 Compiler_Error($"Assigning list initializer to non list\n");
10464 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10468 case baseSpecifier:
10470 if(spec.specifier == THISCLASS)
10474 spec.type = nameSpecifier;
10475 spec.name = ReplaceThisClass(thisClass);
10476 spec.symbol = FindClass(spec.name);
10477 ProcessSpecifier(spec, declareStruct);
10482 case nameSpecifier:
10484 Symbol symbol = FindType(curContext, spec.name);
10486 DeclareType(symbol.type, true, true);
10487 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10488 DeclareStruct(spec.name, false);
10491 case enumSpecifier:
10496 for(e = spec.list->first; e; e = e.next)
10499 ProcessExpressionType(e.exp);
10504 case structSpecifier:
10505 case unionSpecifier:
10507 if(spec.definitions)
10510 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10512 ProcessClass(spec.definitions, symbol);
10515 for(def = spec.definitions->first; def; def = def.next)
10517 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10518 ProcessDeclaration(def.decl);
10525 case classSpecifier:
10527 Symbol classSym = FindClass(spec.name);
10528 if(classSym && classSym.registered && classSym.registered.type == structClass)
10529 DeclareStruct(spec.name, false);
10537 static void ProcessDeclarator(Declarator decl)
10541 case identifierDeclarator:
10542 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10544 FreeSpecifier(decl.identifier._class);
10545 decl.identifier._class = null;
10548 case arrayDeclarator:
10550 ProcessExpressionType(decl.array.exp);
10551 case structDeclarator:
10552 case bracketsDeclarator:
10553 case functionDeclarator:
10554 case pointerDeclarator:
10555 case extendedDeclarator:
10556 case extendedDeclaratorEnd:
10557 if(decl.declarator)
10558 ProcessDeclarator(decl.declarator);
10559 if(decl.type == functionDeclarator)
10561 Identifier id = GetDeclId(decl);
10562 if(id && id._class)
10566 qualifiers = MkListOne(id._class);
10569 if(!decl.function.parameters)
10570 decl.function.parameters = MkList();
10571 decl.function.parameters->Insert(null, param);
10574 if(decl.function.parameters)
10578 for(param = decl.function.parameters->first; param; param = param.next)
10580 if(param.qualifiers && param.qualifiers->first)
10582 Specifier spec = param.qualifiers->first;
10583 if(spec && spec.specifier == TYPED_OBJECT)
10585 Declarator d = param.declarator;
10588 qualifiers = MkListOne(MkSpecifier(VOID));
10589 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10592 FreeList(param.qualifiers, FreeSpecifier);
10594 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10595 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10597 decl.function.parameters->Insert(param, newParam);
10600 else if(spec && spec.specifier == ANY_OBJECT)
10602 Declarator d = param.declarator;
10604 FreeList(param.qualifiers, FreeSpecifier);
10606 param.qualifiers = MkListOne(MkSpecifier(VOID));
10607 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10609 else if(spec.specifier == THISCLASS)
10613 spec.type = nameSpecifier;
10614 spec.name = ReplaceThisClass(thisClass);
10615 spec.symbol = FindClass(spec.name);
10616 ProcessSpecifier(spec, false);
10621 if(param.declarator)
10622 ProcessDeclarator(param.declarator);
10630 static void ProcessDeclaration(Declaration decl)
10635 case initDeclaration:
10637 bool declareStruct = false;
10639 lineNum = decl.pos.line;
10640 column = decl.pos.col;
10643 if(decl.declarators)
10647 for(d = decl.declarators->first; d; d = d.next)
10649 Type type, subType;
10650 ProcessDeclarator(d.declarator);
10652 type = ProcessType(decl.specifiers, d.declarator);
10656 ProcessInitializer(d.initializer, type);
10658 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
10660 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
10661 d.initializer.exp.type == instanceExp)
10663 if(type.kind == classType && type._class ==
10664 d.initializer.exp.expType._class)
10666 Instantiation inst = d.initializer.exp.instance;
10667 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
10669 d.initializer.exp.instance = null;
10670 if(decl.specifiers)
10671 FreeList(decl.specifiers, FreeSpecifier);
10672 FreeList(decl.declarators, FreeInitDeclarator);
10676 decl.type = instDeclaration;
10681 for(subType = type; subType;)
10683 if(subType.kind == classType)
10685 declareStruct = true;
10688 else if(subType.kind == pointerType)
10690 else if(subType.kind == arrayType)
10691 subType = subType.arrayType;
10701 if(decl.specifiers)
10704 for(s = decl.specifiers->first; s; s = s.next)
10706 ProcessSpecifier(s, declareStruct);
10711 case instDeclaration:
10713 ProcessInstantiationType(decl.inst);
10716 case structDeclaration:
10720 bool declareStruct = false;
10722 if(decl.declarators)
10724 for(d = decl.declarators->first; d; d = d.next)
10726 Type type = ProcessType(decl.specifiers, d.declarator);
10728 ProcessDeclarator(d);
10729 for(subType = type; subType;)
10731 if(subType.kind == classType)
10733 declareStruct = true;
10736 else if(subType.kind == pointerType)
10738 else if(subType.kind == arrayType)
10739 subType = subType.arrayType;
10746 if(decl.specifiers)
10748 for(spec = decl.specifiers->first; spec; spec = spec.next)
10749 ProcessSpecifier(spec, declareStruct);
10756 static FunctionDefinition curFunction;
10758 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
10760 char propName[1024], propNameM[1024];
10761 char getName[1024], setName[1024];
10764 DeclareProperty(prop, setName, getName);
10766 // eInstance_FireWatchers(object, prop);
10767 strcpy(propName, "__ecereProp_");
10768 FullClassNameCat(propName, prop._class.fullName, false);
10769 strcat(propName, "_");
10770 // strcat(propName, prop.name);
10771 FullClassNameCat(propName, prop.name, true);
10772 MangleClassName(propName);
10774 strcpy(propNameM, "__ecerePropM_");
10775 FullClassNameCat(propNameM, prop._class.fullName, false);
10776 strcat(propNameM, "_");
10777 // strcat(propNameM, prop.name);
10778 FullClassNameCat(propNameM, prop.name, true);
10779 MangleClassName(propNameM);
10781 if(prop.isWatchable)
10784 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10785 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10786 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10789 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10790 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10791 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10797 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10798 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10799 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10802 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10803 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10804 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10807 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
10808 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
10809 curFunction.propSet.fireWatchersDone = true;
10812 static void ProcessStatement(Statement stmt)
10816 lineNum = stmt.pos.line;
10817 column = stmt.pos.col;
10822 ProcessStatement(stmt.labeled.stmt);
10825 // This expression should be constant...
10826 if(stmt.caseStmt.exp)
10828 FreeType(stmt.caseStmt.exp.destType);
10829 stmt.caseStmt.exp.destType = curSwitchType;
10830 if(curSwitchType) curSwitchType.refCount++;
10831 ProcessExpressionType(stmt.caseStmt.exp);
10832 ComputeExpression(stmt.caseStmt.exp);
10834 if(stmt.caseStmt.stmt)
10835 ProcessStatement(stmt.caseStmt.stmt);
10839 if(stmt.compound.context)
10844 Statement prevCompound = curCompound;
10845 Context prevContext = curContext;
10847 if(!stmt.compound.isSwitch)
10849 curCompound = stmt;
10850 curContext = stmt.compound.context;
10853 if(stmt.compound.declarations)
10855 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
10856 ProcessDeclaration(decl);
10858 if(stmt.compound.statements)
10860 for(s = stmt.compound.statements->first; s; s = s.next)
10861 ProcessStatement(s);
10864 curContext = prevContext;
10865 curCompound = prevCompound;
10869 case expressionStmt:
10872 if(stmt.expressions)
10874 for(exp = stmt.expressions->first; exp; exp = exp.next)
10875 ProcessExpressionType(exp);
10883 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
10884 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
10885 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
10886 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
10888 ProcessExpressionType(exp);
10890 if(stmt.ifStmt.stmt)
10891 ProcessStatement(stmt.ifStmt.stmt);
10892 if(stmt.ifStmt.elseStmt)
10893 ProcessStatement(stmt.ifStmt.elseStmt);
10898 Type oldSwitchType = curSwitchType;
10899 if(stmt.switchStmt.exp)
10902 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
10912 e.exp.destType = destType;
10915 ProcessExpressionType(exp);
10918 curSwitchType = exp.expType;
10921 ProcessStatement(stmt.switchStmt.stmt);
10922 curSwitchType = oldSwitchType;
10927 if(stmt.whileStmt.exp)
10931 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
10932 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
10933 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
10934 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
10936 ProcessExpressionType(exp);
10939 if(stmt.whileStmt.stmt)
10940 ProcessStatement(stmt.whileStmt.stmt);
10945 if(stmt.doWhile.exp)
10949 if(stmt.doWhile.exp->last)
10951 FreeType(((Expression)stmt.doWhile.exp->last).destType);
10952 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
10953 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
10955 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
10957 ProcessExpressionType(exp);
10960 if(stmt.doWhile.stmt)
10961 ProcessStatement(stmt.doWhile.stmt);
10967 if(stmt.forStmt.init)
10968 ProcessStatement(stmt.forStmt.init);
10970 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
10972 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
10973 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
10974 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
10977 if(stmt.forStmt.check)
10978 ProcessStatement(stmt.forStmt.check);
10979 if(stmt.forStmt.increment)
10981 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
10982 ProcessExpressionType(exp);
10985 if(stmt.forStmt.stmt)
10986 ProcessStatement(stmt.forStmt.stmt);
10991 Identifier id = stmt.forEachStmt.id;
10992 OldList * exp = stmt.forEachStmt.exp;
10993 OldList * filter = stmt.forEachStmt.filter;
10994 Statement block = stmt.forEachStmt.stmt;
10995 char iteratorType[1024];
10998 bool isBuiltin = exp && exp->last &&
10999 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11000 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11001 Expression arrayExp;
11002 char * typeString = null;
11003 int builtinCount = 0;
11005 for(e = exp ? exp->first : null; e; e = e.next)
11009 FreeType(e.destType);
11010 e.destType = ProcessTypeString("Container", false);
11012 if(!isBuiltin || e.next)
11013 ProcessExpressionType(e);
11016 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11017 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11018 eClass_IsDerived(source._class.registered, containerClass)))
11020 Class _class = source ? source._class.registered : null;
11022 Expression expIt = null;
11023 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
11024 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11025 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11026 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11027 stmt.type = compoundStmt;
11029 stmt.compound.context = Context { };
11030 stmt.compound.context.parent = curContext;
11031 curContext = stmt.compound.context;
11033 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11035 Class mapClass = eSystem_FindClass(privateModule, "Map");
11036 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11037 isCustomAVLTree = true;
11038 if(eClass_IsDerived(source._class.registered, avlTreeClass))
11040 else if(eClass_IsDerived(source._class.registered, mapClass))
11043 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11044 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11046 Class listClass = eSystem_FindClass(privateModule, "List");
11048 isList = eClass_IsDerived(source._class.registered, listClass);
11054 OldList * specs = MkList();
11055 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11056 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11057 stmt.compound.declarations = MkListOne(
11058 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11059 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11060 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11061 MkInitializerAssignment(MkExpBrackets(exp))))));
11066 char typeStringBuf[1024];
11068 // TODO: Merge this code?
11069 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11070 if(((Expression)exp->last).type == castExp)
11072 TypeName typeName = ((Expression)exp->last).cast.typeName;
11074 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11077 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11078 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11079 arrayExp.destType._class.registered.templateArgs)
11081 Class templateClass = arrayExp.destType._class.registered;
11082 typeString = templateClass.templateArgs[2].dataTypeString;
11084 else if(arrayExp.list)
11086 // Guess type from expressions in the array
11088 for(e = arrayExp.list->first; e; e = e.next)
11090 ProcessExpressionType(e);
11093 if(!type) { type = e.expType; type.refCount++; }
11096 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11097 if(!MatchTypeExpression(e, type, null, false))
11103 e = arrayExp.list->first;
11104 ProcessExpressionType(e);
11107 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11108 if(!MatchTypeExpression(e, type, null, false))
11110 FreeType(e.expType);
11121 FreeType(e.expType);
11128 typeStringBuf[0] = '\0';
11129 PrintType(type, typeStringBuf, false, true);
11130 typeString = typeStringBuf;
11136 OldList * initializers = MkList();
11138 OldList * specs = MkList();
11143 builtinCount = arrayExp.list->count;
11144 type = ProcessTypeString(typeString, false);
11145 while(e = arrayExp.list->first)
11147 arrayExp.list->Remove(e);
11150 ProcessExpressionType(e);
11151 ListAdd(initializers, MkInitializerAssignment(e));
11154 delete arrayExp.list;
11156 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11157 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11158 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11160 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorArray(PlugDeclarator(
11161 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorIdentifier(MkIdentifier("__internalArray"))), null), MkInitializerList(initializers)))));
11163 FreeList(exp, FreeExpression);
11167 arrayExp.expType = ProcessTypeString("Container", false);
11168 Compiler_Error($"Couldn't determine type of array elements\n");
11173 OldList * specs = MkList();
11175 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11176 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11177 stmt.compound.declarations = MkListOne(
11178 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11179 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11180 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11181 MkInitializerAssignment(MkExpBrackets(exp))))));
11184 else if(isLinkList && !isList)
11187 OldList * specs = MkList();
11188 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11189 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11190 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11191 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11192 MkInitializerAssignment(MkExpBrackets(exp))))));
11194 /*else if(isCustomAVLTree)
11197 OldList * specs = MkList();
11198 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11199 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11200 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11201 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11202 MkInitializerAssignment(MkExpBrackets(exp))))));
11204 else if(_class.templateArgs)
11207 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11209 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11211 stmt.compound.declarations = MkListOne(
11212 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11213 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11214 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11216 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11218 if(block && block.type == compoundStmt && block.compound.context)
11220 block.compound.context.parent = stmt.compound.context;
11224 block = MkIfStmt(filter, block, null);
11228 stmt.compound.statements = MkListOne(MkForStmt(
11229 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11230 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11231 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11232 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11234 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11235 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11236 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11241 //OldList * specs = MkList();
11242 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11244 sprintf(count, "%d", builtinCount);
11246 stmt.compound.statements = MkListOne(MkForStmt(
11247 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11248 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11249 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11250 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11254 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11255 stmt.compound.statements = MkListOne(MkForStmt(
11256 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11257 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11258 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11259 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11262 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11263 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11264 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11266 else if(isLinkList && !isList)
11268 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11269 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11270 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11271 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11273 stmt.compound.statements = MkListOne(MkForStmt(
11274 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11275 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11276 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11281 OldList * specs = MkList();
11282 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11283 stmt.compound.statements = MkListOne(MkForStmt(
11284 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11285 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11286 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11287 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11288 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11291 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11292 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11293 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11295 /*else if(isCustomAVLTree)
11297 stmt.compound.statements = MkListOne(MkForStmt(
11298 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11299 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11300 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11301 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11304 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11305 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11306 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11310 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11311 MkIdentifier("Next")), null)), block));
11313 ProcessExpressionType(expIt);
11314 if(stmt.compound.declarations->first)
11315 ProcessDeclaration(stmt.compound.declarations->first);
11318 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11320 ProcessStatement(stmt);
11321 curContext = stmt.compound.context.parent;
11326 Compiler_Error($"Expression is not a container\n");
11339 if(stmt.expressions)
11341 for(exp = stmt.expressions->first; exp; exp = exp.next)
11345 if(curFunction && !curFunction.type)
11346 curFunction.type = ProcessType(
11347 curFunction.specifiers, curFunction.declarator);
11348 FreeType(exp.destType);
11349 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11350 if(exp.destType) exp.destType.refCount++;
11352 ProcessExpressionType(exp);
11357 case badDeclarationStmt:
11359 ProcessDeclaration(stmt.decl);
11365 if(stmt.asmStmt.inputFields)
11367 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11368 if(field.expression)
11369 ProcessExpressionType(field.expression);
11371 if(stmt.asmStmt.outputFields)
11373 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11374 if(field.expression)
11375 ProcessExpressionType(field.expression);
11377 if(stmt.asmStmt.clobberedFields)
11379 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11381 if(field.expression)
11382 ProcessExpressionType(field.expression);
11389 PropertyWatch propWatch;
11390 OldList * watches = stmt._watch.watches;
11391 Expression object = stmt._watch.object;
11392 Expression watcher = stmt._watch.watcher;
11394 ProcessExpressionType(watcher);
11396 ProcessExpressionType(object);
11400 if(watcher || thisClass)
11402 External external = curExternal;
11403 Context context = curContext;
11405 stmt.type = expressionStmt;
11406 stmt.expressions = MkList();
11408 curExternal = external.prev;
11410 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11412 ClassFunction func;
11413 char watcherName[1024];
11414 Class watcherClass = watcher ?
11415 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11416 External createdExternal;
11418 // Create a declaration above
11419 External externalDecl = MkExternalDeclaration(null);
11420 ast->Insert(curExternal.prev, externalDecl);
11422 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11423 if(propWatch.deleteWatch)
11424 strcat(watcherName, "_delete");
11428 for(propID = propWatch.properties->first; propID; propID = propID.next)
11430 strcat(watcherName, "_");
11431 strcat(watcherName, propID.string);
11435 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11437 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11438 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11439 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11440 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11441 ProcessClassFunctionBody(func, propWatch.compound);
11442 propWatch.compound = null;
11444 //afterExternal = afterExternal ? afterExternal : curExternal;
11446 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11447 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11449 createdExternal.symbol.idCode = external.symbol.idCode;
11451 curExternal = createdExternal;
11452 ProcessFunction(createdExternal.function);
11455 // Create a declaration above
11457 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11458 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11459 externalDecl.declaration = decl;
11460 if(decl.symbol && !decl.symbol.pointerExternal)
11461 decl.symbol.pointerExternal = externalDecl;
11464 if(propWatch.deleteWatch)
11466 OldList * args = MkList();
11467 ListAdd(args, CopyExpression(object));
11468 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11469 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11470 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11474 Class _class = object.expType._class.registered;
11477 for(propID = propWatch.properties->first; propID; propID = propID.next)
11479 char propName[1024];
11480 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11483 char getName[1024], setName[1024];
11484 OldList * args = MkList();
11486 DeclareProperty(prop, setName, getName);
11488 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11489 strcpy(propName, "__ecereProp_");
11490 FullClassNameCat(propName, prop._class.fullName, false);
11491 strcat(propName, "_");
11492 // strcat(propName, prop.name);
11493 FullClassNameCat(propName, prop.name, true);
11495 ListAdd(args, CopyExpression(object));
11496 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11497 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11498 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11500 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11503 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11508 Compiler_Error($"Invalid watched object\n");
11511 curExternal = external;
11512 curContext = context;
11515 FreeExpression(watcher);
11517 FreeExpression(object);
11518 FreeList(watches, FreePropertyWatch);
11521 Compiler_Error($"No observer specified and not inside a _class\n");
11525 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11527 ProcessStatement(propWatch.compound);
11533 case fireWatchersStmt:
11535 OldList * watches = stmt._watch.watches;
11536 Expression object = stmt._watch.object;
11538 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11539 // printf("%X\n", watches);
11540 // printf("%X\n", stmt._watch.watches);
11542 ProcessExpressionType(object);
11547 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11553 stmt.type = expressionStmt;
11554 stmt.expressions = MkList();
11556 // Check if we're inside a property set
11557 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11559 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
11563 //Compiler_Error($"No property specified and not inside a property set\n");
11567 for(propID = watches->first; propID; propID = propID.next)
11569 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11572 CreateFireWatcher(prop, object, stmt);
11575 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
11580 // Fire all properties!
11583 for(base = _class; base; base = base.base)
11585 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
11587 if(prop.isProperty && prop.isWatchable)
11589 CreateFireWatcher(prop, object, stmt);
11596 FreeExpression(object);
11597 FreeList(watches, FreeIdentifier);
11600 Compiler_Error($"Invalid object specified and not inside a class\n");
11604 case stopWatchingStmt:
11606 OldList * watches = stmt._watch.watches;
11607 Expression object = stmt._watch.object;
11608 Expression watcher = stmt._watch.watcher;
11611 ProcessExpressionType(object);
11613 ProcessExpressionType(watcher);
11616 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
11618 if(watcher || thisClass)
11624 stmt.type = expressionStmt;
11625 stmt.expressions = MkList();
11630 // eInstance_StopWatching(object, null, watcher);
11632 ListAdd(args, CopyExpression(object));
11633 ListAdd(args, MkExpConstant("0"));
11634 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11635 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11639 for(propID = watches->first; propID; propID = propID.next)
11641 char propName[1024];
11642 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11645 char getName[1024], setName[1024];
11646 OldList * args = MkList();
11648 DeclareProperty(prop, setName, getName);
11650 // eInstance_StopWatching(object, prop, watcher);
11651 strcpy(propName, "__ecereProp_");
11652 FullClassNameCat(propName, prop._class.fullName, false);
11653 strcat(propName, "_");
11654 // strcat(propName, prop.name);
11655 FullClassNameCat(propName, prop.name, true);
11656 MangleClassName(propName);
11658 ListAdd(args, CopyExpression(object));
11659 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11660 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11661 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11664 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11669 FreeExpression(object);
11671 FreeExpression(watcher);
11672 FreeList(watches, FreeIdentifier);
11675 Compiler_Error($"Invalid object specified and not inside a class\n");
11678 Compiler_Error($"No observer specified and not inside a class\n");
11685 static void ProcessFunction(FunctionDefinition function)
11687 Identifier id = GetDeclId(function.declarator);
11688 Symbol symbol = function.declarator ? function.declarator.symbol : null;
11689 Type type = symbol ? symbol.type : null;
11690 Class oldThisClass = thisClass;
11691 Context oldTopContext = topContext;
11693 yylloc = function.loc;
11694 // Process thisClass
11696 if(type && type.thisClass)
11698 Symbol classSym = type.thisClass;
11699 Class _class = type.thisClass.registered;
11700 char className[1024];
11701 char structName[1024];
11702 Declarator funcDecl;
11705 bool typedObject = false;
11707 if(_class && !_class.base)
11709 _class = currentClass;
11710 if(_class && !_class.symbol)
11711 _class.symbol = FindClass(_class.fullName);
11712 classSym = _class ? _class.symbol : null;
11713 typedObject = true;
11716 thisClass = _class;
11718 if(inCompiler && _class)
11720 if(type.kind == functionType)
11722 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
11724 //TypeName param = symbol.type.params.first;
11725 Type param = symbol.type.params.first;
11726 symbol.type.params.Remove(param);
11727 //FreeTypeName(param);
11730 if(type.classObjectType != classPointer)
11732 symbol.type.params.Insert(null, MkClassType(_class.fullName));
11733 symbol.type.staticMethod = true;
11734 symbol.type.thisClass = null;
11736 // HIGH DANGER: VERIFYING THIS...
11737 symbol.type.extraParam = false;
11741 strcpy(className, "__ecereClass_");
11742 FullClassNameCat(className, _class.fullName, true);
11744 MangleClassName(className);
11747 FullClassNameCat(structName, _class.fullName, false);
11752 funcDecl = GetFuncDecl(function.declarator);
11755 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11757 TypeName param = funcDecl.function.parameters->first;
11758 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11760 funcDecl.function.parameters->Remove(param);
11761 FreeTypeName(param);
11765 // DANGER: Watch for this... Check if it's a Conversion?
11766 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11768 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
11769 if(!function.propertyNoThis)
11771 TypeName thisParam;
11773 if(type.classObjectType != classPointer)
11775 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11776 if(!funcDecl.function.parameters)
11777 funcDecl.function.parameters = MkList();
11778 funcDecl.function.parameters->Insert(null, thisParam);
11783 if(type.classObjectType != classPointer)
11785 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
11786 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
11789 thisParam = TypeName
11791 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11792 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11794 funcDecl.function.parameters->Insert(null, thisParam);
11799 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11801 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11802 funcDecl = GetFuncDecl(initDecl.declarator);
11805 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11807 TypeName param = funcDecl.function.parameters->first;
11808 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11810 funcDecl.function.parameters->Remove(param);
11811 FreeTypeName(param);
11815 if(type.classObjectType != classPointer)
11817 // DANGER: Watch for this... Check if it's a Conversion?
11818 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11820 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11822 if(!funcDecl.function.parameters)
11823 funcDecl.function.parameters = MkList();
11824 funcDecl.function.parameters->Insert(null, thisParam);
11831 // Add this to the context
11834 if(type.classObjectType != classPointer)
11836 thisSymbol = Symbol
11838 string = CopyString("this");
11839 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
11841 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
11843 if(typedObject && thisSymbol.type)
11845 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
11846 thisSymbol.type.byReference = type.byReference;
11848 thisSymbol = Symbol { string = CopyString("class") };
11849 function.body.compound.context.symbols.Add(thisSymbol);
11855 // Pointer to class data
11857 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
11859 DataMember member = null;
11862 for(base = _class; base && base.type != systemClass; base = base.next)
11864 for(member = base.membersAndProperties.first; member; member = member.next)
11865 if(!member.isProperty)
11871 for(member = _class.membersAndProperties.first; member; member = member.next)
11872 if(!member.isProperty)
11876 char pointerName[1024];
11879 Initializer initializer;
11880 Expression exp, bytePtr;
11882 strcpy(pointerName, "__ecerePointer_");
11883 FullClassNameCat(pointerName, _class.fullName, false);
11885 char className[1024];
11886 strcpy(className, "__ecereClass_");
11887 FullClassNameCat(className, classSym.string, true);
11888 MangleClassName(className);
11891 DeclareClass(classSym, className);
11895 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
11900 sprintf(string, "%d", _class.offset);
11901 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
11905 // ([bytePtr] + [className]->offset)
11906 exp = QBrackets(MkExpOp(bytePtr, '+',
11907 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
11910 // (this ? [exp] : 0)
11911 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
11915 kind = pointerType;
11916 type = Type { refCount = 1, kind = voidType };
11921 yylloc = function.body.loc;
11922 // ([structName] *) [exp]
11923 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
11924 initializer = MkInitializerAssignment(
11925 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
11927 // [structName] * [pointerName] = [initializer];
11928 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
11931 Context prevContext = curContext;
11932 curContext = function.body.compound.context;
11934 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
11935 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
11937 curContext = prevContext;
11941 decl.symbol = null;
11943 if(!function.body.compound.declarations)
11944 function.body.compound.declarations = MkList();
11945 function.body.compound.declarations->Insert(null, decl);
11951 // Loop through the function and replace undeclared identifiers
11952 // which are a member of the class (methods, properties or data)
11953 // by "this.[member]"
11960 FreeSpecifier(id._class);
11963 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11965 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11966 id = GetDeclId(initDecl.declarator);
11968 FreeSpecifier(id._class);
11973 topContext = function.body.compound.context;
11975 FunctionDefinition oldFunction = curFunction;
11976 curFunction = function;
11978 ProcessStatement(function.body);
11980 // If this is a property set and no firewatchers has been done yet, add one here
11981 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
11983 Statement prevCompound = curCompound;
11984 Context prevContext = curContext;
11986 Statement fireWatchers = MkFireWatchersStmt(null, null);
11987 if(!function.body.compound.statements) function.body.compound.statements = MkList();
11988 ListAdd(function.body.compound.statements, fireWatchers);
11990 curCompound = function.body;
11991 curContext = function.body.compound.context;
11993 ProcessStatement(fireWatchers);
11995 curContext = prevContext;
11996 curCompound = prevCompound;
12000 curFunction = oldFunction;
12003 if(function.declarator)
12005 ProcessDeclarator(function.declarator);
12008 topContext = oldTopContext;
12009 thisClass = oldThisClass;
12012 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12013 static void ProcessClass(OldList definitions, Symbol symbol)
12016 External external = curExternal;
12017 Class regClass = symbol ? symbol.registered : null;
12019 // Process all functions
12020 for(def = definitions.first; def; def = def.next)
12022 if(def.type == functionClassDef)
12024 if(def.function.declarator)
12025 curExternal = def.function.declarator.symbol.pointerExternal;
12027 curExternal = external;
12029 ProcessFunction((FunctionDefinition)def.function);
12031 else if(def.type == declarationClassDef)
12033 if(def.decl.type == instDeclaration)
12035 thisClass = regClass;
12036 ProcessInstantiationType(def.decl.inst);
12042 Class backThisClass = thisClass;
12043 if(regClass) thisClass = regClass;
12044 ProcessDeclaration(def.decl);
12045 thisClass = backThisClass;
12048 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12050 MemberInit defProperty;
12052 // Add this to the context
12053 Symbol thisSymbol = Symbol
12055 string = CopyString("this");
12056 type = regClass ? MkClassType(regClass.fullName) : null;
12058 globalContext.symbols.Add((BTNode)thisSymbol);
12060 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12062 thisClass = regClass;
12063 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12067 globalContext.symbols.Remove((BTNode)thisSymbol);
12068 FreeSymbol(thisSymbol);
12070 else if(def.type == propertyClassDef && def.propertyDef)
12072 PropertyDef prop = def.propertyDef;
12074 // Add this to the context
12076 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12077 globalContext.symbols.Add(thisSymbol);
12080 thisClass = regClass;
12087 string = CopyString("this");
12088 type = MkClassType(regClass.fullName);
12090 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12093 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12094 ProcessStatement(prop.setStmt);
12102 string = CopyString("this");
12103 type = MkClassType(regClass.fullName);
12105 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12108 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12109 ProcessStatement(prop.getStmt);
12117 string = CopyString("this");
12118 type = MkClassType(regClass.fullName);
12120 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12123 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12124 ProcessStatement(prop.issetStmt);
12130 globalContext.symbols.Remove(thisSymbol);
12131 FreeSymbol(thisSymbol);
12134 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12136 PropertyWatch propertyWatch = def.propertyWatch;
12138 thisClass = regClass;
12139 if(propertyWatch.compound)
12143 string = CopyString("this");
12144 type = regClass ? MkClassType(regClass.fullName) : null;
12147 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12149 curExternal = null;
12150 ProcessStatement(propertyWatch.compound);
12157 void DeclareFunctionUtil(String s)
12159 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12164 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12165 strcpy(name, "__ecereFunction_");
12166 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12167 DeclareFunction(function, name);
12171 void ComputeDataTypes()
12175 External after = null;
12177 currentClass = null;
12179 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12181 for(external = ast->first; external; external = external.next)
12183 if(external.type == declarationExternal)
12185 Declaration decl = external.declaration;
12188 OldList * decls = decl.declarators;
12191 InitDeclarator initDecl = decls->first;
12194 Declarator declarator = initDecl.declarator;
12195 if(declarator && declarator.type == identifierDeclarator)
12197 Identifier id = declarator.identifier;
12198 if(id && id.string)
12200 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12202 external.symbol.id = -1001, external.symbol.idCode = -1001;
12213 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12214 ast->Insert(after, temp);
12215 curExternal = temp;
12217 DeclareFunctionUtil("eSystem_New");
12218 DeclareFunctionUtil("eSystem_New0");
12219 DeclareFunctionUtil("eSystem_Renew");
12220 DeclareFunctionUtil("eSystem_Renew0");
12221 DeclareFunctionUtil("eClass_GetProperty");
12223 DeclareStruct("ecere::com::Class", false);
12224 DeclareStruct("ecere::com::Instance", false);
12225 DeclareStruct("ecere::com::Property", false);
12226 DeclareStruct("ecere::com::DataMember", false);
12227 DeclareStruct("ecere::com::Method", false);
12228 DeclareStruct("ecere::com::SerialBuffer", false);
12229 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12233 for(external = ast->first; external; external = external.next)
12235 afterExternal = curExternal = external;
12236 if(external.type == functionExternal)
12238 currentClass = external.function._class;
12239 ProcessFunction(external.function);
12241 // There shouldn't be any _class member access here anyways...
12242 else if(external.type == declarationExternal)
12244 currentClass = null;
12245 ProcessDeclaration(external.declaration);
12247 else if(external.type == classExternal)
12249 ClassDefinition _class = external._class;
12250 currentClass = external.symbol.registered;
12251 if(_class.definitions)
12253 ProcessClass(_class.definitions, _class.symbol);
12257 // Free class data...
12258 ast->Remove(external);
12262 else if(external.type == nameSpaceExternal)
12264 thisNameSpace = external.id.string;
12267 currentClass = null;
12268 thisNameSpace = null;
12270 delete temp.symbol;