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;
3441 Type backupSourceExpType = null;
3443 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3446 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3448 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3450 Class sourceBase, destBase;
3451 for(sourceBase = source._class.registered;
3452 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3453 sourceBase = sourceBase.base);
3454 for(destBase = dest._class.registered;
3455 destBase && destBase.base && destBase.base.type != systemClass;
3456 destBase = destBase.base);
3457 //if(source._class.registered == dest._class.registered)
3458 if(sourceBase == destBase)
3467 int64 value = MAXINT;
3472 if(sourceExp.type == constantExp)
3475 value = strtoll(sourceExp.constant, null, 0);
3477 value = strtoull(sourceExp.constant, null, 0);
3479 else if(sourceExp.type == opExp && sourceExp.op.op == '-' && !sourceExp.op.exp1 && sourceExp.op.exp2 && sourceExp.op.exp2.type == constantExp)
3482 value = -strtoll(sourceExp.op.exp2.constant, null, 0);
3484 value = -strtoull(sourceExp.op.exp2.constant, null, 0);
3487 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3488 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3491 source = Type { kind = intType, isSigned = false, refCount = 1 };
3494 if(dest.kind == classType)
3496 Class _class = dest._class ? dest._class.registered : null;
3498 if(_class && _class.type == unitClass)
3500 if(source.kind != classType)
3503 Type tempDest, tempSource;
3505 for(; _class.base.type != systemClass; _class = _class.base);
3507 tempDest = tempType;
3509 tempType.kind = classType;
3511 _class.symbol = FindClass(_class.fullName);
3513 tempType._class = _class.symbol;
3514 tempType.truth = dest.truth;
3516 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3518 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3519 backupSourceExpType = sourceExp.expType;
3520 sourceExp.expType = dest; dest.refCount++;
3521 //sourceExp.expType = MkClassType(_class.fullName);
3529 // Why wasn't there something like this?
3530 if(_class && _class.type == bitClass && source.kind != classType)
3532 if(!dest._class.registered.dataType)
3533 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3534 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3537 FreeType(sourceExp.expType);
3538 source = sourceExp.expType = MkClassType(dest._class.string);
3541 //source.kind = classType;
3542 //source._class = dest._class;
3546 // Adding two enumerations
3548 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3550 if(!source._class.registered.dataType)
3551 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3552 if(!dest._class.registered.dataType)
3553 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3555 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3558 source = sourceExp.expType = MkClassType(dest._class.string);
3561 //source.kind = classType;
3562 //source._class = dest._class;
3566 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3568 OldList * specs = MkList();
3572 ReadString(string, sourceExp.string);
3573 decl = SpecDeclFromString(string, specs, null);
3575 FreeExpContents(sourceExp);
3576 FreeType(sourceExp.expType);
3578 sourceExp.type = classExp;
3579 sourceExp._classExp.specifiers = specs;
3580 sourceExp._classExp.decl = decl;
3581 sourceExp.expType = dest;
3586 if(backupSourceExpType) FreeType(backupSourceExpType);
3590 else if(source.kind == classType)
3592 Class _class = source._class ? source._class.registered : null;
3594 if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3597 if(dest.kind != classType)
3599 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3600 if(!source._class.registered.dataType)
3601 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3604 dest = MkClassType(source._class.string);
3605 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3606 // dest = MkClassType(source._class.string);
3610 if(dest.kind != classType)
3613 Type tempDest, tempSource;
3615 if(!source._class.registered.dataType)
3616 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3618 for(; _class.base.type != systemClass; _class = _class.base);
3620 tempSource = tempType;
3621 tempType.kind = classType;
3622 tempType._class = FindClass(_class.fullName);
3623 tempType.truth = source.truth;
3624 tempType.classObjectType = source.classObjectType;
3627 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3629 // PUT THIS BACK TESTING UNITS?
3630 if(conversions.last)
3632 ((Conversion)(conversions.last)).resultType = dest;
3636 FreeType(sourceExp.expType);
3637 sourceExp.expType = MkClassType(_class.fullName);
3638 sourceExp.expType.truth = source.truth;
3639 sourceExp.expType.classObjectType = source.classObjectType;
3641 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3643 if(!sourceExp.destType)
3645 FreeType(sourceExp.destType);
3646 sourceExp.destType = sourceExp.expType;
3647 if(sourceExp.expType)
3648 sourceExp.expType.refCount++;
3651 //source = _class.dataType;
3654 // TOCHECK: TESTING THIS NEW CODE
3655 if(!_class.dataType)
3656 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3658 dest = MkClassType(source._class.string);
3659 dest.truth = source.truth;
3660 dest.classObjectType = source.classObjectType;
3663 source = _class.dataType;
3673 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3683 if(source.kind == classType)
3685 Class _class = source._class.registered;
3686 if(_class.type == unitClass)
3688 if(!_class.dataType)
3689 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3690 source = _class.dataType;
3694 if(dest.kind == classType)
3696 Class _class = dest._class ? dest._class.registered : null;
3697 if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
3698 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3700 if(_class.type == normalClass || _class.type == noHeadClass)
3702 Expression newExp { };
3703 *newExp = *sourceExp;
3704 if(sourceExp.destType) sourceExp.destType.refCount++;
3705 if(sourceExp.expType) sourceExp.expType.refCount++;
3706 sourceExp.type = castExp;
3707 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3708 sourceExp.cast.exp = newExp;
3709 FreeType(sourceExp.expType);
3710 sourceExp.expType = null;
3711 ProcessExpressionType(sourceExp);
3713 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3716 FreeType(sourceExp.expType);
3717 sourceExp.expType = dest;
3721 if(inCompiler) FreeType(dest);
3723 if(backupSourceExpType) FreeType(backupSourceExpType);
3727 if(!_class.dataType)
3728 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3730 dest = _class.dataType;
3734 // Accept lower precision types for units, since we want to keep the unit type
3735 if(dest.kind == doubleType &&
3736 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3737 source.kind == charType))
3739 specs = MkListOne(MkSpecifier(DOUBLE));
3741 else if(dest.kind == floatType &&
3742 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3743 source.kind == doubleType))
3745 specs = MkListOne(MkSpecifier(FLOAT));
3747 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3748 source.kind == floatType || source.kind == doubleType))
3751 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3752 ListAdd(specs, MkSpecifier(INT64));
3754 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3755 source.kind == floatType || source.kind == doubleType))
3758 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3759 ListAdd(specs, MkSpecifier(INT));
3761 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == intType ||
3762 source.kind == floatType || source.kind == doubleType))
3765 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3766 ListAdd(specs, MkSpecifier(SHORT));
3768 else if(dest.kind == charType && (source.kind == charType || source.kind == shortType || source.kind == intType ||
3769 source.kind == floatType || source.kind == doubleType))
3772 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3773 ListAdd(specs, MkSpecifier(CHAR));
3779 if(backupSourceExpType)
3781 // Failed to convert: revert previous exp type
3782 if(sourceExp.expType) FreeType(sourceExp.expType);
3783 sourceExp.expType = backupSourceExpType;
3788 else if(dest.kind == doubleType &&
3789 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3790 source.kind == charType))
3792 specs = MkListOne(MkSpecifier(DOUBLE));
3794 else if(dest.kind == floatType &&
3795 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3797 specs = MkListOne(MkSpecifier(FLOAT));
3799 else if(dest.kind == charType && (source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3800 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3803 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3804 ListAdd(specs, MkSpecifier(CHAR));
3806 else if(dest.kind == shortType && (source.kind == enumType || source.kind == charType || source.kind == shortType ||
3807 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3810 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3811 ListAdd(specs, MkSpecifier(SHORT));
3813 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType))
3816 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3817 ListAdd(specs, MkSpecifier(INT));
3819 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3822 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3823 ListAdd(specs, MkSpecifier(INT64));
3825 else if(dest.kind == enumType &&
3826 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3828 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3834 if(backupSourceExpType)
3836 // Failed to convert: revert previous exp type
3837 if(sourceExp.expType) FreeType(sourceExp.expType);
3838 sourceExp.expType = backupSourceExpType;
3845 Expression newExp { };
3846 *newExp = *sourceExp;
3849 if(sourceExp.destType) sourceExp.destType.refCount++;
3850 if(sourceExp.expType) sourceExp.expType.refCount++;
3852 sourceExp.type = castExp;
3853 if(realDest.kind == classType)
3855 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3856 FreeList(specs, FreeSpecifier);
3859 sourceExp.cast.typeName = MkTypeName(specs, null);
3860 if(newExp.type == opExp)
3862 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3865 sourceExp.cast.exp = newExp;
3867 FreeType(sourceExp.expType);
3868 sourceExp.expType = null;
3869 ProcessExpressionType(sourceExp);
3872 FreeList(specs, FreeSpecifier);
3876 if(backupSourceExpType) FreeType(backupSourceExpType);
3882 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
3883 if(sourceExp.type == identifierExp)
3885 Identifier id = sourceExp.identifier;
3886 if(dest.kind == classType)
3888 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3890 Class _class = dest._class.registered;
3891 Class enumClass = eSystem_FindClass(privateModule, "enum");
3894 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
3897 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
3898 for(value = e.values.first; value; value = value.next)
3900 if(!strcmp(value.name, id.string))
3905 FreeExpContents(sourceExp);
3906 FreeType(sourceExp.expType);
3908 sourceExp.isConstant = true;
3909 sourceExp.expType = MkClassType(_class.fullName);
3913 sourceExp.type = constantExp;
3914 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
3915 sprintf(constant, "%d",value.data);
3917 sprintf(constant, "0x%X",value.data);
3918 sourceExp.constant = CopyString(constant);
3919 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
3928 // Loop through all enum classes
3929 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
3936 #define TERTIARY(o, name, m, t, p) \
3937 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
3939 exp.type = constantExp; \
3940 exp.string = p(op1.m ? op2.m : op3.m); \
3942 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3946 #define BINARY(o, name, m, t, p) \
3947 static bool name(Expression exp, Operand op1, Operand op2) \
3950 exp.type = constantExp; \
3951 exp.string = p(op1.m o value2); \
3953 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3957 #define BINARY_DIVIDE(o, name, m, t, p) \
3958 static bool name(Expression exp, Operand op1, Operand op2) \
3961 exp.type = constantExp; \
3962 exp.string = p(value2 ? (op1.m o value2) : 0); \
3964 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3968 #define UNARY(o, name, m, t, p) \
3969 static bool name(Expression exp, Operand op1) \
3971 exp.type = constantExp; \
3972 exp.string = p(o op1.m); \
3974 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3978 #define OPERATOR_ALL(macro, o, name) \
3979 macro(o, Int##name, i, int, PrintInt) \
3980 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
3981 macro(o, Short##name, s, short, PrintShort) \
3982 macro(o, UShort##name, us, unsigned short, PrintUShort) \
3983 macro(o, Char##name, c, char, PrintChar) \
3984 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
3985 macro(o, Float##name, f, float, PrintFloat) \
3986 macro(o, Double##name, d, double, PrintDouble)
3988 #define OPERATOR_INTTYPES(macro, o, name) \
3989 macro(o, Int##name, i, int, PrintInt) \
3990 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
3991 macro(o, Short##name, s, short, PrintShort) \
3992 macro(o, UShort##name, us, unsigned short, PrintUShort) \
3993 macro(o, Char##name, c, char, PrintChar) \
3994 macro(o, UChar##name, uc, unsigned char, PrintUChar)
3997 // binary arithmetic
3998 OPERATOR_ALL(BINARY, +, Add)
3999 OPERATOR_ALL(BINARY, -, Sub)
4000 OPERATOR_ALL(BINARY, *, Mul)
4001 OPERATOR_ALL(BINARY_DIVIDE, /, Div)
4002 OPERATOR_INTTYPES(BINARY_DIVIDE, %, Mod)
4005 OPERATOR_ALL(UNARY, -, Neg)
4007 // unary arithmetic increment and decrement
4008 OPERATOR_ALL(UNARY, ++, Inc)
4009 OPERATOR_ALL(UNARY, --, Dec)
4011 // binary arithmetic assignment
4012 OPERATOR_ALL(BINARY, =, Asign)
4013 OPERATOR_ALL(BINARY, +=, AddAsign)
4014 OPERATOR_ALL(BINARY, -=, SubAsign)
4015 OPERATOR_ALL(BINARY, *=, MulAsign)
4016 OPERATOR_ALL(BINARY_DIVIDE, /=, DivAsign)
4017 OPERATOR_INTTYPES(BINARY_DIVIDE, %=, ModAsign)
4020 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4021 OPERATOR_INTTYPES(BINARY, |, BitOr)
4022 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4023 OPERATOR_INTTYPES(BINARY, <<, LShift)
4024 OPERATOR_INTTYPES(BINARY, >>, RShift)
4027 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4029 // binary bitwise assignment
4030 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4031 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4032 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4033 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4034 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4036 // unary logical negation
4037 OPERATOR_INTTYPES(UNARY, !, Not)
4039 // binary logical equality
4040 OPERATOR_ALL(BINARY, ==, Equ)
4041 OPERATOR_ALL(BINARY, !=, Nqu)
4044 OPERATOR_ALL(BINARY, &&, And)
4045 OPERATOR_ALL(BINARY, ||, Or)
4047 // binary logical relational
4048 OPERATOR_ALL(BINARY, >, Grt)
4049 OPERATOR_ALL(BINARY, <, Sma)
4050 OPERATOR_ALL(BINARY, >=, GrtEqu)
4051 OPERATOR_ALL(BINARY, <=, SmaEqu)
4053 // tertiary condition operator
4054 OPERATOR_ALL(TERTIARY, ?, Cond)
4056 //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
4057 #define OPERATOR_TABLE_ALL(name, type) \
4058 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4060 type##Inc, type##Dec, \
4061 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4062 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4064 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4066 type##Equ, type##Nqu, \
4067 type##And, type##Or, \
4068 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4071 #define OPERATOR_TABLE_INTTYPES(name, type) \
4072 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4074 type##Inc, type##Dec, \
4075 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4076 null, null, null, null, null, \
4078 null, null, null, null, null, \
4080 type##Equ, type##Nqu, \
4081 type##And, type##Or, \
4082 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4085 OPERATOR_TABLE_ALL(int, Int)
4086 OPERATOR_TABLE_ALL(uint, UInt)
4087 OPERATOR_TABLE_ALL(short, Short)
4088 OPERATOR_TABLE_ALL(ushort, UShort)
4089 OPERATOR_TABLE_INTTYPES(float, Float)
4090 OPERATOR_TABLE_INTTYPES(double, Double)
4091 OPERATOR_TABLE_ALL(char, Char)
4092 OPERATOR_TABLE_ALL(uchar, UChar)
4094 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4095 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4096 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4097 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4098 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4099 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4100 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4101 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4103 public void ReadString(char * output, char * string)
4105 int len = strlen(string);
4107 bool quoted = false, escaped = false;
4108 for(c = 0; c<len; c++)
4110 char ch = string[c];
4115 case 'n': output[d] = '\n'; break;
4116 case 't': output[d] = '\t'; break;
4117 case 'a': output[d] = '\a'; break;
4118 case 'b': output[d] = '\b'; break;
4119 case 'f': output[d] = '\f'; break;
4120 case 'r': output[d] = '\r'; break;
4121 case 'v': output[d] = '\v'; break;
4122 case '\\': output[d] = '\\'; break;
4123 case '\"': output[d] = '\"'; break;
4124 default: output[d++] = '\\'; output[d] = ch;
4125 //default: output[d] = ch;
4146 public Operand GetOperand(Expression exp)
4149 Type type = exp.expType;
4152 while(type.kind == classType &&
4153 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4155 if(!type._class.registered.dataType)
4156 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4157 type = type._class.registered.dataType;
4160 op.kind = type.kind;
4161 op.type = exp.expType;
4162 if(exp.isConstant && exp.type == constantExp)
4168 if(exp.constant[0] == '\'')
4169 op.c = exp.constant[1];
4170 else if(type.isSigned)
4172 op.c = (char)strtol(exp.constant, null, 0);
4177 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4185 op.s = (short)strtol(exp.constant, null, 0);
4190 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4198 op.i = (int)strtol(exp.constant, null, 0);
4203 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4211 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4216 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4224 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4229 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4237 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4242 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4248 op.f = (float)strtod(exp.constant, null);
4252 op.d = (double)strtod(exp.constant, null);
4255 //case classType: For when we have operator overloading...
4256 // Pointer additions
4257 //case functionType:
4261 op.ui64 = _strtoui64(exp.constant, null, 0);
4262 op.kind = pointerType;
4272 static void UnusedFunction()
4275 a.OnGetString(0,0,0);
4278 extern int __ecereVMethodID_class_OnGetString;
4281 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4283 DataMember dataMember;
4284 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4286 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4287 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4291 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4293 void * ptr = inst.data + dataMember.offset + offset;
4294 char * result = null;
4295 exp.loc = member.loc = inst.loc;
4296 ((Identifier)member.identifiers->first).loc = inst.loc;
4298 if(!dataMember.dataType)
4299 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4300 type = dataMember.dataType;
4301 if(type.kind == classType)
4303 Class _class = type._class.registered;
4304 if(_class.type == enumClass)
4306 Class enumClass = eSystem_FindClass(privateModule, "enum");
4309 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4311 for(item = e.values.first; item; item = item.next)
4313 if((int)item.data == *(int *)ptr)
4321 exp.identifier = MkIdentifier(result);
4322 exp.type = identifierExp;
4323 exp.destType = MkClassType(_class.fullName);
4324 ProcessExpressionType(exp);
4328 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4330 if(!_class.dataType)
4331 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4332 type = _class.dataType;
4341 FreeExpContents(exp);
4343 exp.constant = PrintFloat(*(float*)ptr);
4344 exp.type = constantExp;
4349 FreeExpContents(exp);
4351 exp.constant = PrintDouble(*(double*)ptr);
4352 exp.type = constantExp;
4357 FreeExpContents(exp);
4359 exp.constant = PrintInt(*(int*)ptr);
4360 exp.type = constantExp;
4365 FreeExpContents(exp);
4367 exp.constant = PrintInt64(*(int64*)ptr);
4368 exp.type = constantExp;
4373 FreeExpContents(exp);
4374 // TODO: This should probably use proper type
4375 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4376 exp.type = constantExp;
4381 FreeExpContents(exp);
4382 // TODO: This should probably use proper type
4383 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4384 exp.type = constantExp;
4388 Compiler_Error($"Unhandled type populating instance\n");
4391 ListAdd(memberList, member);
4394 if(parentDataMember.type == unionMember)
4399 void PopulateInstance(Instantiation inst)
4401 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4402 Class _class = classSym.registered;
4403 DataMember dataMember;
4404 OldList * memberList = MkList();
4405 inst.members = MkListOne(MkMembersInitList(memberList));
4406 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4408 if(!dataMember.isProperty)
4410 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4411 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4415 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4417 void * ptr = inst.data + dataMember.offset;
4418 char * result = null;
4420 exp.loc = member.loc = inst.loc;
4421 ((Identifier)member.identifiers->first).loc = inst.loc;
4423 if(!dataMember.dataType)
4424 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4425 type = dataMember.dataType;
4426 if(type.kind == classType)
4428 Class _class = type._class.registered;
4429 if(_class.type == enumClass)
4431 Class enumClass = eSystem_FindClass(privateModule, "enum");
4434 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4436 for(item = e.values.first; item; item = item.next)
4438 if((int)item.data == *(int *)ptr)
4447 exp.identifier = MkIdentifier(result);
4448 exp.type = identifierExp;
4449 exp.destType = MkClassType(_class.fullName);
4450 ProcessExpressionType(exp);
4453 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4455 if(!_class.dataType)
4456 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4457 type = _class.dataType;
4466 exp.constant = PrintFloat(*(float*)ptr);
4467 exp.type = constantExp;
4472 exp.constant = PrintDouble(*(double*)ptr);
4473 exp.type = constantExp;
4478 exp.constant = PrintInt(*(int*)ptr);
4479 exp.type = constantExp;
4484 exp.constant = PrintInt64(*(int64*)ptr);
4485 exp.type = constantExp;
4490 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4491 exp.type = constantExp;
4495 Compiler_Error($"Unhandled type populating instance\n");
4498 ListAdd(memberList, member);
4504 void ComputeInstantiation(Expression exp)
4506 Instantiation inst = exp.instance;
4507 MembersInit members;
4508 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4509 Class _class = classSym ? classSym.registered : null;
4510 DataMember curMember = null;
4511 Class curClass = null;
4512 DataMember subMemberStack[256];
4513 int subMemberStackPos = 0;
4516 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4518 // Don't recompute the instantiation...
4519 // Non Simple classes will have become constants by now
4523 if(_class.type == normalClass || _class.type == noHeadClass)
4524 inst.data = (byte *)eInstance_New(_class);
4526 inst.data = new0 byte[_class.structSize];
4531 for(members = inst.members->first; members; members = members.next)
4533 switch(members.type)
4535 case dataMembersInit:
4537 if(members.dataMembers)
4540 for(member = members.dataMembers->first; member; member = member.next)
4542 Identifier ident = member.identifiers ? member.identifiers->first : null;
4545 Property prop = null;
4546 DataMember dataMember = null;
4547 Method method = null;
4548 uint dataMemberOffset;
4552 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4555 if(curMember.isProperty)
4556 prop = (Property)curMember;
4559 dataMember = curMember;
4561 // CHANGED THIS HERE
4562 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4563 // dataMemberOffset = dataMember.offset;
4570 prop = eClass_FindProperty(_class, ident.string, privateModule);
4574 if(prop.memberAccess == publicAccess)
4576 curMember = (DataMember)prop;
4577 curClass = prop._class;
4582 DataMember _subMemberStack[256];
4583 int _subMemberStackPos = 0;
4585 // FILL MEMBER STACK
4586 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4591 if(dataMember.memberAccess == publicAccess)
4593 curMember = dataMember;
4594 curClass = dataMember._class;
4595 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
4596 subMemberStackPos = _subMemberStackPos;
4602 if(found && member.initializer && member.initializer.type == expInitializer)
4604 Expression value = member.initializer.exp;
4608 type = prop.dataType;
4612 if(!dataMember.dataType)
4613 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4615 type = dataMember.dataType;
4618 if(ident && ident.next)
4620 // for(; ident && type; ident = ident.next)
4621 for(ident = ident.next; ident && type; ident = ident.next)
4623 if(type.kind == classType)
4625 prop = eClass_FindProperty(type._class.registered,
4626 ident.string, privateModule);
4628 type = prop.dataType;
4631 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4632 ident.string, &dataMemberOffset, privateModule, null, null);
4634 type = dataMember.dataType;
4637 else if(type.kind == structType || type.kind == unionType)
4640 for(memberType = type.members.first; memberType; memberType = memberType.next)
4642 if(!strcmp(memberType.name, ident.string))
4653 FreeType(value.destType);
4654 value.destType = type;
4655 if(type) type.refCount++;
4656 ComputeExpression(value);
4658 if(value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4660 if(type.kind == classType)
4662 Class _class = type._class.registered;
4663 if(_class.type == bitClass || _class.type == unitClass ||
4664 _class.type == enumClass)
4666 if(!_class.dataType)
4667 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4668 type = _class.dataType;
4674 void * ptr = inst.data + dataMemberOffset;
4676 if(value.type == constantExp)
4682 GetInt(value, (int*)ptr);
4687 GetInt64(value, (int64*)ptr);
4692 GetIntPtr(value, (intptr*)ptr);
4697 GetIntSize(value, (intsize*)ptr);
4702 GetFloat(value, (float*)ptr);
4707 GetDouble(value, (double *)ptr);
4712 else if(value.type == instanceExp)
4714 if(type.kind == classType)
4716 Class _class = type._class.registered;
4717 if(_class.type == structClass)
4719 ComputeTypeSize(type);
4720 if(value.instance.data)
4721 memcpy(ptr, value.instance.data, type.size);
4728 if(value.type == instanceExp && value.instance.data)
4730 void (*Set)(void *, void *) = (void *)prop.Set;
4731 Set(inst.data, value.instance.data);
4732 PopulateInstance(inst);
4734 else if(value.type == constantExp)
4740 void (*Set)(void *, double) = (void *)prop.Set;
4741 Set(inst.data, strtod(value.constant, null) );
4746 void (*Set)(void *, float) = (void *)prop.Set;
4747 Set(inst.data, (float)(strtod(value.constant, null)));
4752 void (*Set)(void *, int) = (void *)prop.Set;
4753 Set(inst.data, strtol(value.constant, null, 0));
4758 void (*Set)(void *, int64) = (void *)prop.Set;
4759 Set(inst.data, _strtoi64(value.constant, null, 0));
4764 void (*Set)(void *, intptr) = (void *)prop.Set;
4765 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
4770 void (*Set)(void *, intsize) = (void *)prop.Set;
4771 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
4776 else if(value.type == stringExp)
4779 ReadString(temp, value.string);
4780 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
4784 else if(_class.type == unitClass)
4788 // Only support converting units to units for now...
4789 if(value.type == constantExp)
4791 if(type.kind == classType)
4793 Class _class = type._class.registered;
4794 if(_class.type == unitClass)
4796 if(!_class.dataType)
4797 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4798 type = _class.dataType;
4801 // TODO: Assuming same base type for units...
4807 float (*Set)(float) = (void *)prop.Set;
4808 GetFloat(member.initializer.exp, &fValue);
4809 exp.constant = PrintFloat(Set(fValue));
4810 exp.type = constantExp;
4816 double (*Set)(double) = (void *)prop.Set;
4817 GetDouble(member.initializer.exp, &dValue);
4818 exp.constant = PrintDouble(Set(dValue));
4819 exp.type = constantExp;
4826 else if(_class.type == bitClass)
4830 if(value.type == instanceExp && value.instance.data)
4832 unsigned int (*Set)(void *) = (void *)prop.Set;
4833 bits = Set(value.instance.data);
4835 else if(value.type == constantExp)
4841 BitMember bitMember = (BitMember) dataMember;
4844 GetInt(value, &part);
4845 bits = (bits & ~bitMember.mask);
4846 if(!bitMember.dataType)
4847 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
4849 type = bitMember.dataType;
4851 if(type.kind == classType && type._class && type._class.registered)
4853 if(!type._class.registered.dataType)
4854 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4855 type = type._class.registered.dataType;
4862 bits |= ((char)part << bitMember.pos);
4864 bits |= ((unsigned char)part << bitMember.pos);
4868 bits |= ((short)part << bitMember.pos);
4870 bits |= ((unsigned short)part << bitMember.pos);
4875 bits |= ((int)part << bitMember.pos);
4877 bits |= ((unsigned int)part << bitMember.pos);
4881 bits |= ((int64)part << bitMember.pos);
4883 bits |= ((uint64)part << bitMember.pos);
4888 bits |= ((intptr)part << bitMember.pos);
4892 bits |= ((uintptr)part << bitMember.pos);
4898 bits |= ((ssize_t)(intsize)part << bitMember.pos);
4902 bits |= ((size_t) (uintsize)part << bitMember.pos);
4911 if(_class && _class.type == unitClass)
4913 ComputeExpression(member.initializer.exp);
4914 exp.constant = member.initializer.exp.constant;
4915 exp.type = constantExp;
4917 member.initializer.exp.constant = null;
4927 if(_class && _class.type == bitClass)
4929 exp.constant = PrintHexUInt(bits);
4930 exp.type = constantExp;
4932 if(exp.type != instanceExp)
4938 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
4940 if(exp.op.op == SIZEOF)
4942 FreeExpContents(exp);
4943 exp.type = constantExp;
4944 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
4955 // Provide default unary +
4956 Expression exp2 = exp.op.exp2;
4958 FreeExpContents(exp);
4959 FreeType(exp.expType);
4960 FreeType(exp.destType);
4966 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
4968 // unary arithmetic increment and decrement
4969 //OPERATOR_ALL(UNARY, ++, Inc)
4970 //OPERATOR_ALL(UNARY, --, Dec)
4973 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
4975 // unary logical negation
4977 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
4985 // binary arithmetic
4987 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
4990 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
4993 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
4996 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
4999 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5001 // binary arithmetic assignment
5002 //OPERATOR_ALL(BINARY, =, Asign)
5003 //OPERATOR_ALL(BINARY, +=, AddAsign)
5004 //OPERATOR_ALL(BINARY, -=, SubAsign)
5005 //OPERATOR_ALL(BINARY, *=, MulAsign)
5006 //OPERATOR_ALL(BINARY, /=, DivAsign)
5007 //OPERATOR_ALL(BINARY, %=, ModAsign)
5012 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5016 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5019 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5022 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5025 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5027 // binary bitwise assignment
5028 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5029 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5030 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5031 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5032 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5033 // binary logical equality
5035 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5038 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5042 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5045 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5047 // binary logical relational
5049 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5052 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5055 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5058 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5065 void ComputeExpression(Expression exp)
5067 char expString[10240];
5068 expString[0] = '\0';
5070 PrintExpression(exp, expString);
5077 ComputeInstantiation(exp);
5086 Expression exp1, exp2 = null;
5090 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5092 ComputeExpression(exp.op.exp2);
5095 ComputeExpression(exp.op.exp1);
5098 op1 = GetOperand(exp1);
5099 if(op1.type) op1.type.refCount++;
5102 op2 = GetOperand(exp2);
5103 if(op2.type) op2.type.refCount++;
5109 op1 = GetOperand(exp1);
5110 if(op1.type) op1.type.refCount++;
5113 CallOperator(exp, exp1, exp2, op1, op2);
5120 if(exp.op.exp1 && exp.op.exp2)
5125 FreeExpContents(exp);
5126 op1.ops.BitAnd(exp, op1, op2);
5135 FreeExpContents(exp);
5136 op1.ops.Mul(exp, op1, op2);
5145 FreeExpContents(exp);
5146 op1.ops.Add(exp, op1, op2);
5151 // Provide default unary +
5152 Expression exp2 = exp.op.exp2;
5154 FreeExpContents(exp);
5155 FreeType(exp.expType);
5156 FreeType(exp.destType);
5167 FreeExpContents(exp);
5168 op1.ops.Sub(exp, op1, op2);
5175 FreeExpContents(exp);
5176 op1.ops.Neg(exp, op1);
5183 FreeExpContents(exp);
5184 op1.ops.BitNot(exp, op1);
5190 FreeExpContents(exp);
5191 op1.ops.Not(exp, op1);
5194 // Binary only operators
5198 FreeExpContents(exp);
5199 op1.ops.Div(exp, op1, op2);
5205 FreeExpContents(exp);
5206 op1.ops.Mod(exp, op1, op2);
5218 FreeExpContents(exp);
5219 op1.ops.Sma(exp, op1, op2);
5228 FreeExpContents(exp);
5229 op1.ops.Grt(exp, op1, op2);
5238 FreeExpContents(exp);
5239 op1.ops.SmaEqu(exp, op1, op2);
5248 FreeExpContents(exp);
5249 op1.ops.GrtEqu(exp, op1, op2);
5258 FreeExpContents(exp);
5259 op1.ops.Equ(exp, op1, op2);
5268 FreeExpContents(exp);
5269 op1.ops.Nqu(exp, op1, op2);
5276 FreeExpContents(exp);
5277 op1.ops.BitOr(exp, op1, op2);
5283 FreeExpContents(exp);
5284 op1.ops.BitXor(exp, op1, op2);
5292 FreeExpContents(exp);
5293 exp.type = constantExp;
5294 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5298 if(op1.type) FreeType(op1.type);
5299 if(op2.type) FreeType(op2.type);
5303 case extensionExpressionExp:
5306 for(e = exp.list->first; e; e = n)
5311 OldList * list = exp.list;
5312 ComputeExpression(e);
5313 //FreeExpContents(exp);
5314 FreeType(exp.expType);
5315 FreeType(exp.destType);
5332 exp.isConstant = true;
5334 ComputeExpression(exp.index.exp);
5335 if(!exp.index.exp.isConstant)
5336 exp.isConstant = false;
5338 for(e = exp.index.index->first; e; e = e.next)
5340 ComputeExpression(e);
5343 // Check if this type is int
5346 exp.isConstant = false;
5348 exp.expType = Dereference(exp.index.exp.expType);
5354 Expression memberExp = exp.member.exp;
5355 Identifier memberID = exp.member.member;
5358 ComputeExpression(exp.member.exp);
5359 type = exp.member.exp.expType;
5362 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);
5363 Property prop = null;
5364 DataMember member = null;
5365 Class convertTo = null;
5366 if(type.kind == subClassType && exp.member.exp.type == classExp)
5367 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5374 PrintType(type, string, false, true);
5375 classSym = FindClass(string);
5376 _class = classSym ? classSym.registered : null;
5379 if(exp.member.member)
5381 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5383 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5385 if(!prop && !member && _class && exp.member.member)
5387 Symbol classSym = FindClass(exp.member.member.string);
5389 _class = classSym ? classSym.registered : null;
5390 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5397 Type type = prop.dataType;
5398 // TODO: Assuming same base type for units...
5399 if(_class.type == unitClass)
5401 if(type.kind == classType)
5403 Class _class = type._class.registered;
5404 if(_class.type == unitClass)
5406 if(!_class.dataType)
5407 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5408 type = _class.dataType;
5416 float (*Get)(float) = (void *)prop.Get;
5417 GetFloat(exp.member.exp, &value);
5418 exp.constant = PrintFloat(Get ? Get(value) : value);
5419 exp.type = constantExp;
5425 double (*Get)(double);
5426 GetDouble(exp.member.exp, &value);
5429 Get = (void *)prop.Set;
5431 Get = (void *)prop.Get;
5432 exp.constant = PrintDouble(Get ? Get(value) : value);
5433 exp.type = constantExp;
5442 Expression value = exp.member.exp;
5445 ProcessPropertyType(prop);
5447 type = prop.dataType;
5450 // printf("Investigate this\n");
5452 else if(_class.type == structClass)
5458 Class propertyClass = type._class.registered;
5459 if(propertyClass.type == structClass && value.type == instanceExp)
5461 void (*Set)(void *, void *) = (void *)prop.Set;
5462 exp.instance = Instantiation { };
5463 exp.instance.data = new0 byte[_class.structSize];
5464 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5465 exp.instance.loc = exp.loc;
5466 exp.type = instanceExp;
5467 Set(exp.instance.data, value.instance.data);
5468 PopulateInstance(exp.instance);
5475 void (*Set)(void *, int) = (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 GetInt(value, &intValue);
5485 Set(exp.instance.data, intValue);
5486 PopulateInstance(exp.instance);
5492 void (*Set)(void *, int64) = (void *)prop.Set;
5494 exp.instance = Instantiation { };
5495 exp.instance.data = new0 byte[_class.structSize];
5496 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5497 exp.instance.loc = exp.loc;
5498 exp.type = instanceExp;
5500 GetInt64(value, &intValue);
5502 Set(exp.instance.data, intValue);
5503 PopulateInstance(exp.instance);
5510 void (*Set)(void *, intptr) = (void *)prop.Set;
5512 exp.instance = Instantiation { };
5513 exp.instance.data = new0 byte[_class.structSize];
5514 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5515 exp.instance.loc = exp.loc;
5516 exp.type = instanceExp;
5518 GetIntPtr(value, &intValue);
5520 Set(exp.instance.data, intValue);
5521 PopulateInstance(exp.instance);
5528 void (*Set)(void *, intsize) = (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 GetIntSize(value, &intValue);
5538 Set(exp.instance.data, intValue);
5539 PopulateInstance(exp.instance);
5545 void (*Set)(void *, double) = (void *)prop.Set;
5547 exp.instance = Instantiation { };
5548 exp.instance.data = new0 byte[_class.structSize];
5549 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5550 exp.instance.loc = exp.loc;
5551 exp.type = instanceExp;
5553 GetDouble(value, &doubleValue);
5555 Set(exp.instance.data, doubleValue);
5556 PopulateInstance(exp.instance);
5561 else if(_class.type == bitClass)
5567 Class propertyClass = type._class.registered;
5568 if(propertyClass.type == structClass && value.instance.data)
5570 unsigned int (*Set)(void *) = (void *)prop.Set;
5571 unsigned int bits = Set(value.instance.data);
5572 exp.constant = PrintHexUInt(bits);
5573 exp.type = constantExp;
5576 else if(_class.type == bitClass)
5579 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5582 GetUInt(exp.member.exp, &value);
5584 exp.constant = PrintHexUInt(bits);
5585 exp.type = constantExp;
5593 if(_class.type == bitClass)
5596 GetUInt(exp.member.exp, &value);
5602 Class _class = type._class.registered;
5603 if(_class.type == structClass)
5605 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5607 exp.instance = Instantiation { };
5608 exp.instance.data = new0 byte[_class.structSize];
5609 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5610 exp.instance.loc = exp.loc;
5611 //exp.instance.fullSet = true;
5612 exp.type = instanceExp;
5613 Get(value, exp.instance.data);
5614 PopulateInstance(exp.instance);
5616 else if(_class.type == bitClass)
5618 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5619 uint64 bits = Get(value);
5620 exp.constant = PrintHexUInt64(bits);
5621 exp.type = constantExp;
5627 else if(_class.type == structClass)
5629 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5634 Class _class = type._class.registered;
5635 if(_class.type == structClass && value)
5637 void (*Get)(void *, void *) = (void *)prop.Get;
5639 exp.instance = Instantiation { };
5640 exp.instance.data = new0 byte[_class.structSize];
5641 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5642 exp.instance.loc = exp.loc;
5643 //exp.instance.fullSet = true;
5644 exp.type = instanceExp;
5645 Get(value, exp.instance.data);
5646 PopulateInstance(exp.instance);
5654 char * value = exp.member.exp.instance.data;
5659 Class _class = type._class.registered;
5660 if(_class.type == normalClass)
5662 void *(*Get)(void *) = (void *)prop.Get;
5664 exp.instance = Instantiation { };
5665 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5666 exp.type = instanceExp;
5667 exp.instance.data = Get(value, exp.instance.data);
5679 exp.isConstant = false;
5687 if(exp.type != ExpressionType::memberExp)
5689 FreeExpression(memberExp);
5690 FreeIdentifier(memberID);
5696 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5697 FreeExpContents(exp);
5698 exp.constant = PrintUInt(ComputeTypeSize(type));
5699 exp.type = constantExp;
5705 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5706 if(classSym && classSym.registered)
5708 if(classSym.registered.fixed)
5710 FreeSpecifier(exp._class);
5711 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5712 exp.type = constantExp;
5716 char className[1024];
5717 strcpy(className, "__ecereClass_");
5718 FullClassNameCat(className, classSym.string, true);
5719 MangleClassName(className);
5721 FreeExpContents(exp);
5722 exp.type = pointerExp;
5723 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5724 exp.member.member = MkIdentifier("structSize");
5734 if(exp.type == castExp)
5737 ComputeExpression(exp.cast.exp);
5740 if(e && exp.expType)
5743 type = exp.destType;
5746 if(type.kind == classType)
5748 Class _class = type._class.registered;
5749 if(_class && (_class.type == unitClass || _class.type == bitClass))
5751 if(!_class.dataType)
5752 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5753 type = _class.dataType;
5764 FreeExpContents(exp);
5765 exp.constant = PrintChar(value);
5766 exp.type = constantExp;
5770 unsigned char value;
5771 GetUChar(e, &value);
5772 FreeExpContents(exp);
5773 exp.constant = PrintUChar(value);
5774 exp.type = constantExp;
5781 GetShort(e, &value);
5782 FreeExpContents(exp);
5783 exp.constant = PrintShort(value);
5784 exp.type = constantExp;
5788 unsigned short value;
5789 GetUShort(e, &value);
5790 FreeExpContents(exp);
5791 exp.constant = PrintUShort(value);
5792 exp.type = constantExp;
5800 FreeExpContents(exp);
5801 exp.constant = PrintInt(value);
5802 exp.type = constantExp;
5808 FreeExpContents(exp);
5809 exp.constant = PrintUInt(value);
5810 exp.type = constantExp;
5817 GetInt64(e, &value);
5818 FreeExpContents(exp);
5819 exp.constant = PrintInt64(value);
5820 exp.type = constantExp;
5825 GetUInt64(e, &value);
5826 FreeExpContents(exp);
5827 exp.constant = PrintUInt64(value);
5828 exp.type = constantExp;
5835 GetIntPtr(e, &value);
5836 FreeExpContents(exp);
5837 exp.constant = PrintInt64((int64)value);
5838 exp.type = constantExp;
5843 GetUIntPtr(e, &value);
5844 FreeExpContents(exp);
5845 exp.constant = PrintUInt64((uint64)value);
5846 exp.type = constantExp;
5853 GetIntSize(e, &value);
5854 FreeExpContents(exp);
5855 exp.constant = PrintInt64((int64)value);
5856 exp.type = constantExp;
5861 GetUIntSize(e, &value);
5862 FreeExpContents(exp);
5863 exp.constant = PrintUInt64((uint64)value);
5864 exp.type = constantExp;
5870 GetFloat(e, &value);
5871 FreeExpContents(exp);
5872 exp.constant = PrintFloat(value);
5873 exp.type = constantExp;
5879 GetDouble(e, &value);
5880 FreeExpContents(exp);
5881 exp.constant = PrintDouble(value);
5882 exp.type = constantExp;
5896 // Caring only about last expression for now...
5897 ComputeExpression(exp.cond.exp->last);
5898 if(exp.cond.elseExp)
5899 ComputeExpression(exp.cond.elseExp);
5901 ComputeExpression(exp.cond.cond);
5903 op1 = GetOperand(exp.cond.cond);
5904 if(op1.type) op1.type.refCount++;
5905 op2 = GetOperand(exp.cond.exp->last);
5906 if(op2.type) op2.type.refCount++;
5907 op3 = GetOperand(exp.cond.elseExp);
5908 if(op3.type) op3.type.refCount++;
5910 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
5911 if(op1.type) FreeType(op1.type);
5912 if(op2.type) FreeType(op2.type);
5913 if(op3.type) FreeType(op3.type);
5919 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
5924 OldList converts { };
5927 if(destType.kind == voidType)
5930 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
5934 // for(convert = converts.last; convert; convert = convert.prev)
5935 for(convert = converts.first; convert; convert = convert.next)
5937 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
5940 Expression newExp { };
5941 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
5943 // TODO: Check this...
5945 newExp.destType = null;
5950 exp.type = memberExp;
5951 exp.addedThis = true;
5952 exp.member.exp = newExp;
5953 FreeType(exp.member.exp.expType);
5955 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
5956 exp.member.exp.expType.classObjectType = objectType;
5957 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
5958 exp.member.memberType = propertyMember;
5959 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
5960 // TESTING THIS... for (int)degrees
5961 exp.needCast = true;
5962 if(exp.expType) exp.expType.refCount++;
5963 ApplyAnyObjectLogic(exp.member.exp);
5968 /*if(exp.isConstant)
5970 // Color { ColorRGB = [exp] };
5971 exp.type = instanceExp;
5972 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
5973 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
5974 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
5978 // If not constant, don't turn it yet into an instantiation
5979 // (Go through the deep members system first)
5980 exp.type = memberExp;
5981 exp.addedThis = true;
5982 exp.member.exp = newExp;
5984 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
5985 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
5986 newExp.expType._class.registered.type == noHeadClass)
5988 newExp.byReference = true;
5991 FreeType(exp.member.exp.expType);
5992 /*exp.member.exp.expType = convert.convert.dataType;
5993 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
5994 exp.member.exp.expType = null;
5995 if(convert.convert.dataType)
5997 exp.member.exp.expType = { };
5998 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
5999 exp.member.exp.expType.refCount = 1;
6000 exp.member.exp.expType.classObjectType = objectType;
6001 ApplyAnyObjectLogic(exp.member.exp);
6004 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6005 exp.member.memberType = reverseConversionMember;
6006 exp.expType = convert.resultType ? convert.resultType :
6007 MkClassType(convert.convert._class.fullName);
6008 exp.needCast = true;
6009 if(convert.resultType) convert.resultType.refCount++;
6015 FreeType(exp.expType);
6018 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6019 exp.needCast = true;
6020 if(exp.expType) exp.expType.refCount++;
6024 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6025 exp.needCast = true;
6026 if(convert.resultType)
6027 convert.resultType.refCount++;
6031 if(exp.isConstant && inCompiler)
6032 ComputeExpression(exp);
6034 converts.Free(FreeConvert);
6037 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6039 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6041 if(!result && exp.expType && exp.destType)
6043 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6044 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6045 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6046 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6050 // if(result) CheckTemplateTypes(exp);
6054 void CheckTemplateTypes(Expression exp)
6056 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6058 Expression newExp { };
6062 if(exp.destType) exp.destType.refCount++;
6063 if(exp.expType) exp.expType.refCount++;
6067 switch(exp.expType.kind)
6070 if(exp.destType.classObjectType)
6072 // We need to pass the address, just pass it along (Undo what was done above)
6073 if(exp.destType) exp.destType.refCount--;
6074 if(exp.expType) exp.expType.refCount--;
6079 // If we're looking for value:
6080 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6082 OldList * unionDefs = MkList();
6083 OldList * statements = MkList();
6084 context = PushContext();
6085 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6086 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6087 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6088 exp.type = extensionCompoundExp;
6089 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6090 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6091 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6092 exp.compound.compound.context = context;
6093 PopContext(context);
6098 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6099 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6103 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6105 Expression newExp { };
6109 if(exp.destType) exp.destType.refCount++;
6110 if(exp.expType) exp.expType.refCount++;
6114 switch(exp.expType.kind)
6117 if(exp.destType.classObjectType)
6119 // We need to pass the address, just pass it along (Undo what was done above)
6120 if(exp.destType) exp.destType.refCount--;
6121 if(exp.expType) exp.expType.refCount--;
6126 // If we're looking for value:
6127 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6129 OldList * unionDefs = MkList();
6130 OldList * statements = MkList();
6131 context = PushContext();
6132 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6133 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6134 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6135 exp.type = extensionCompoundExp;
6136 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6137 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6138 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6139 exp.compound.compound.context = context;
6140 PopContext(context);
6145 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6147 exp.type = bracketsExp;
6148 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6149 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6150 ProcessExpressionType(exp.list->first);
6155 exp.type = bracketsExp;
6156 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6157 newExp.needCast = true;
6158 ProcessExpressionType(exp.list->first);
6164 if(exp.expType.kind == templateType)
6166 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6169 FreeType(exp.destType);
6170 FreeType(exp.expType);
6175 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6180 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6181 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6185 char typeString[1024];
6187 OldList * specs = MkList();
6188 typeString[0] = '\0';
6189 PrintType(exp.expType, typeString, false, false);
6190 decl = SpecDeclFromString(typeString, specs, null);
6193 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6194 exp.cast.typeName = MkTypeName(specs, decl);
6195 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6196 exp.cast.exp.needCast = true;
6203 // TODO: The Symbol tree should be reorganized by namespaces
6205 // - Tree of all symbols within (stored without namespace)
6206 // - Tree of sub-namespaces
6208 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6210 int nsLen = strlen(nameSpace);
6212 // Start at the name space prefix
6213 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6215 char * s = symbol.string;
6216 if(!strncmp(s, nameSpace, nsLen))
6218 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6221 for(c = strlen(s)-1; c >= 0; c--)
6226 if(!strcmp(namePart, name))
6228 // TODO: Error on ambiguity
6238 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6241 char nameSpace[1024];
6243 bool gotColon = false;
6245 nameSpace[0] = '\0';
6246 for(c = strlen(name)-1; c >= 0; c--)
6253 namePart = name+c+1;
6254 while(c >= 0 && name[c] == ':') c--;
6257 // Try an exact match first
6258 Symbol symbol = (Symbol)tree.FindString(name);
6262 // Namespace specified
6263 memcpy(nameSpace, name, c + 1);
6266 return ScanWithNameSpace(tree, nameSpace, namePart);
6270 // Looking for a global symbol, e.g. ::Sleep()
6271 Symbol symbol = (Symbol)tree.FindString(namePart);
6276 // Name only (no namespace specified)
6277 Symbol symbol = (Symbol)tree.FindString(namePart);
6280 return ScanWithNameSpace(tree, "", namePart);
6285 static void ProcessDeclaration(Declaration decl);
6287 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6290 //Time startTime = GetTime();
6292 // Optimize this later? Do this before/less?
6294 Symbol symbol = null;
6295 // First, check if the identifier is declared inside the function
6296 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6298 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6300 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6306 strcpy(curName, thisNameSpace);
6307 strcat(curName, "::");
6308 strcat(curName, name);
6309 // Try to resolve in current namespace first
6310 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6313 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6316 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6318 if(symbol || ctx == endContext) break;
6320 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6322 if(symbol.pointerExternal.type == functionExternal)
6324 FunctionDefinition function = symbol.pointerExternal.function;
6326 // Modified this recently...
6327 Context tmpContext = curContext;
6329 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6330 curContext = tmpContext;
6332 symbol.pointerExternal.symbol = symbol;
6335 DeclareType(symbol.type, true, true);
6337 ast->Insert(curExternal.prev, symbol.pointerExternal);
6339 symbol.id = curExternal.symbol.idCode;
6342 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6344 ast->Move(symbol.pointerExternal, curExternal.prev);
6345 symbol.id = curExternal.symbol.idCode;
6349 //findSymbolTotalTime += GetTime() - startTime;
6354 static void GetTypeSpecs(Type type, OldList * specs)
6356 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6361 if(type._class.registered)
6363 if(!type._class.registered.dataType)
6364 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6365 GetTypeSpecs(type._class.registered.dataType, specs);
6369 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6370 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6371 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6372 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6373 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6374 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6375 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6378 ListAdd(specs, MkSpecifier(INT)); break;
6382 // WARNING : This function expects a null terminated string since it recursively concatenate...
6383 static void _PrintType(Type type, char * string, bool printName, bool printFunction, bool fullName)
6390 if(type._class && type._class.string)
6392 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6393 // look into merging with thisclass ?
6394 if(type.classObjectType == typedObject)
6395 strcat(string, "typed_object");
6397 strcat(string, type._class.string);
6400 if(type._class.registered)
6401 strcat(string, type._class.registered.name);
6403 strcat(string, type._class.string);
6410 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6411 if(funcType && funcType.kind == functionType)
6414 PrintType(funcType.returnType, string, false, fullName);
6415 strcat(string, "(*");
6416 if(printName || funcType.thisClass)
6418 strcat(string, " ");
6419 if(funcType.thisClass)
6421 strcat(string, funcType.thisClass.string);
6422 strcat(string, "::");
6425 strcat(string, type.name);
6427 strcat(string, ")(");
6428 for(param = funcType.params.first; param; param = param.next)
6430 PrintType(param, string, false, fullName);
6431 if(param.next) strcat(string, ", ");
6433 strcat(string, ")");
6437 _PrintType(type.type, string, false /*printName*/, printFunction, fullName);
6438 strcat(string, " *");
6442 case voidType: strcat(string, "void"); break;
6443 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6444 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6445 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6446 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6447 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6448 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6449 case floatType: strcat(string, "float"); break;
6450 case doubleType: strcat(string, "double"); break;
6454 strcat(string, "struct ");
6455 strcat(string, type.enumName);
6457 else if(type.typeName)
6459 strcat(string, type.typeName);
6464 strcat(string, "struct ");
6465 strcat(string,"(unnamed)");
6468 strcat(string, "struct {");
6469 for(member = type.members.first; member; member = member.next)
6471 PrintType(member, string, true, fullName);
6472 strcat(string,"; ");
6480 strcat(string, "union ");
6481 strcat(string, type.enumName);
6483 else if(type.typeName)
6485 strcat(string, type.typeName);
6489 strcat(string, "union ");
6490 strcat(string,"(unnamed)");
6496 strcat(string, "enum ");
6497 strcat(string, type.enumName);
6499 else if(type.typeName)
6501 strcat(string, type.typeName);
6504 strcat(string, "enum");
6511 strcat(string, "dllexport ");
6512 PrintType(type.returnType, string, false, fullName);
6513 strcat(string, " ");
6516 // DANGER: Testing This
6522 strcat(string, type.name);
6525 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6526 if(name) name += 2; else name = type.name;
6527 strcat(string, name);
6535 strcat(string, "(");
6536 for(param = type.params.first; param; param = param.next)
6538 PrintType(param, string, true, fullName);
6539 if(param.next) strcat(string, ", ");
6541 strcat(string, ")");
6548 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6549 if(funcType && funcType.kind == functionType)
6552 PrintType(funcType.returnType, string, false, fullName);
6553 strcat(string, "(*");
6554 if(printName || funcType.thisClass)
6556 strcat(string, " ");
6557 if(funcType.thisClass)
6559 strcat(string, funcType.thisClass.string);
6560 strcat(string, "::");
6563 strcat(string, type.name);
6565 strcat(string, ")(");
6566 for(param = funcType.params.first; param; param = param.next)
6568 PrintType(param, string, false, fullName);
6569 if(param.next) strcat(string, ", ");
6571 strcat(string, ")");
6575 char baseType[1024], size[256];
6576 Type arrayType = type;
6580 while(arrayType.kind == TypeKind::arrayType)
6583 if(arrayType.enumClass)
6584 strcat(size, arrayType.enumClass.string);
6585 else if(arrayType.arraySizeExp)
6586 PrintExpression(arrayType.arraySizeExp, size);
6587 //sprintf(string, "%s[%s]", baseType, size);
6590 arrayType = arrayType.arrayType;
6592 _PrintType(arrayType, baseType, printName, printFunction, fullName);
6593 strcat(string, baseType);
6594 strcat(string, size);
6598 PrintType(type.arrayType, baseType, printName, fullName);
6600 strcpy(size, type.enumClass.string);
6601 else if(type.arraySizeExp)
6602 PrintExpression(type.arraySizeExp, size);
6603 //sprintf(string, "%s[%s]", baseType, size);
6604 strcat(string, baseType);
6605 strcat(string, "[");
6606 strcat(string, size);
6607 strcat(string, "]");
6614 strcat(string, "...");
6617 _PrintType(type.method.dataType, string, false, printFunction, fullName);
6620 strcat(string, "subclass(");
6621 strcat(string, type._class ? type._class.string : "int");
6622 strcat(string, ")");
6625 strcat(string, type.templateParameter.identifier.string);
6628 strcat(string, "thisclass");
6631 strcat(string, "__builtin_va_list");
6634 if(type.name && printName && type.kind != functionType && (type.kind != pointerType || type.type.kind != functionType))
6636 strcat(string, " ");
6637 strcat(string, type.name);
6643 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6645 void PrintType(Type type, char * string, bool printName, bool fullName)
6648 for(funcType = type; funcType && (funcType.kind == pointerType || funcType.kind == arrayType); funcType = funcType.type);
6649 if(funcType && funcType.kind == functionType && type != funcType)
6651 char typeString[1024];
6654 PrintType(funcType.returnType, string, false, fullName);
6655 strcat(string, "(");
6656 _PrintType(type, string, printName, false, fullName);
6657 strcat(string, ")");
6659 strcat(string, "(");
6660 for(param = funcType.params.first; param; param = param.next)
6662 PrintType(param, string, true, fullName);
6663 if(param.next) strcat(string, ", ");
6665 strcat(string, ")");
6668 _PrintType(type, string, printName, true, fullName);
6669 if(type.bitFieldCount)
6672 sprintf(count, ":%d", type.bitFieldCount);
6673 strcat(string, count);
6677 static Type FindMember(Type type, char * string)
6680 for(memberType = type.members.first; memberType; memberType = memberType.next)
6682 if(!memberType.name)
6684 Type subType = FindMember(memberType, string);
6688 else if(!strcmp(memberType.name, string))
6694 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6697 for(memberType = type.members.first; memberType; memberType = memberType.next)
6699 if(!memberType.name)
6701 Type subType = FindMember(memberType, string);
6704 *offset += memberType.offset;
6708 else if(!strcmp(memberType.name, string))
6710 *offset += memberType.offset;
6717 Expression ParseExpressionString(char * expression)
6719 fileInput = TempFile { };
6720 fileInput.Write(expression, 1, strlen(expression));
6721 fileInput.Seek(0, start);
6724 parsedExpression = null;
6726 expression_yyparse();
6729 return parsedExpression;
6732 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6734 Identifier id = exp.identifier;
6735 Method method = null;
6736 Property prop = null;
6737 DataMember member = null;
6738 ClassProperty classProp = null;
6740 if(_class && _class.type == enumClass)
6742 NamedLink value = null;
6743 Class enumClass = eSystem_FindClass(privateModule, "enum");
6747 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6749 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6750 for(value = e.values.first; value; value = value.next)
6752 if(!strcmp(value.name, id.string))
6759 FreeExpContents(exp);
6761 exp.type = constantExp;
6762 exp.isConstant = true;
6763 if(!strcmp(baseClass.dataTypeString, "int"))
6764 sprintf(constant, "%d",value.data);
6766 sprintf(constant, "0x%X",value.data);
6767 exp.constant = CopyString(constant);
6768 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6769 exp.expType = MkClassType(baseClass.fullName);
6777 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6779 ProcessMethodType(method);
6786 // TOCHECK: Put it back to what it was...
6787 // methodClass = _class;
6788 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6793 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
6796 ProcessPropertyType(prop);
6797 exp.expType = prop.dataType;
6798 if(prop.dataType) prop.dataType.refCount++;
6801 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
6803 if(!member.dataType)
6804 member.dataType = ProcessTypeString(member.dataTypeString, false);
6805 exp.expType = member.dataType;
6806 if(member.dataType) member.dataType.refCount++;
6809 else if((classProp = eClass_FindClassProperty(_class, id.string)))
6811 if(!classProp.dataType)
6812 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
6814 if(classProp.constant)
6816 FreeExpContents(exp);
6818 exp.isConstant = true;
6819 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
6821 //char constant[256];
6822 exp.type = stringExp;
6823 exp.constant = QMkString((char *)classProp.Get(_class));
6828 exp.type = constantExp;
6829 sprintf(constant, "%d", (int)classProp.Get(_class));
6830 exp.constant = CopyString(constant);
6838 exp.expType = classProp.dataType;
6839 if(classProp.dataType) classProp.dataType.refCount++;
6845 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
6847 BinaryTree * tree = &nameSpace.functions;
6848 GlobalData data = (GlobalData)tree->FindString(name);
6852 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
6854 data = ScanGlobalData(child, name);
6862 static GlobalData FindGlobalData(char * name)
6865 NameSpace * nameSpace;
6866 nameSpace = globalData;
6867 for(c = 0; name[c]; c++)
6869 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
6871 NameSpace * newSpace;
6872 char * spaceName = new char[c - start + 1];
6873 strncpy(spaceName, name + start, c - start);
6874 spaceName[c-start] = '\0';
6875 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
6879 nameSpace = newSpace;
6880 if(name[c] == ':') c++;
6886 return ScanGlobalData(nameSpace, name + start);
6891 static int definedExpStackPos;
6892 static void * definedExpStack[512];
6894 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
6895 void ReplaceExpContents(Expression checkedExp, Expression newExp)
6897 Expression prev = checkedExp.prev, next = checkedExp.next;
6899 FreeExpContents(checkedExp);
6900 FreeType(checkedExp.expType);
6901 FreeType(checkedExp.destType);
6903 *checkedExp = *newExp;
6907 checkedExp.prev = prev;
6908 checkedExp.next = next;
6911 void ApplyAnyObjectLogic(Expression e)
6913 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
6914 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
6916 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
6917 //ellipsisDestType = destType;
6920 Type type = e.expType;
6921 Class _class = null;
6922 //Type destType = e.destType;
6924 if(type.kind == classType && type._class && type._class.registered)
6926 _class = type._class.registered;
6928 else if(type.kind == subClassType)
6930 _class = FindClass("ecere::com::Class").registered;
6934 char string[1024] = "";
6937 PrintType(type, string, false, true);
6938 classSym = FindClass(string);
6939 if(classSym) _class = classSym.registered;
6942 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...
6943 (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
6944 destType.byReference)))
6946 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
6948 Expression checkedExp = e, newExp;
6950 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6952 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6954 if(checkedExp.type == extensionCompoundExp)
6956 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6959 checkedExp = checkedExp.list->last;
6961 else if(checkedExp.type == castExp)
6962 checkedExp = checkedExp.cast.exp;
6965 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
6967 newExp = checkedExp.op.exp2;
6968 checkedExp.op.exp2 = null;
6969 FreeExpContents(checkedExp);
6971 if(e.expType && e.expType.passAsTemplate)
6974 ComputeTypeSize(e.expType);
6975 sprintf(size, "%d", e.expType.size);
6976 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
6977 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
6978 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
6981 ReplaceExpContents(checkedExp, newExp);
6982 e.byReference = true;
6984 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
6986 Expression checkedExp, newExp;
6989 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
6991 e.type == identifierExp ||
6992 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
6993 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
6994 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
6997 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
6999 Context context = PushContext();
7001 OldList * specs = MkList();
7002 char typeString[1024];
7003 Expression newExp { };
7005 typeString[0] = '\0';
7008 //if(e.destType) e.destType.refCount++;
7009 // if(exp.expType) exp.expType.refCount++;
7012 newExp.expType = null;
7014 PrintType(e.expType, typeString, false, true);
7015 decl = SpecDeclFromString(typeString, specs, null);
7016 newExp.destType = ProcessType(specs, decl);
7018 curContext = context;
7019 e.type = extensionCompoundExp;
7021 // We need a current compound for this
7025 OldList * stmts = MkList();
7026 sprintf(name, "__internalValue%03X", internalValueCounter++);
7027 if(!curCompound.compound.declarations)
7028 curCompound.compound.declarations = MkList();
7029 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7030 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7031 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7032 e.compound = MkCompoundStmt(null, stmts);
7035 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7038 e.compound = MkCompoundStmt(
7039 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7040 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7042 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7046 Type type = e.destType;
7048 CopyTypeInto(e.destType, type);
7049 e.destType.refCount = 1;
7050 e.destType.classObjectType = none;
7054 e.compound.compound.context = context;
7055 PopContext(context);
7056 curContext = context.parent;
7060 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7062 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7064 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7066 if(checkedExp.type == extensionCompoundExp)
7068 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7071 checkedExp = checkedExp.list->last;
7073 else if(checkedExp.type == castExp)
7074 checkedExp = checkedExp.cast.exp;
7077 Expression operand { };
7078 operand = *checkedExp;
7079 checkedExp.destType = null;
7080 checkedExp.expType = null;
7082 checkedExp.type = opExp;
7083 checkedExp.op.op = '&';
7084 checkedExp.op.exp1 = null;
7085 checkedExp.op.exp2 = operand;
7087 //newExp = MkExpOp(null, '&', checkedExp);
7089 //ReplaceExpContents(checkedExp, newExp);
7096 // If expression type is a simple class, make it an address
7097 // FixReference(e, true);
7100 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7101 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7102 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7104 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
7106 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7110 Expression thisExp { };
7113 thisExp.prev = null;
7114 thisExp.next = null;
7117 e.type = bracketsExp;
7118 e.list = MkListOne(MkExpOp(null, '*', MkExpBrackets(MkListOne(thisExp))));
7119 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7120 ((Expression)e.list->first).byReference = true;
7122 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7124 e.expType = thisExp.expType;
7125 e.expType.refCount++;
7130 CopyTypeInto(e.expType, thisExp.expType);
7131 e.expType.byReference = false;
7132 e.expType.refCount = 1;
7134 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7135 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7137 e.expType.classObjectType = none;
7142 // TOFIX: Try this for a nice IDE crash!
7144 // The other way around
7147 if(destType && e.expType &&
7148 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7149 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7150 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7152 if(destType.kind == ellipsisType)
7154 Compiler_Error($"Unspecified type\n");
7156 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7158 bool byReference = e.expType.byReference;
7159 Expression thisExp { };
7161 OldList * specs = MkList();
7162 char typeString[1024]; // Watch buffer overruns
7164 ClassObjectType backupClassObjectType;
7166 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7171 backupClassObjectType = type.classObjectType;
7173 type.classObjectType = none;
7175 typeString[0] = '\0';
7176 PrintType(type, typeString, false, true);
7177 decl = SpecDeclFromString(typeString, specs, null);
7179 type.classObjectType = backupClassObjectType;
7182 thisExp.prev = null;
7183 thisExp.next = null;
7186 if( ( type.kind == classType && type._class && type._class.registered && strcmp(type._class.registered.fullName, "ecere::com::Instance") &&
7187 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7188 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7189 (type.kind != pointerType && type.kind != arrayType && type.kind != classType) ||
7190 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7195 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7200 e.cast.typeName = MkTypeName(specs, decl);
7201 e.cast.exp = thisExp;
7202 e.byReference = true;
7205 e.destType = destType;
7207 destType.refCount++;
7212 void ProcessExpressionType(Expression exp)
7214 bool unresolved = false;
7215 Location oldyylloc = yylloc;
7216 bool notByReference = false;
7218 char debugExpString[4096];
7219 debugExpString[0] = '\0';
7220 PrintExpression(exp, debugExpString);
7222 if(!exp || exp.expType)
7225 //eSystem_Logf("%s\n", expString);
7227 // Testing this here
7233 Identifier id = exp.identifier;
7236 // DOING THIS LATER NOW...
7237 if(id._class && id._class.name)
7239 id.classSym = id._class.symbol; // FindClass(id._class.name);
7240 /* TODO: Name Space Fix ups
7242 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7246 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7248 exp.expType = ProcessTypeString("Module", true);
7251 else */if(strstr(id.string, "__ecereClass") == id.string)
7253 exp.expType = ProcessTypeString("ecere::com::Class", true);
7256 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7258 // Added this here as well
7259 ReplaceClassMembers(exp, thisClass);
7260 if(exp.type != identifierExp)
7262 ProcessExpressionType(exp);
7266 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7271 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7272 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7273 if(!symbol/* && exp.destType*/)
7275 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7281 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7282 if(exp.type != identifierExp)
7284 ProcessExpressionType(exp);
7288 // Static methods called from inside the _class
7289 else if(currentClass && !id._class)
7291 if(ResolveIdWithClass(exp, currentClass, true))
7294 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7298 // If we manage to resolve this symbol
7301 Type type = symbol.type;
7302 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7304 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7306 Context context = SetupTemplatesContext(_class);
7307 type = ReplaceThisClassType(_class);
7308 FinishTemplatesContext(context);
7309 if(type) type.refCount = 0; // We'll be incrementing it right below...
7312 FreeSpecifier(id._class);
7315 id.string = CopyString(symbol.string);
7321 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7322 // Add missing cases here... enum Classes...
7323 exp.isConstant = true;
7325 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7326 if(symbol.isParam || !strcmp(id.string, "this"))
7328 if(_class && _class.type == structClass)
7329 exp.byReference = true;
7331 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7332 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7333 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7334 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7336 Identifier id = exp.identifier;
7337 exp.type = bracketsExp;
7338 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7342 if(symbol.isIterator)
7344 if(symbol.isIterator == 3)
7346 exp.type = bracketsExp;
7347 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7348 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7350 ProcessExpressionType(exp);
7352 else if(symbol.isIterator != 4)
7354 exp.type = memberExp;
7355 exp.member.exp = MkExpIdentifier(exp.identifier);
7356 exp.member.exp.expType = exp.expType;
7357 /*if(symbol.isIterator == 6)
7358 exp.member.member = MkIdentifier("key");
7360 exp.member.member = MkIdentifier("data");
7362 ProcessExpressionType(exp);
7369 DefinedExpression definedExp = null;
7370 if(thisNameSpace && !(id._class && !id._class.name))
7373 strcpy(name, thisNameSpace);
7375 strcat(name, id.string);
7376 definedExp = eSystem_FindDefine(privateModule, name);
7379 definedExp = eSystem_FindDefine(privateModule, id.string);
7383 for(c = 0; c<definedExpStackPos; c++)
7384 if(definedExpStack[c] == definedExp)
7386 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7388 Location backupYylloc = yylloc;
7389 definedExpStack[definedExpStackPos++] = definedExp;
7390 fileInput = TempFile { };
7391 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7392 fileInput.Seek(0, start);
7395 parsedExpression = null;
7397 expression_yyparse();
7400 yylloc = backupYylloc;
7402 if(parsedExpression)
7405 exp.type = bracketsExp;
7406 exp.list = MkListOne(parsedExpression);
7407 parsedExpression.loc = yylloc;
7408 ProcessExpressionType(exp);
7409 definedExpStackPos--;
7412 definedExpStackPos--;
7418 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7424 GlobalData data = null;
7425 if(thisNameSpace && !(id._class && !id._class.name))
7428 strcpy(name, thisNameSpace);
7430 strcat(name, id.string);
7431 data = FindGlobalData(name);
7434 data = FindGlobalData(id.string);
7437 DeclareGlobalData(data);
7438 exp.expType = data.dataType;
7439 if(data.dataType) data.dataType.refCount++;
7442 id.string = CopyString(data.fullName);
7443 FreeSpecifier(id._class);
7450 GlobalFunction function = null;
7451 if(thisNameSpace && !(id._class && !id._class.name))
7454 strcpy(name, thisNameSpace);
7456 strcat(name, id.string);
7457 function = eSystem_FindFunction(privateModule, name);
7460 function = eSystem_FindFunction(privateModule, id.string);
7465 id.string = CopyString(function.name);
7468 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7469 strcpy(name, "__ecereFunction_");
7470 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7471 if(DeclareFunction(function, name))
7474 id.string = CopyString(name);
7476 exp.expType = function.dataType;
7477 if(function.dataType) function.dataType.refCount++;
7479 FreeSpecifier(id._class);
7496 if(!exp.instance._class)
7498 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7500 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7504 //classSym = FindClass(exp.instance._class.fullName);
7505 //_class = classSym ? classSym.registered : null;
7507 ProcessInstantiationType(exp.instance);
7508 exp.isConstant = exp.instance.isConstant;
7511 if(_class.type == unitClass && _class.base.type != systemClass)
7514 Type destType = exp.destType;
7516 exp.destType = MkClassType(_class.base.fullName);
7517 exp.expType = MkClassType(_class.fullName);
7518 CheckExpressionType(exp, exp.destType, true);
7520 exp.destType = destType;
7522 exp.expType = MkClassType(_class.fullName);
7525 if(exp.instance._class)
7527 exp.expType = MkClassType(exp.instance._class.name);
7528 /*if(exp.expType._class && exp.expType._class.registered &&
7529 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7530 exp.expType.byReference = true;*/
7545 if(exp.constant[0] == '\'')
7547 if((int)((byte *)exp.constant)[1] > 127)
7550 unichar ch = UTF8GetChar(exp.constant + 1, &nb);
7551 if(nb < 2) ch = exp.constant[1];
7552 delete exp.constant;
7553 exp.constant = PrintUInt(ch);
7554 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7555 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7556 type._class = FindClass("unichar");
7558 type.isSigned = false;
7562 type.kind = charType;
7563 type.isSigned = true;
7566 else if(strchr(exp.constant, '.'))
7568 char ch = exp.constant[strlen(exp.constant)-1];
7570 type.kind = floatType;
7572 type.kind = doubleType;
7573 type.isSigned = true;
7577 if(exp.constant[0] == '0' && exp.constant[1])
7578 type.isSigned = false;
7579 else if(strchr(exp.constant, 'L') || strchr(exp.constant, 'l'))
7580 type.isSigned = false;
7581 else if(strtoll(exp.constant, null, 0) > MAXINT)
7582 type.isSigned = false;
7584 type.isSigned = true;
7585 type.kind = intType;
7587 exp.isConstant = true;
7593 exp.isConstant = true; // Why wasn't this constant?
7609 ProcessExpressionType(exp._new.size);
7614 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7616 DeclareType(exp.expType.type, false, false);
7620 ProcessExpressionType(exp._renew.size);
7621 ProcessExpressionType(exp._renew.exp);
7626 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7628 DeclareType(exp.expType.type, false, false);
7632 bool assign = false, boolResult = false, boolOps = false;
7633 Type type1 = null, type2 = null;
7634 bool useDestType = false, useSideType = false;
7635 Location oldyylloc = yylloc;
7636 bool useSideUnit = false;
7638 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7647 // Assignment Operators
7661 // boolean Operators
7663 // Expect boolean operators
7665 //boolResult = true;
7669 // Expect boolean operands
7680 // Gives boolean result
7688 // Just added these... testing
7693 // DANGER: Verify units
7698 if(exp.op.op != '*' || exp.op.exp1)
7705 /*// Implement speed etc.
7711 if(exp.op.op == '&')
7713 // Added this here earlier for Iterator address as key
7714 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7716 Identifier id = exp.op.exp2.identifier;
7717 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7718 if(symbol && symbol.isIterator == 2)
7720 exp.type = memberExp;
7721 exp.member.exp = exp.op.exp2;
7722 exp.member.member = MkIdentifier("key");
7724 exp.op.exp2.expType = symbol.type;
7725 symbol.type.refCount++;
7726 ProcessExpressionType(exp);
7730 // exp.op.exp2.usage.usageRef = true;
7734 //dummy.kind = TypeDummy;
7738 if(exp.destType && exp.destType.kind == classType &&
7739 exp.destType._class && exp.destType._class.registered && useDestType &&
7741 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
7742 exp.destType._class.registered.type == enumClass ||
7743 exp.destType._class.registered.type == bitClass
7746 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
7748 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7749 exp.op.exp1.destType = exp.destType;
7751 exp.destType.refCount++;
7755 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7756 exp.op.exp1.destType = dummy;
7760 // TESTING THIS HERE...
7761 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
7762 ProcessExpressionType(exp.op.exp1);
7763 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
7765 if(exp.op.exp1.destType == dummy)
7768 exp.op.exp1.destType = null;
7770 type1 = exp.op.exp1.expType;
7775 char expString[10240];
7776 expString[0] = '\0';
7777 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
7781 exp.op.exp2.destType = exp.op.exp1.expType;
7782 if(exp.op.exp1.expType)
7783 exp.op.exp1.expType.refCount++;
7787 exp.op.exp2.destType = exp.destType;
7789 exp.destType.refCount++;
7792 if(type1) type1.refCount++;
7793 exp.expType = type1;
7798 PrintExpression(exp.op.exp2, expString);
7800 if(type1 && type1.kind == pointerType)
7802 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 ||
7803 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
7804 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
7805 else if(exp.op.op == '=')
7807 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7808 exp.op.exp2.destType = type1;
7815 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
7816 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/* ||
7817 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
7820 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7821 exp.op.exp2.destType = type1;
7826 if(type1) type1.refCount++;
7827 exp.expType = type1;
7829 else if(exp.destType && exp.destType.kind == classType &&
7830 exp.destType._class && exp.destType._class.registered &&
7832 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
7833 (exp.destType._class.registered.type == enumClass && useDestType))
7836 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7837 exp.op.exp2.destType = exp.destType;
7839 exp.destType.refCount++;
7843 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7844 exp.op.exp2.destType = dummy;
7848 // TESTING THIS HERE... (DANGEROUS)
7849 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
7850 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
7852 FreeType(exp.op.exp2.destType);
7853 exp.op.exp2.destType = type1;
7856 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
7857 ProcessExpressionType(exp.op.exp2);
7858 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
7860 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
7862 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)
7864 if(exp.op.op != '=' && type1.type.kind == voidType)
7865 Compiler_Error($"void *: unknown size\n");
7867 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||
7868 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
7869 (exp.op.exp2.expType._class.registered.type == normalClass ||
7870 exp.op.exp2.expType._class.registered.type == structClass ||
7871 exp.op.exp2.expType._class.registered.type == noHeadClass)))
7873 if(exp.op.op == ADD_ASSIGN)
7874 Compiler_Error($"cannot add two pointers\n");
7876 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
7877 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
7879 if(exp.op.op == ADD_ASSIGN)
7880 Compiler_Error($"cannot add two pointers\n");
7884 char type1String[1024];
7885 char type2String[1024];
7886 type1String[0] = '\0';
7887 type2String[0] = '\0';
7889 PrintType(exp.op.exp2.expType, type1String, false, true);
7890 PrintType(type1, type2String, false, true);
7891 ChangeCh(expString, '\n', ' ');
7892 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
7896 if(exp.op.exp2.destType == dummy)
7899 exp.op.exp2.destType = null;
7902 type2 = exp.op.exp2.expType;
7905 dummy.kind = voidType;
7907 if(exp.op.op == SIZEOF)
7914 exp.isConstant = true;
7916 // Get type of dereferenced pointer
7917 else if(exp.op.op == '*' && !exp.op.exp1)
7919 exp.expType = Dereference(type2);
7920 if(type2 && type2.kind == classType)
7921 notByReference = true;
7923 else if(exp.op.op == '&' && !exp.op.exp1)
7924 exp.expType = Reference(type2);
7931 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7932 exp.op.exp1.destType = MkClassType("bool");
7933 exp.op.exp1.destType.truth = true;
7934 if(!exp.op.exp1.expType)
7935 ProcessExpressionType(exp.op.exp1);
7937 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
7938 FreeType(exp.op.exp1.expType);
7939 exp.op.exp1.expType = MkClassType("bool");
7940 exp.op.exp1.expType.truth = true;
7944 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7945 exp.op.exp2.destType = MkClassType("bool");
7946 exp.op.exp2.destType.truth = true;
7947 if(!exp.op.exp2.expType)
7948 ProcessExpressionType(exp.op.exp2);
7950 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
7951 FreeType(exp.op.exp2.expType);
7952 exp.op.exp2.expType = MkClassType("bool");
7953 exp.op.exp2.expType.truth = true;
7956 else if(exp.op.exp1 && exp.op.exp2 &&
7959 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
7960 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
7961 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
7962 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
7964 if(type1 && type2 &&
7965 // If either both are class or both are not class
7966 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
7968 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7969 exp.op.exp2.destType = type1;
7971 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7972 exp.op.exp1.destType = type2;
7974 // Warning here for adding Radians + Degrees with no destination type
7975 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
7976 type1._class.registered && type1._class.registered.type == unitClass &&
7977 type2._class.registered && type2._class.registered.type == unitClass &&
7978 type1._class.registered != type2._class.registered)
7979 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
7980 type1._class.string, type2._class.string, type1._class.string);
7982 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
7984 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7987 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7989 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
7990 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
7993 ProcessExpressionType(exp.op.exp1);
7995 if(type2.kind != pointerType)
7997 ProcessExpressionType(classExp);
7999 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8000 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8001 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8003 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8006 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8007 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8008 MkPointer(null, null), null)))),
8009 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8011 if(!exp.op.exp2.expType)
8012 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8014 ProcessExpressionType(exp.op.exp2);
8019 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)))
8021 if(type1.kind != classType && type1.type.kind == voidType)
8022 Compiler_Error($"void *: unknown size\n");
8023 exp.expType = type1;
8024 if(type1) type1.refCount++;
8026 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)))
8028 if(type2.kind != classType && type2.type.kind == voidType)
8029 Compiler_Error($"void *: unknown size\n");
8030 exp.expType = type2;
8031 if(type2) type2.refCount++;
8033 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8034 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8036 Compiler_Warning($"different levels of indirection\n");
8040 bool success = false;
8041 if(type1.kind == pointerType && type2.kind == pointerType)
8043 if(exp.op.op == '+')
8044 Compiler_Error($"cannot add two pointers\n");
8045 else if(exp.op.op == '-')
8047 // Pointer Subtraction gives integer
8048 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8057 if(type1.type.kind == templateType)
8059 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8062 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8064 ProcessExpressionType(classExp);
8066 exp.type = bracketsExp;
8067 exp.list = MkListOne(MkExpOp(
8068 MkExpBrackets(MkListOne(MkExpOp(
8069 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8071 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8073 //MkExpMember(classExp, MkIdentifier("typeSize"))
8075 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8076 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8078 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8081 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8082 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8083 MkPointer(null, null), null)))),
8084 MkExpMember(classExp, MkIdentifier("typeSize")))))
8089 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8098 if(!success && exp.op.exp1.type == constantExp)
8100 // If first expression is constant, try to match that first
8101 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8103 if(exp.expType) FreeType(exp.expType);
8104 exp.expType = exp.op.exp1.destType;
8105 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8108 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8110 if(exp.expType) FreeType(exp.expType);
8111 exp.expType = exp.op.exp2.destType;
8112 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8118 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8120 if(exp.expType) FreeType(exp.expType);
8121 exp.expType = exp.op.exp2.destType;
8122 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8125 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8127 if(exp.expType) FreeType(exp.expType);
8128 exp.expType = exp.op.exp1.destType;
8129 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8135 char expString1[10240];
8136 char expString2[10240];
8139 expString1[0] = '\0';
8140 expString2[0] = '\0';
8145 PrintExpression(exp.op.exp1, expString1);
8146 ChangeCh(expString1, '\n', ' ');
8147 PrintExpression(exp.op.exp2, expString2);
8148 ChangeCh(expString2, '\n', ' ');
8149 PrintType(exp.op.exp1.expType, type1, false, true);
8150 PrintType(exp.op.exp2.expType, type2, false, true);
8153 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8157 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8158 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8160 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8161 // Convert e.g. / 4 into / 4.0
8162 exp.op.exp1.destType = type2._class.registered.dataType;
8163 if(type2._class.registered.dataType)
8164 type2._class.registered.dataType.refCount++;
8165 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8166 exp.expType = type2;
8167 if(type2) type2.refCount++;
8169 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8171 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8172 // Convert e.g. / 4 into / 4.0
8173 exp.op.exp2.destType = type1._class.registered.dataType;
8174 if(type1._class.registered.dataType)
8175 type1._class.registered.dataType.refCount++;
8176 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8177 exp.expType = type1;
8178 if(type1) type1.refCount++;
8184 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8186 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8188 if(!type1._class.registered.dataType)
8189 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8190 exp.op.exp2.destType = type1._class.registered.dataType;
8191 exp.op.exp2.destType.refCount++;
8193 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8194 type2 = exp.op.exp2.destType;
8196 exp.expType = type2;
8200 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8202 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8204 if(!type2._class.registered.dataType)
8205 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8206 exp.op.exp1.destType = type2._class.registered.dataType;
8207 exp.op.exp1.destType.refCount++;
8209 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8210 type1 = exp.op.exp1.destType;
8211 exp.expType = type1;
8215 // TESTING THIS NEW CODE
8216 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8218 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8220 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8222 if(exp.expType) FreeType(exp.expType);
8223 exp.expType = exp.op.exp1.expType;
8224 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8229 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8231 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8233 if(exp.expType) FreeType(exp.expType);
8234 exp.expType = exp.op.exp2.expType;
8235 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8243 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8244 exp.op.exp2.destType = type1;
8248 // Maybe this was meant to be an enum...
8249 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8251 Type oldType = exp.op.exp2.expType;
8252 exp.op.exp2.expType = null;
8253 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8256 exp.op.exp2.expType = oldType;
8261 // TESTING THIS HERE... LATEST ADDITION
8262 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8264 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8265 exp.op.exp2.destType = type2._class.registered.dataType;
8266 if(type2._class.registered.dataType)
8267 type2._class.registered.dataType.refCount++;
8268 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8270 //exp.expType = type2._class.registered.dataType; //type2;
8271 //if(type2) type2.refCount++;
8274 // TESTING THIS HERE... LATEST ADDITION
8275 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8277 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8278 exp.op.exp1.destType = type1._class.registered.dataType;
8279 if(type1._class.registered.dataType)
8280 type1._class.registered.dataType.refCount++;
8281 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8282 exp.expType = type1._class.registered.dataType; //type1;
8283 if(type1) type1.refCount++;
8287 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8289 if(exp.expType) FreeType(exp.expType);
8290 exp.expType = exp.op.exp2.destType;
8291 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8293 else if(type1 && type2)
8295 char expString1[10240];
8296 char expString2[10240];
8297 char type1String[1024];
8298 char type2String[1024];
8299 expString1[0] = '\0';
8300 expString2[0] = '\0';
8301 type1String[0] = '\0';
8302 type2String[0] = '\0';
8305 PrintExpression(exp.op.exp1, expString1);
8306 ChangeCh(expString1, '\n', ' ');
8307 PrintExpression(exp.op.exp2, expString2);
8308 ChangeCh(expString2, '\n', ' ');
8309 PrintType(exp.op.exp1.expType, type1String, false, true);
8310 PrintType(exp.op.exp2.expType, type2String, false, true);
8313 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8315 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8317 exp.expType = exp.op.exp1.expType;
8318 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8320 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8322 exp.expType = exp.op.exp2.expType;
8323 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8330 // Maybe this was meant to be an enum...
8331 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8333 Type oldType = exp.op.exp1.expType;
8334 exp.op.exp1.expType = null;
8335 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8338 exp.op.exp1.expType = oldType;
8341 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8342 exp.op.exp1.destType = type2;
8345 // TESTING THIS HERE... LATEST ADDITION
8346 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8348 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8349 exp.op.exp1.destType = type1._class.registered.dataType;
8350 if(type1._class.registered.dataType)
8351 type1._class.registered.dataType.refCount++;
8354 // TESTING THIS HERE... LATEST ADDITION
8355 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8357 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8358 exp.op.exp2.destType = type2._class.registered.dataType;
8359 if(type2._class.registered.dataType)
8360 type2._class.registered.dataType.refCount++;
8364 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8366 if(exp.expType) FreeType(exp.expType);
8367 exp.expType = exp.op.exp1.destType;
8368 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8372 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8374 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8376 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8377 // Convert e.g. / 4 into / 4.0
8378 exp.op.exp1.destType = type2._class.registered.dataType;
8379 if(type2._class.registered.dataType)
8380 type2._class.registered.dataType.refCount++;
8381 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8383 if(exp.op.op == '!')
8385 exp.expType = MkClassType("bool");
8386 exp.expType.truth = true;
8390 exp.expType = type2;
8391 if(type2) type2.refCount++;
8394 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8396 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8398 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8399 // Convert e.g. / 4 into / 4.0
8400 exp.op.exp2.destType = type1._class.registered.dataType;
8401 if(type1._class.registered.dataType)
8402 type1._class.registered.dataType.refCount++;
8403 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8405 exp.expType = type1;
8406 if(type1) type1.refCount++;
8411 if(exp.op.exp1 && !exp.op.exp1.expType)
8413 char expString[10000];
8414 expString[0] = '\0';
8417 PrintExpression(exp.op.exp1, expString);
8418 ChangeCh(expString, '\n', ' ');
8421 Compiler_Error($"couldn't determine type of %s\n", expString);
8423 if(exp.op.exp2 && !exp.op.exp2.expType)
8425 char expString[10240];
8426 expString[0] = '\0';
8429 PrintExpression(exp.op.exp2, expString);
8430 ChangeCh(expString, '\n', ' ');
8433 Compiler_Error($"couldn't determine type of %s\n", expString);
8438 FreeType(exp.expType);
8439 exp.expType = MkClassType("bool");
8440 exp.expType.truth = true;
8443 if(exp.op.op != SIZEOF)
8444 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8445 (!exp.op.exp2 || exp.op.exp2.isConstant);
8447 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8449 DeclareType(exp.op.exp2.expType, false, false);
8458 case extensionExpressionExp:
8461 exp.isConstant = true;
8462 for(e = exp.list->first; e; e = e.next)
8467 FreeType(e.destType);
8468 e.destType = exp.destType;
8469 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8471 ProcessExpressionType(e);
8473 exp.destType.count--;
8474 if(!exp.expType && !e.next)
8476 exp.expType = e.expType;
8477 if(e.expType) e.expType.refCount++;
8480 exp.isConstant = false;
8483 // In case a cast became a member...
8484 e = exp.list->first;
8485 if(!e.next && e.type == memberExp)
8487 // Preserve prev, next
8488 Expression next = exp.next, prev = exp.prev;
8491 FreeType(exp.expType);
8492 FreeType(exp.destType);
8502 ProcessExpressionType(exp);
8509 exp.isConstant = true;
8511 ProcessExpressionType(exp.index.exp);
8512 if(!exp.index.exp.isConstant)
8513 exp.isConstant = false;
8515 if(exp.index.exp.expType)
8517 Type source = exp.index.exp.expType;
8518 if(source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
8519 eClass_IsDerived(source._class.registered, containerClass) &&
8520 source._class.registered.templateArgs)
8522 Class _class = source._class.registered;
8523 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8525 if(exp.index.index && exp.index.index->last)
8527 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8532 for(e = exp.index.index->first; e; e = e.next)
8534 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8536 if(e.destType) FreeType(e.destType);
8537 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8539 ProcessExpressionType(e);
8542 // Check if this type is int
8545 exp.isConstant = false;
8549 exp.expType = Dereference(exp.index.exp.expType);
8551 DeclareType(exp.expType, false, false);
8558 Type methodType = null;
8564 PrintExpression(exp.call.exp, name);
8565 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8567 //exp.call.exp.expType = null;
8568 PrintExpression(exp.call.exp, name);
8571 if(exp.call.exp.type == identifierExp)
8573 Expression idExp = exp.call.exp;
8574 Identifier id = idExp.identifier;
8575 if(!strcmp(id.string, "__builtin_frame_address"))
8577 exp.expType = ProcessTypeString("void *", true);
8578 if(exp.call.arguments && exp.call.arguments->first)
8579 ProcessExpressionType(exp.call.arguments->first);
8582 else if(!strcmp(id.string, "__ENDIAN_PAD"))
8584 exp.expType = ProcessTypeString("int", true);
8585 if(exp.call.arguments && exp.call.arguments->first)
8586 ProcessExpressionType(exp.call.arguments->first);
8589 else if(!strcmp(id.string, "Max") ||
8590 !strcmp(id.string, "Min") ||
8591 !strcmp(id.string, "Sgn") ||
8592 !strcmp(id.string, "Abs"))
8594 Expression a = null;
8595 Expression b = null;
8596 Expression tempExp1 = null, tempExp2 = null;
8597 if((!strcmp(id.string, "Max") ||
8598 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8600 a = exp.call.arguments->first;
8601 b = exp.call.arguments->last;
8605 else if(exp.call.arguments->count == 1)
8607 a = exp.call.arguments->first;
8613 exp.call.arguments->Clear();
8614 idExp.identifier = null;
8616 FreeExpContents(exp);
8618 ProcessExpressionType(a);
8620 ProcessExpressionType(b);
8622 exp.type = bracketsExp;
8623 exp.list = MkList();
8625 if(a.expType && (!b || b.expType))
8627 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8629 // Use the simpleStruct name/ids for now...
8632 OldList * specs = MkList();
8633 OldList * decls = MkList();
8635 char temp1[1024], temp2[1024];
8637 GetTypeSpecs(a.expType, specs);
8639 if(a && !a.isConstant && a.type != identifierExp)
8641 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8642 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8643 tempExp1 = QMkExpId(temp1);
8644 tempExp1.expType = a.expType;
8646 a.expType.refCount++;
8647 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8649 if(b && !b.isConstant && b.type != identifierExp)
8651 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8652 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8653 tempExp2 = QMkExpId(temp2);
8654 tempExp2.expType = b.expType;
8656 b.expType.refCount++;
8657 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8660 decl = MkDeclaration(specs, decls);
8661 if(!curCompound.compound.declarations)
8662 curCompound.compound.declarations = MkList();
8663 curCompound.compound.declarations->Insert(null, decl);
8668 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8670 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8672 MkExpCondition(MkExpBrackets(MkListOne(
8673 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8674 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8675 exp.expType = a.expType;
8677 a.expType.refCount++;
8679 else if(!strcmp(id.string, "Abs"))
8682 MkExpCondition(MkExpBrackets(MkListOne(
8683 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8684 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8685 exp.expType = a.expType;
8687 a.expType.refCount++;
8689 else if(!strcmp(id.string, "Sgn"))
8691 // ((!(a))?(0):(((a)<0)?(-1):(1)))
8693 MkExpCondition(MkExpBrackets(MkListOne(
8694 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
8695 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
8696 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8697 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
8698 exp.expType = ProcessTypeString("int", false);
8701 FreeExpression(tempExp1);
8702 if(tempExp2) FreeExpression(tempExp2);
8716 if(!exp.call.exp.destType)
8718 exp.call.exp.destType = dummy;
8721 ProcessExpressionType(exp.call.exp);
8722 if(exp.call.exp.destType == dummy)
8725 exp.call.exp.destType = null;
8730 // Check argument types against parameter types
8731 functionType = exp.call.exp.expType;
8733 if(functionType && functionType.kind == TypeKind::methodType)
8735 methodType = functionType;
8736 functionType = methodType.method.dataType;
8738 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
8739 // TOCHECK: Instead of doing this here could this be done per param?
8740 if(exp.call.exp.expType.usedClass)
8742 char typeString[1024];
8743 typeString[0] = '\0';
8744 PrintType(functionType, typeString, true, true);
8745 if(strstr(typeString, "thisclass"))
8747 OldList * specs = MkList();
8750 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
8752 decl = SpecDeclFromString(typeString, specs, null);
8754 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
8755 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
8756 exp.call.exp.expType.usedClass))
8757 thisClassParams = false;
8759 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
8761 Class backupThisClass = thisClass;
8762 thisClass = exp.call.exp.expType.usedClass;
8763 ProcessDeclarator(decl);
8764 thisClass = backupThisClass;
8767 thisClassParams = true;
8769 functionType = ProcessType(specs, decl);
8770 functionType.refCount = 0;
8771 FinishTemplatesContext(context);
8774 FreeList(specs, FreeSpecifier);
8775 FreeDeclarator(decl);
8779 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
8781 Type type = functionType.type;
8782 if(!functionType.refCount)
8784 functionType.type = null;
8785 FreeType(functionType);
8787 //methodType = functionType;
8788 functionType = type;
8790 if(functionType && functionType.kind != TypeKind::functionType)
8792 Compiler_Error($"called object %s is not a function\n", name);
8794 else if(functionType)
8796 bool emptyParams = false, noParams = false;
8797 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
8798 Type type = functionType.params.first;
8799 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
8801 Location oldyylloc = yylloc;
8803 if(!type) emptyParams = true;
8806 if(functionType.extraParam && e && functionType.thisClass)
8808 e.destType = MkClassType(functionType.thisClass.string);
8812 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
8813 if(!functionType.staticMethod)
8815 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
8816 memberExp.member.exp.expType._class)
8818 type = MkClassType(memberExp.member.exp.expType._class.string);
8823 type = functionType.params.first;
8828 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
8830 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
8835 type = functionType.params.first;
8843 if(type && type.kind == voidType)
8846 if(!type.refCount) FreeType(type);
8850 for( ; e; e = e.next)
8852 if(!type && !emptyParams)
8855 if(methodType && methodType.methodClass)
8856 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
8857 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
8858 noParams ? 0 : functionType.params.count);
8860 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
8861 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
8862 noParams ? 0 : functionType.params.count);
8866 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
8868 Type templatedType = null;
8869 Class _class = methodType.usedClass;
8870 ClassTemplateParameter curParam = null;
8872 if(_class && _class.templateArgs /*&& _class.templateClass*/)
8875 for(sClass = _class; sClass; sClass = sClass.base)
8877 if(sClass.templateClass) sClass = sClass.templateClass;
8879 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
8881 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
8884 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
8886 if(nextClass.templateClass) nextClass = nextClass.templateClass;
8887 id += nextClass.templateParams.count;
8896 if(curParam && _class.templateArgs[id].dataTypeString)
8898 ClassTemplateArgument arg = _class.templateArgs[id];
8900 Context context = SetupTemplatesContext(_class);
8903 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
8904 templatedType = ProcessTypeString(arg.dataTypeString, false);
8905 FinishTemplatesContext(context);
8907 e.destType = templatedType;
8910 templatedType.passAsTemplate = true;
8911 // templatedType.refCount++;
8917 if(type) type.refCount++;
8923 if(type) type.refCount++;
8925 // Don't reach the end for the ellipsis
8926 if(type && type.kind != ellipsisType)
8928 Type next = type.next;
8929 if(!type.refCount) FreeType(type);
8934 if(type && type.kind != ellipsisType)
8936 if(methodType && methodType.methodClass)
8937 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
8938 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
8939 functionType.params.count + extra);
8941 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
8942 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
8943 functionType.params.count + extra);
8946 if(type && !type.refCount) FreeType(type);
8953 kind = TypeKind::functionType;
8956 if(exp.call.exp.type == identifierExp)
8958 char * string = exp.call.exp.identifier.string;
8962 Location oldyylloc = yylloc;
8964 yylloc = exp.call.exp.identifier.loc;
8965 if(strstr(string, "__builtin_") == string);
8967 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
8968 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
8969 globalContext.symbols.Add((BTNode)symbol);
8970 if(strstr(symbol.string, "::"))
8971 globalContext.hasNameSpace = true;
8976 else if(exp.call.exp.type == memberExp)
8978 /*Compiler_Warning($"%s undefined; assuming returning int\n",
8979 exp.call.exp.member.member.string);*/
8982 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
8984 if(!functionType.returnType)
8986 functionType.returnType = Type
8993 if(functionType && functionType.kind == TypeKind::functionType)
8995 exp.expType = functionType.returnType;
8997 if(functionType.returnType)
8998 functionType.returnType.refCount++;
9000 if(!functionType.refCount)
9001 FreeType(functionType);
9004 if(exp.call.arguments)
9006 for(e = exp.call.arguments->first; e; e = e.next)
9008 Type destType = e.destType;
9009 ProcessExpressionType(e);
9017 Location oldyylloc = yylloc;
9018 bool thisPtr = (exp.member.exp && exp.member.exp.type == identifierExp && !strcmp(exp.member.exp.identifier.string, "this"));
9019 exp.thisPtr = thisPtr;
9021 // DOING THIS LATER NOW...
9022 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9024 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9025 /* TODO: Name Space Fix ups
9026 if(!exp.member.member.classSym)
9027 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9031 ProcessExpressionType(exp.member.exp);
9032 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9033 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9035 exp.isConstant = false;
9038 exp.isConstant = exp.member.exp.isConstant;
9039 type = exp.member.exp.expType;
9043 if(type && (type.kind == templateType))
9045 Class _class = thisClass ? thisClass : currentClass;
9046 ClassTemplateParameter param = null;
9049 for(param = _class.templateParams.first; param; param = param.next)
9051 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9055 if(param && param.defaultArg.member)
9057 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9060 Expression expMember = exp.member.exp;
9062 OldList * specs = MkList();
9063 char thisClassTypeString[1024];
9065 FreeIdentifier(exp.member.member);
9067 ProcessExpressionType(argExp);
9070 char * colon = strstr(param.defaultArg.memberString, "::");
9073 char className[1024];
9076 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9077 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9080 strcpy(thisClassTypeString, _class.fullName);
9083 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9085 exp.expType = ProcessType(specs, decl);
9086 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9088 Class expClass = exp.expType._class.registered;
9089 Class cClass = null;
9094 char templateString[1024];
9095 ClassTemplateParameter param;
9096 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9097 for(cClass = expClass; cClass; cClass = cClass.base)
9100 for(param = cClass.templateParams.first; param; param = param.next)
9104 ClassTemplateArgument arg;
9105 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9106 arg = expClass.templateArgs[id];
9108 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9110 ClassTemplateParameter cParam;
9111 //int p = numParams - sClass.templateParams.count;
9114 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9116 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9118 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9120 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9122 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9123 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9135 strcat(argument, arg.name.string);
9136 strcat(argument, " = ");
9142 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9143 char expString[1024];
9144 OldList * specs = MkList();
9145 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9147 char * string = PrintHexUInt64(arg.expression.ui64);
9148 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9150 ProcessExpressionType(exp);
9151 ComputeExpression(exp);
9152 expString[0] = '\0';
9153 PrintExpression(exp, expString);
9154 strcat(argument, expString);
9156 FreeExpression(exp);
9161 strcat(argument, arg.member.name);
9164 case TemplateParameterType::type:
9166 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9168 if(!strcmp(arg.dataTypeString, "thisclass"))
9169 strcat(argument, thisClassTypeString);
9171 strcat(argument, arg.dataTypeString);
9178 if(paramCount) strcat(templateString, ", ");
9179 if(lastParam != p - 1)
9181 strcat(templateString, param.name);
9182 strcat(templateString, " = ");
9184 strcat(templateString, argument);
9193 int len = strlen(templateString);
9194 if(templateString[len-1] == '>') templateString[len++] = ' ';
9195 templateString[len++] = '>';
9196 templateString[len++] = '\0';
9199 Context context = SetupTemplatesContext(_class);
9200 FreeType(exp.expType);
9201 exp.expType = ProcessTypeString(templateString, false);
9202 FinishTemplatesContext(context);
9206 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9207 exp.type = bracketsExp;
9208 exp.list = MkListOne(MkExpOp(null, '*',
9213 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9214 MkExpBrackets(MkListOne(
9215 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9217 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9219 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9224 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9225 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9227 type = ProcessTemplateParameterType(type.templateParameter);
9231 if(type && (type.kind == templateType));
9232 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9234 Identifier id = exp.member.member;
9235 TypeKind typeKind = type.kind;
9236 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9237 if(typeKind == subClassType && exp.member.exp.type == classExp)
9239 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9240 typeKind = classType;
9243 if(id && (typeKind == intType || typeKind == enumType))
9244 _class = eSystem_FindClass(privateModule, "int");
9249 (exp.member.exp.type == identifierExp &&
9250 !strcmp(exp.member.exp.identifier.string, "this"));*/
9251 Property prop = null;
9252 Method method = null;
9253 DataMember member = null;
9254 Property revConvert = null;
9255 ClassProperty classProp = null;
9257 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9258 exp.member.memberType = propertyMember;
9260 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9261 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9263 if(typeKind != subClassType)
9265 // Prioritize data members over properties for "this"
9266 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9268 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9269 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9271 prop = eClass_FindProperty(_class, id.string, privateModule);
9275 if(!member && !prop)
9276 prop = eClass_FindProperty(_class, id.string, privateModule);
9277 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9278 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9279 exp.member.thisPtr = true;
9281 // Prioritize properties over data members otherwise
9284 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9287 prop = eClass_FindProperty(_class, id.string, null);
9288 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9289 member = eClass_FindDataMember(_class, id.string, null, null, null);
9292 if(!prop && !member)
9294 method = eClass_FindMethod(_class, id.string, null);
9297 prop = eClass_FindProperty(_class, id.string, privateModule);
9298 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9299 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9305 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9312 if(!prop && !member)
9313 method = eClass_FindMethod(_class, id.string, privateModule);
9314 if(!prop && !member && !method)
9316 if(typeKind == subClassType)
9318 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9321 exp.member.memberType = classPropertyMember;
9322 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9326 // Assume this is a class_data member
9327 char structName[1024];
9328 Identifier id = exp.member.member;
9329 Expression classExp = exp.member.exp;
9332 FreeType(classExp.expType);
9333 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9335 strcpy(structName, "__ecereClassData_");
9336 FullClassNameCat(structName, type._class.string, false);
9337 exp.type = pointerExp;
9338 exp.member.member = id;
9340 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9341 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9342 MkExpBrackets(MkListOne(MkExpOp(
9343 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9344 MkExpMember(classExp, MkIdentifier("data"))), '+',
9345 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9350 ProcessExpressionType(exp);
9356 // Check for reverse conversion
9357 // (Convert in an instantiation later, so that we can use
9358 // deep properties system)
9359 Symbol classSym = FindClass(id.string);
9362 Class convertClass = classSym.registered;
9364 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9371 exp.member.memberType = propertyMember;
9373 ProcessPropertyType(prop);
9374 exp.expType = prop.dataType;
9375 if(prop.dataType) prop.dataType.refCount++;
9379 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9381 FreeExpContents(exp);
9382 exp.type = identifierExp;
9383 exp.identifier = MkIdentifier("class");
9384 ProcessExpressionType(exp);
9388 exp.member.memberType = dataMember;
9389 DeclareStruct(_class.fullName, false);
9390 if(!member.dataType)
9392 Context context = SetupTemplatesContext(_class);
9393 member.dataType = ProcessTypeString(member.dataTypeString, false);
9394 FinishTemplatesContext(context);
9396 exp.expType = member.dataType;
9397 if(member.dataType) member.dataType.refCount++;
9401 exp.member.memberType = reverseConversionMember;
9402 exp.expType = MkClassType(revConvert._class.fullName);
9410 exp.type = identifierExp;
9411 exp.identifier = exp.member.member;
9414 exp.member.memberType = methodMember;
9416 if(!method.dataType)
9417 ProcessMethodType(method);
9425 // Tricky spot here... To use instance versus class virtual table
9426 // Put it back to what it was... What did we break?
9428 // Had to put it back for overriding Main of Thread global instance
9430 //exp.expType.methodClass = _class;
9431 exp.expType.methodClass = (id && id._class) ? _class : null;
9433 // Need the actual class used for templated classes
9434 exp.expType.usedClass = _class;
9438 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9440 FreeExpContents(exp);
9441 exp.type = identifierExp;
9442 exp.identifier = MkIdentifier("class");
9443 ProcessExpressionType(exp);
9446 yylloc = exp.member.member.loc;
9447 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9449 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9452 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9457 while(tClass && !tClass.templateClass) tClass = tClass.base;
9459 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9462 ClassTemplateParameter curParam = null;
9465 for(sClass = tClass; sClass; sClass = sClass.base)
9468 if(sClass.templateClass) sClass = sClass.templateClass;
9469 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9471 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9473 for(sClass = sClass.base; sClass; sClass = sClass.base)
9474 id += sClass.templateParams.count;
9482 if(curParam && tClass.templateArgs[id].dataTypeString)
9484 ClassTemplateArgument arg = tClass.templateArgs[id];
9485 Context context = SetupTemplatesContext(tClass);
9487 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9488 FreeType(exp.expType);
9489 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9492 if(exp.expType.kind == thisClassType)
9494 FreeType(exp.expType);
9495 exp.expType = ReplaceThisClassType(_class);
9498 if(tClass.templateClass)
9499 exp.expType.passAsTemplate = true;
9500 //exp.expType.refCount++;
9503 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9504 //exp.destType.refCount++;
9506 if(exp.destType.kind == thisClassType)
9508 FreeType(exp.destType);
9509 exp.destType = ReplaceThisClassType(_class);
9513 FinishTemplatesContext(context);
9516 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9517 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9520 ClassTemplateParameter curParam = null;
9523 for(sClass = tClass; sClass; sClass = sClass.base)
9526 if(sClass.templateClass) sClass = sClass.templateClass;
9527 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9529 if(curParam.type == TemplateParameterType::type &&
9530 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9532 for(sClass = sClass.base; sClass; sClass = sClass.base)
9533 id += sClass.templateParams.count;
9543 ClassTemplateArgument arg = tClass.templateArgs[id];
9544 Context context = SetupTemplatesContext(tClass);
9547 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9549 basicType = ProcessTypeString(arg.dataTypeString, false);
9552 if(basicType.kind == thisClassType)
9554 FreeType(basicType);
9555 basicType = ReplaceThisClassType(_class);
9558 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9559 if(tClass.templateClass)
9560 basicType.passAsTemplate = true;
9563 FreeType(exp.expType);
9565 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9566 //exp.expType.refCount++;
9569 exp.destType = exp.expType;
9570 exp.destType.refCount++;
9574 Expression newExp { };
9575 OldList * specs = MkList();
9577 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9579 if(exp.destType) exp.destType.refCount++;
9580 if(exp.expType) exp.expType.refCount++;
9582 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9583 exp.cast.exp = newExp;
9584 //FreeType(exp.expType);
9585 //exp.expType = null;
9586 //ProcessExpressionType(sourceExp);
9589 FinishTemplatesContext(context);
9592 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9594 Class expClass = exp.expType._class.registered;
9597 Class cClass = null;
9602 char templateString[1024];
9603 ClassTemplateParameter param;
9604 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9605 while(cClass != expClass)
9608 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9611 for(param = cClass.templateParams.first; param; param = param.next)
9613 Class cClassCur = null;
9616 ClassTemplateParameter paramCur = null;
9617 ClassTemplateArgument arg;
9618 while(cClassCur != tClass && !paramCur)
9621 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
9622 cClassCur = sClassCur;
9624 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
9626 if(!strcmp(paramCur.name, param.name))
9634 if(paramCur && paramCur.type == TemplateParameterType::type)
9635 arg = tClass.templateArgs[cp];
9637 arg = expClass.templateArgs[p];
9644 strcat(argument, arg.name.string);
9645 strcat(argument, " = ");
9651 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9652 char expString[1024];
9653 OldList * specs = MkList();
9654 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9656 char * string = PrintHexUInt64(arg.expression.ui64);
9657 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9659 ProcessExpressionType(exp);
9660 ComputeExpression(exp);
9661 expString[0] = '\0';
9662 PrintExpression(exp, expString);
9663 strcat(argument, expString);
9665 FreeExpression(exp);
9670 strcat(argument, arg.member.name);
9673 case TemplateParameterType::type:
9675 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9676 strcat(argument, arg.dataTypeString);
9682 if(paramCount) strcat(templateString, ", ");
9683 if(lastParam != p - 1)
9685 strcat(templateString, param.name);
9686 strcat(templateString, " = ");
9688 strcat(templateString, argument);
9697 int len = strlen(templateString);
9698 if(templateString[len-1] == '>') templateString[len++] = ' ';
9699 templateString[len++] = '>';
9700 templateString[len++] = '\0';
9703 FreeType(exp.expType);
9705 Context context = SetupTemplatesContext(tClass);
9706 exp.expType = ProcessTypeString(templateString, false);
9707 FinishTemplatesContext(context);
9714 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
9716 else if(type && (type.kind == structType || type.kind == unionType))
9718 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
9721 exp.expType = memberType;
9723 memberType.refCount++;
9728 char expString[10240];
9729 expString[0] = '\0';
9730 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
9731 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
9734 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
9736 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9738 Identifier id = exp.member.member;
9739 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9742 FreeType(exp.expType);
9743 exp.expType = ReplaceThisClassType(_class);
9750 // Convert x->y into (*x).y
9753 Type destType = exp.destType;
9755 // DOING THIS LATER NOW...
9756 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9758 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9759 /* TODO: Name Space Fix ups
9760 if(!exp.member.member.classSym)
9761 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
9765 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
9766 exp.type = memberExp;
9769 ProcessExpressionType(exp);
9776 //ComputeExpression(exp);
9778 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
9779 if(classSym && classSym.registered)
9781 if(classSym.registered.type == noHeadClass)
9785 DeclareStruct(classSym.string, false);
9786 FreeSpecifier(exp._class);
9787 exp.type = typeSizeExp;
9788 FullClassNameCat(name, classSym.string, false);
9789 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
9793 if(classSym.registered.fixed)
9795 FreeSpecifier(exp._class);
9796 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
9797 exp.type = constantExp;
9801 char className[1024];
9802 strcpy(className, "__ecereClass_");
9803 FullClassNameCat(className, classSym.string, true);
9804 MangleClassName(className);
9806 DeclareClass(classSym, className);
9808 FreeExpContents(exp);
9809 exp.type = pointerExp;
9810 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
9811 exp.member.member = MkIdentifier("structSize");
9821 // exp.isConstant = true;
9826 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
9833 exp.isConstant = true;
9835 DeclareType(type, false, false);
9841 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
9843 FreeType(exp.cast.exp.destType);
9844 exp.cast.exp.destType = type;
9846 ProcessExpressionType(exp.cast.exp);
9851 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
9852 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
9854 void * prev = exp.prev, * next = exp.next;
9855 Type expType = exp.cast.exp.destType;
9856 Expression castExp = exp.cast.exp;
9857 Type destType = exp.destType;
9859 if(expType) expType.refCount++;
9861 //FreeType(exp.destType);
9862 FreeType(exp.expType);
9863 FreeTypeName(exp.cast.typeName);
9866 FreeType(exp.expType);
9867 FreeType(exp.destType);
9869 exp.expType = expType;
9870 exp.destType = destType;
9880 exp.isConstant = exp.cast.exp.isConstant;
9885 case extensionInitializerExp:
9887 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
9890 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
9891 // ProcessInitializer(exp.initializer.initializer, type);
9897 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
9898 ProcessExpressionType(exp.vaArg.exp);
9906 exp.isConstant = true;
9908 FreeType(exp.cond.cond.destType);
9909 exp.cond.cond.destType = MkClassType("bool");
9910 exp.cond.cond.destType.truth = true;
9911 ProcessExpressionType(exp.cond.cond);
9912 if(!exp.cond.cond.isConstant)
9913 exp.isConstant = false;
9914 for(e = exp.cond.exp->first; e; e = e.next)
9918 FreeType(e.destType);
9919 e.destType = exp.destType;
9920 if(e.destType) e.destType.refCount++;
9922 ProcessExpressionType(e);
9925 exp.expType = e.expType;
9926 if(e.expType) e.expType.refCount++;
9929 exp.isConstant = false;
9932 FreeType(exp.cond.elseExp.destType);
9933 // Added this check if we failed to find an expType
9934 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
9937 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
9939 if(exp.cond.elseExp.destType)
9940 exp.cond.elseExp.destType.refCount++;
9941 ProcessExpressionType(exp.cond.elseExp);
9943 // FIXED THIS: Was done before calling process on elseExp
9944 if(!exp.cond.elseExp.isConstant)
9945 exp.isConstant = false;
9948 case extensionCompoundExp:
9950 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
9952 Statement last = exp.compound.compound.statements->last;
9953 if(last.type == expressionStmt && last.expressions && last.expressions->last)
9955 ((Expression)last.expressions->last).destType = exp.destType;
9957 exp.destType.refCount++;
9959 ProcessStatement(exp.compound);
9960 exp.expType = ((Expression)last.expressions->last).expType;
9961 if(((Expression)last.expressions->last).expType)
9962 exp.expType.refCount++;
9968 Specifier spec = exp._classExp.specifiers->first;
9969 if(spec && spec.type == nameSpecifier)
9971 exp.expType = MkClassType(spec.name);
9972 exp.expType.kind = subClassType;
9973 exp.byReference = true;
9977 exp.expType = MkClassType("ecere::com::Class");
9978 exp.byReference = true;
9984 Class _class = thisClass ? thisClass : currentClass;
9987 Identifier id = exp.classData.id;
9988 char structName[1024];
9989 Expression classExp;
9990 strcpy(structName, "__ecereClassData_");
9991 FullClassNameCat(structName, _class.fullName, false);
9992 exp.type = pointerExp;
9993 exp.member.member = id;
9994 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
9995 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
9997 classExp = MkExpIdentifier(MkIdentifier("class"));
9999 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10000 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10001 MkExpBrackets(MkListOne(MkExpOp(
10002 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10003 MkExpMember(classExp, MkIdentifier("data"))), '+',
10004 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10007 ProcessExpressionType(exp);
10015 char * typeString = null;
10016 char typeStringBuf[1024];
10017 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10018 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10020 Class templateClass = exp.destType._class.registered;
10021 typeString = templateClass.templateArgs[2].dataTypeString;
10025 // Guess type from expressions in the array
10027 for(e = exp.list->first; e; e = e.next)
10029 ProcessExpressionType(e);
10032 if(!type) { type = e.expType; type.refCount++; }
10035 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10036 if(!MatchTypeExpression(e, type, null, false))
10042 e = exp.list->first;
10043 ProcessExpressionType(e);
10046 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10047 if(!MatchTypeExpression(e, type, null, false))
10049 FreeType(e.expType);
10060 FreeType(e.expType);
10067 typeStringBuf[0] = '\0';
10068 PrintType(type, typeStringBuf, false, true);
10069 typeString = typeStringBuf;
10077 (Container)& (struct BuiltInContainer)
10079 ._vTbl = class(BuiltInContainer)._vTbl,
10080 ._class = class(BuiltInContainer),
10082 .data = (int[]){ 1, 7, 3, 4, 5 },
10084 .type = class(int),
10087 char templateString[1024];
10088 OldList * initializers = MkList();
10089 OldList * structInitializers = MkList();
10090 OldList * specs = MkList();
10092 Declarator decl = SpecDeclFromString(typeString, specs, null);
10093 sprintf(templateString, "Container<%s>", typeString);
10098 type = ProcessTypeString(typeString, false);
10099 while(e = exp.list->first)
10101 exp.list->Remove(e);
10104 ProcessExpressionType(e);
10105 ListAdd(initializers, MkInitializerAssignment(e));
10111 DeclareStruct("ecere::com::BuiltInContainer", false);
10113 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10114 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10115 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10116 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10117 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10118 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10119 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10120 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10121 MkInitializerList(initializers))));
10122 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10123 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10124 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10125 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10126 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10127 exp.expType = ProcessTypeString(templateString, false);
10128 exp.type = bracketsExp;
10129 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10131 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10132 MkInitializerList(structInitializers)))));
10133 ProcessExpressionType(expExt);
10137 exp.expType = ProcessTypeString("Container", false);
10138 Compiler_Error($"Couldn't determine type of array elements\n");
10144 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10146 FreeType(exp.expType);
10147 exp.expType = ReplaceThisClassType(thisClass);
10150 // Resolve structures here
10151 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10153 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10154 // TODO: Fix members reference...
10157 if(exp.expType.kind != enumType)
10160 String enumName = CopyString(exp.expType.enumName);
10162 // Fixed a memory leak on self-referencing C structs typedefs
10163 // by instantiating a new type rather than simply copying members
10164 // into exp.expType
10165 FreeType(exp.expType);
10166 exp.expType = Type { };
10167 exp.expType.kind = symbol.type.kind;
10168 exp.expType.refCount++;
10169 exp.expType.enumName = enumName;
10171 exp.expType.members = symbol.type.members;
10172 for(member = symbol.type.members.first; member; member = member.next)
10178 for(member = symbol.type.members.first; member; member = member.next)
10180 NamedLink value { name = CopyString(member.name) };
10181 exp.expType.members.Add(value);
10188 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10189 else if(exp.destType && !exp.destType.keepCast)
10191 if(!CheckExpressionType(exp, exp.destType, false))
10193 if(!exp.destType.count || unresolved)
10198 if(exp.destType.kind != ellipsisType)
10204 char expString[10240];
10205 expString[0] = '\0';
10207 PrintType(exp.destType, type2, false, true);
10209 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10211 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10212 else if(exp.type != dummyExp)
10213 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10218 char expString[10240] ;
10219 expString[0] = '\0';
10220 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10223 Compiler_Error($"unresolved identifier %s\n", expString);
10224 else if(exp.type != dummyExp)
10225 Compiler_Error($"couldn't determine type of %s\n", expString);
10236 PrintType(exp.expType, type1, false, true);
10237 PrintType(exp.destType, type2, false, true);
10240 //CheckExpressionType(exp, exp.destType, false);
10242 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10243 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10244 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10247 char expString[10240];
10248 expString[0] = '\0';
10249 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10252 CheckExpressionType(exp, exp.destType, false);
10254 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10255 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10256 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10258 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10259 FreeType(exp.expType);
10260 exp.destType.refCount++;
10261 exp.expType = exp.destType;
10266 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10268 Expression newExp { };
10269 char typeString[1024];
10270 OldList * specs = MkList();
10273 typeString[0] = '\0';
10277 if(exp.expType) exp.expType.refCount++;
10278 if(exp.expType) exp.expType.refCount++;
10279 exp.type = castExp;
10280 newExp.destType = exp.expType;
10282 PrintType(exp.expType, typeString, false, false);
10283 decl = SpecDeclFromString(typeString, specs, null);
10285 exp.cast.typeName = MkTypeName(specs, decl);
10286 exp.cast.exp = newExp;
10289 else if(unresolved)
10291 if(exp.identifier._class && exp.identifier._class.name)
10292 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10293 else if(exp.identifier.string && exp.identifier.string[0])
10294 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10296 else if(!exp.expType && exp.type != dummyExp)
10298 char expString[10240];
10299 expString[0] = '\0';
10300 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10301 Compiler_Error($"couldn't determine type of %s\n", expString);
10304 // Let's try to support any_object & typed_object here:
10305 ApplyAnyObjectLogic(exp);
10307 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10308 exp.expType._class.registered.type == noHeadClass)
10310 exp.byReference = true;
10312 /*else if(!notByReference && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10313 exp.destType._class.registered.type == noHeadClass)
10315 exp.byReference = true;
10317 yylloc = oldyylloc;
10320 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10322 // THIS CODE WILL FIND NEXT MEMBER...
10325 *curMember = (*curMember).next;
10327 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10329 *curMember = subMemberStack[--(*subMemberStackPos)];
10330 *curMember = (*curMember).next;
10333 // SKIP ALL PROPERTIES HERE...
10334 while((*curMember) && (*curMember).isProperty)
10335 *curMember = (*curMember).next;
10337 if(subMemberStackPos)
10339 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10341 subMemberStack[(*subMemberStackPos)++] = *curMember;
10343 *curMember = (*curMember).members.first;
10344 while(*curMember && (*curMember).isProperty)
10345 *curMember = (*curMember).next;
10353 if(subMemberStackPos && *subMemberStackPos)
10355 *curMember = subMemberStack[--(*subMemberStackPos)];
10356 *curMember = (*curMember).next;
10360 Class lastCurClass = *curClass;
10362 if(*curClass == _class) break; // REACHED THE END
10364 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10365 *curMember = (*curClass).membersAndProperties.first;
10368 while((*curMember) && (*curMember).isProperty)
10369 *curMember = (*curMember).next;
10370 if(subMemberStackPos)
10372 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10374 subMemberStack[(*subMemberStackPos)++] = *curMember;
10376 *curMember = (*curMember).members.first;
10377 while(*curMember && (*curMember).isProperty)
10378 *curMember = (*curMember).next;
10386 static void ProcessInitializer(Initializer init, Type type)
10390 case expInitializer:
10391 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10393 // TESTING THIS FOR SHUTTING = 0 WARNING
10394 if(init.exp && !init.exp.destType)
10396 FreeType(init.exp.destType);
10397 init.exp.destType = type;
10398 if(type) type.refCount++;
10402 ProcessExpressionType(init.exp);
10403 init.isConstant = init.exp.isConstant;
10409 Expression exp = init.exp;
10410 Instantiation inst = exp.instance;
10411 MembersInit members;
10413 init.type = listInitializer;
10414 init.list = MkList();
10418 for(members = inst.members->first; members; members = members.next)
10420 if(members.type == dataMembersInit)
10423 for(member = members.dataMembers->first; member; member = member.next)
10425 ListAdd(init.list, member.initializer);
10426 member.initializer = null;
10429 // Discard all MembersInitMethod
10432 FreeExpression(exp);
10434 case listInitializer:
10437 Type initializerType = null;
10438 Class curClass = null;
10439 DataMember curMember = null;
10440 DataMember subMemberStack[256];
10441 int subMemberStackPos = 0;
10443 if(type && type.kind == arrayType)
10444 initializerType = Dereference(type);
10445 else if(type && (type.kind == structType || type.kind == unionType))
10446 initializerType = type.members.first;
10448 for(i = init.list->first; i; i = i.next)
10450 if(type && type.kind == classType && type._class && type._class.registered)
10452 // 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)
10453 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10454 // TODO: Generate error on initializing a private data member this way from another module...
10457 if(!curMember.dataType)
10458 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10459 initializerType = curMember.dataType;
10462 ProcessInitializer(i, initializerType);
10463 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10464 initializerType = initializerType.next;
10466 init.isConstant = false;
10469 if(type && type.kind == arrayType)
10470 FreeType(initializerType);
10472 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10474 Compiler_Error($"Assigning list initializer to non list\n");
10481 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10485 case baseSpecifier:
10487 if(spec.specifier == THISCLASS)
10491 spec.type = nameSpecifier;
10492 spec.name = ReplaceThisClass(thisClass);
10493 spec.symbol = FindClass(spec.name);
10494 ProcessSpecifier(spec, declareStruct);
10499 case nameSpecifier:
10501 Symbol symbol = FindType(curContext, spec.name);
10503 DeclareType(symbol.type, true, true);
10504 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10505 DeclareStruct(spec.name, false);
10508 case enumSpecifier:
10513 for(e = spec.list->first; e; e = e.next)
10516 ProcessExpressionType(e.exp);
10521 case structSpecifier:
10522 case unionSpecifier:
10524 if(spec.definitions)
10527 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10529 ProcessClass(spec.definitions, symbol);
10532 for(def = spec.definitions->first; def; def = def.next)
10534 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10535 ProcessDeclaration(def.decl);
10542 case classSpecifier:
10544 Symbol classSym = FindClass(spec.name);
10545 if(classSym && classSym.registered && classSym.registered.type == structClass)
10546 DeclareStruct(spec.name, false);
10554 static void ProcessDeclarator(Declarator decl)
10558 case identifierDeclarator:
10559 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10561 FreeSpecifier(decl.identifier._class);
10562 decl.identifier._class = null;
10565 case arrayDeclarator:
10567 ProcessExpressionType(decl.array.exp);
10568 case structDeclarator:
10569 case bracketsDeclarator:
10570 case functionDeclarator:
10571 case pointerDeclarator:
10572 case extendedDeclarator:
10573 case extendedDeclaratorEnd:
10574 if(decl.declarator)
10575 ProcessDeclarator(decl.declarator);
10576 if(decl.type == functionDeclarator)
10578 Identifier id = GetDeclId(decl);
10579 if(id && id._class)
10583 qualifiers = MkListOne(id._class);
10586 if(!decl.function.parameters)
10587 decl.function.parameters = MkList();
10588 decl.function.parameters->Insert(null, param);
10591 if(decl.function.parameters)
10595 for(param = decl.function.parameters->first; param; param = param.next)
10597 if(param.qualifiers && param.qualifiers->first)
10599 Specifier spec = param.qualifiers->first;
10600 if(spec && spec.specifier == TYPED_OBJECT)
10602 Declarator d = param.declarator;
10605 qualifiers = MkListOne(MkSpecifier(VOID));
10606 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10609 FreeList(param.qualifiers, FreeSpecifier);
10611 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10612 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10614 decl.function.parameters->Insert(param, newParam);
10617 else if(spec && spec.specifier == ANY_OBJECT)
10619 Declarator d = param.declarator;
10621 FreeList(param.qualifiers, FreeSpecifier);
10623 param.qualifiers = MkListOne(MkSpecifier(VOID));
10624 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10626 else if(spec.specifier == THISCLASS)
10630 spec.type = nameSpecifier;
10631 spec.name = ReplaceThisClass(thisClass);
10632 spec.symbol = FindClass(spec.name);
10633 ProcessSpecifier(spec, false);
10638 if(param.declarator)
10639 ProcessDeclarator(param.declarator);
10647 static void ProcessDeclaration(Declaration decl)
10652 case initDeclaration:
10654 bool declareStruct = false;
10656 lineNum = decl.pos.line;
10657 column = decl.pos.col;
10660 if(decl.declarators)
10664 for(d = decl.declarators->first; d; d = d.next)
10666 Type type, subType;
10667 ProcessDeclarator(d.declarator);
10669 type = ProcessType(decl.specifiers, d.declarator);
10673 ProcessInitializer(d.initializer, type);
10675 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
10677 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
10678 d.initializer.exp.type == instanceExp)
10680 if(type.kind == classType && type._class ==
10681 d.initializer.exp.expType._class)
10683 Instantiation inst = d.initializer.exp.instance;
10684 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
10686 d.initializer.exp.instance = null;
10687 if(decl.specifiers)
10688 FreeList(decl.specifiers, FreeSpecifier);
10689 FreeList(decl.declarators, FreeInitDeclarator);
10693 decl.type = instDeclaration;
10698 for(subType = type; subType;)
10700 if(subType.kind == classType)
10702 declareStruct = true;
10705 else if(subType.kind == pointerType)
10707 else if(subType.kind == arrayType)
10708 subType = subType.arrayType;
10718 if(decl.specifiers)
10721 for(s = decl.specifiers->first; s; s = s.next)
10723 ProcessSpecifier(s, declareStruct);
10728 case instDeclaration:
10730 ProcessInstantiationType(decl.inst);
10733 case structDeclaration:
10737 bool declareStruct = false;
10739 if(decl.declarators)
10741 for(d = decl.declarators->first; d; d = d.next)
10743 Type type = ProcessType(decl.specifiers, d.declarator);
10745 ProcessDeclarator(d);
10746 for(subType = type; subType;)
10748 if(subType.kind == classType)
10750 declareStruct = true;
10753 else if(subType.kind == pointerType)
10755 else if(subType.kind == arrayType)
10756 subType = subType.arrayType;
10763 if(decl.specifiers)
10765 for(spec = decl.specifiers->first; spec; spec = spec.next)
10766 ProcessSpecifier(spec, declareStruct);
10773 static FunctionDefinition curFunction;
10775 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
10777 char propName[1024], propNameM[1024];
10778 char getName[1024], setName[1024];
10781 DeclareProperty(prop, setName, getName);
10783 // eInstance_FireWatchers(object, prop);
10784 strcpy(propName, "__ecereProp_");
10785 FullClassNameCat(propName, prop._class.fullName, false);
10786 strcat(propName, "_");
10787 // strcat(propName, prop.name);
10788 FullClassNameCat(propName, prop.name, true);
10789 MangleClassName(propName);
10791 strcpy(propNameM, "__ecerePropM_");
10792 FullClassNameCat(propNameM, prop._class.fullName, false);
10793 strcat(propNameM, "_");
10794 // strcat(propNameM, prop.name);
10795 FullClassNameCat(propNameM, prop.name, true);
10796 MangleClassName(propNameM);
10798 if(prop.isWatchable)
10801 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10802 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10803 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10806 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10807 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10808 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10814 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10815 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10816 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10819 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10820 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10821 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10824 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
10825 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
10826 curFunction.propSet.fireWatchersDone = true;
10829 static void ProcessStatement(Statement stmt)
10833 lineNum = stmt.pos.line;
10834 column = stmt.pos.col;
10839 ProcessStatement(stmt.labeled.stmt);
10842 // This expression should be constant...
10843 if(stmt.caseStmt.exp)
10845 FreeType(stmt.caseStmt.exp.destType);
10846 stmt.caseStmt.exp.destType = curSwitchType;
10847 if(curSwitchType) curSwitchType.refCount++;
10848 ProcessExpressionType(stmt.caseStmt.exp);
10849 ComputeExpression(stmt.caseStmt.exp);
10851 if(stmt.caseStmt.stmt)
10852 ProcessStatement(stmt.caseStmt.stmt);
10856 if(stmt.compound.context)
10861 Statement prevCompound = curCompound;
10862 Context prevContext = curContext;
10864 if(!stmt.compound.isSwitch)
10866 curCompound = stmt;
10867 curContext = stmt.compound.context;
10870 if(stmt.compound.declarations)
10872 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
10873 ProcessDeclaration(decl);
10875 if(stmt.compound.statements)
10877 for(s = stmt.compound.statements->first; s; s = s.next)
10878 ProcessStatement(s);
10881 curContext = prevContext;
10882 curCompound = prevCompound;
10886 case expressionStmt:
10889 if(stmt.expressions)
10891 for(exp = stmt.expressions->first; exp; exp = exp.next)
10892 ProcessExpressionType(exp);
10900 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
10901 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
10902 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
10903 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
10905 ProcessExpressionType(exp);
10907 if(stmt.ifStmt.stmt)
10908 ProcessStatement(stmt.ifStmt.stmt);
10909 if(stmt.ifStmt.elseStmt)
10910 ProcessStatement(stmt.ifStmt.elseStmt);
10915 Type oldSwitchType = curSwitchType;
10916 if(stmt.switchStmt.exp)
10919 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
10929 e.exp.destType = destType;
10932 ProcessExpressionType(exp);
10935 curSwitchType = exp.expType;
10938 ProcessStatement(stmt.switchStmt.stmt);
10939 curSwitchType = oldSwitchType;
10944 if(stmt.whileStmt.exp)
10948 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
10949 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
10950 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
10951 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
10953 ProcessExpressionType(exp);
10956 if(stmt.whileStmt.stmt)
10957 ProcessStatement(stmt.whileStmt.stmt);
10962 if(stmt.doWhile.exp)
10966 if(stmt.doWhile.exp->last)
10968 FreeType(((Expression)stmt.doWhile.exp->last).destType);
10969 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
10970 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
10972 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
10974 ProcessExpressionType(exp);
10977 if(stmt.doWhile.stmt)
10978 ProcessStatement(stmt.doWhile.stmt);
10984 if(stmt.forStmt.init)
10985 ProcessStatement(stmt.forStmt.init);
10987 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
10989 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
10990 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
10991 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
10994 if(stmt.forStmt.check)
10995 ProcessStatement(stmt.forStmt.check);
10996 if(stmt.forStmt.increment)
10998 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
10999 ProcessExpressionType(exp);
11002 if(stmt.forStmt.stmt)
11003 ProcessStatement(stmt.forStmt.stmt);
11008 Identifier id = stmt.forEachStmt.id;
11009 OldList * exp = stmt.forEachStmt.exp;
11010 OldList * filter = stmt.forEachStmt.filter;
11011 Statement block = stmt.forEachStmt.stmt;
11012 char iteratorType[1024];
11015 bool isBuiltin = exp && exp->last &&
11016 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11017 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11018 Expression arrayExp;
11019 char * typeString = null;
11020 int builtinCount = 0;
11022 for(e = exp ? exp->first : null; e; e = e.next)
11026 FreeType(e.destType);
11027 e.destType = ProcessTypeString("Container", false);
11029 if(!isBuiltin || e.next)
11030 ProcessExpressionType(e);
11033 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11034 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11035 eClass_IsDerived(source._class.registered, containerClass)))
11037 Class _class = source ? source._class.registered : null;
11039 Expression expIt = null;
11040 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
11041 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11042 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11043 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11044 stmt.type = compoundStmt;
11046 stmt.compound.context = Context { };
11047 stmt.compound.context.parent = curContext;
11048 curContext = stmt.compound.context;
11050 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11052 Class mapClass = eSystem_FindClass(privateModule, "Map");
11053 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11054 isCustomAVLTree = true;
11055 if(eClass_IsDerived(source._class.registered, avlTreeClass))
11057 else if(eClass_IsDerived(source._class.registered, mapClass))
11060 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11061 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11063 Class listClass = eSystem_FindClass(privateModule, "List");
11065 isList = eClass_IsDerived(source._class.registered, listClass);
11071 OldList * specs = MkList();
11072 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11073 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11074 stmt.compound.declarations = MkListOne(
11075 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11076 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11077 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11078 MkInitializerAssignment(MkExpBrackets(exp))))));
11083 char typeStringBuf[1024];
11085 // TODO: Merge this code?
11086 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11087 if(((Expression)exp->last).type == castExp)
11089 TypeName typeName = ((Expression)exp->last).cast.typeName;
11091 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11094 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11095 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11096 arrayExp.destType._class.registered.templateArgs)
11098 Class templateClass = arrayExp.destType._class.registered;
11099 typeString = templateClass.templateArgs[2].dataTypeString;
11101 else if(arrayExp.list)
11103 // Guess type from expressions in the array
11105 for(e = arrayExp.list->first; e; e = e.next)
11107 ProcessExpressionType(e);
11110 if(!type) { type = e.expType; type.refCount++; }
11113 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11114 if(!MatchTypeExpression(e, type, null, false))
11120 e = arrayExp.list->first;
11121 ProcessExpressionType(e);
11124 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11125 if(!MatchTypeExpression(e, type, null, false))
11127 FreeType(e.expType);
11138 FreeType(e.expType);
11145 typeStringBuf[0] = '\0';
11146 PrintType(type, typeStringBuf, false, true);
11147 typeString = typeStringBuf;
11153 OldList * initializers = MkList();
11155 OldList * specs = MkList();
11160 builtinCount = arrayExp.list->count;
11161 type = ProcessTypeString(typeString, false);
11162 while(e = arrayExp.list->first)
11164 arrayExp.list->Remove(e);
11167 ProcessExpressionType(e);
11168 ListAdd(initializers, MkInitializerAssignment(e));
11171 delete arrayExp.list;
11173 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11174 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11175 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11177 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorArray(PlugDeclarator(
11178 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorIdentifier(MkIdentifier("__internalArray"))), null), MkInitializerList(initializers)))));
11180 FreeList(exp, FreeExpression);
11184 arrayExp.expType = ProcessTypeString("Container", false);
11185 Compiler_Error($"Couldn't determine type of array elements\n");
11190 OldList * specs = MkList();
11192 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11193 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11194 stmt.compound.declarations = MkListOne(
11195 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11196 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11197 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11198 MkInitializerAssignment(MkExpBrackets(exp))))));
11201 else if(isLinkList && !isList)
11204 OldList * specs = MkList();
11205 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11206 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11207 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11208 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11209 MkInitializerAssignment(MkExpBrackets(exp))))));
11211 /*else if(isCustomAVLTree)
11214 OldList * specs = MkList();
11215 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11216 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11217 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11218 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11219 MkInitializerAssignment(MkExpBrackets(exp))))));
11221 else if(_class.templateArgs)
11224 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11226 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11228 stmt.compound.declarations = MkListOne(
11229 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11230 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11231 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11233 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11235 if(block && block.type == compoundStmt && block.compound.context)
11237 block.compound.context.parent = stmt.compound.context;
11241 block = MkIfStmt(filter, block, null);
11245 stmt.compound.statements = MkListOne(MkForStmt(
11246 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11247 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11248 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11249 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11251 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11252 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11253 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11258 //OldList * specs = MkList();
11259 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11261 sprintf(count, "%d", builtinCount);
11263 stmt.compound.statements = MkListOne(MkForStmt(
11264 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11265 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11266 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11267 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11271 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11272 stmt.compound.statements = MkListOne(MkForStmt(
11273 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11274 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11275 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11276 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11279 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11280 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11281 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11283 else if(isLinkList && !isList)
11285 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11286 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11287 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11288 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11290 stmt.compound.statements = MkListOne(MkForStmt(
11291 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11292 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11293 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11298 OldList * specs = MkList();
11299 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11300 stmt.compound.statements = MkListOne(MkForStmt(
11301 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11302 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11303 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11304 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11305 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11308 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11309 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11310 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11312 /*else if(isCustomAVLTree)
11314 stmt.compound.statements = MkListOne(MkForStmt(
11315 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11316 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11317 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11318 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11321 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11322 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11323 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11327 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11328 MkIdentifier("Next")), null)), block));
11330 ProcessExpressionType(expIt);
11331 if(stmt.compound.declarations->first)
11332 ProcessDeclaration(stmt.compound.declarations->first);
11335 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11337 ProcessStatement(stmt);
11338 curContext = stmt.compound.context.parent;
11343 Compiler_Error($"Expression is not a container\n");
11356 if(stmt.expressions)
11358 for(exp = stmt.expressions->first; exp; exp = exp.next)
11362 if(curFunction && !curFunction.type)
11363 curFunction.type = ProcessType(
11364 curFunction.specifiers, curFunction.declarator);
11365 FreeType(exp.destType);
11366 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11367 if(exp.destType) exp.destType.refCount++;
11369 ProcessExpressionType(exp);
11374 case badDeclarationStmt:
11376 ProcessDeclaration(stmt.decl);
11382 if(stmt.asmStmt.inputFields)
11384 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11385 if(field.expression)
11386 ProcessExpressionType(field.expression);
11388 if(stmt.asmStmt.outputFields)
11390 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11391 if(field.expression)
11392 ProcessExpressionType(field.expression);
11394 if(stmt.asmStmt.clobberedFields)
11396 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11398 if(field.expression)
11399 ProcessExpressionType(field.expression);
11406 PropertyWatch propWatch;
11407 OldList * watches = stmt._watch.watches;
11408 Expression object = stmt._watch.object;
11409 Expression watcher = stmt._watch.watcher;
11411 ProcessExpressionType(watcher);
11413 ProcessExpressionType(object);
11417 if(watcher || thisClass)
11419 External external = curExternal;
11420 Context context = curContext;
11422 stmt.type = expressionStmt;
11423 stmt.expressions = MkList();
11425 curExternal = external.prev;
11427 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11429 ClassFunction func;
11430 char watcherName[1024];
11431 Class watcherClass = watcher ?
11432 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11433 External createdExternal;
11435 // Create a declaration above
11436 External externalDecl = MkExternalDeclaration(null);
11437 ast->Insert(curExternal.prev, externalDecl);
11439 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11440 if(propWatch.deleteWatch)
11441 strcat(watcherName, "_delete");
11445 for(propID = propWatch.properties->first; propID; propID = propID.next)
11447 strcat(watcherName, "_");
11448 strcat(watcherName, propID.string);
11452 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11454 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11455 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11456 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11457 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11458 ProcessClassFunctionBody(func, propWatch.compound);
11459 propWatch.compound = null;
11461 //afterExternal = afterExternal ? afterExternal : curExternal;
11463 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11464 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11466 createdExternal.symbol.idCode = external.symbol.idCode;
11468 curExternal = createdExternal;
11469 ProcessFunction(createdExternal.function);
11472 // Create a declaration above
11474 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11475 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11476 externalDecl.declaration = decl;
11477 if(decl.symbol && !decl.symbol.pointerExternal)
11478 decl.symbol.pointerExternal = externalDecl;
11481 if(propWatch.deleteWatch)
11483 OldList * args = MkList();
11484 ListAdd(args, CopyExpression(object));
11485 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11486 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11487 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11491 Class _class = object.expType._class.registered;
11494 for(propID = propWatch.properties->first; propID; propID = propID.next)
11496 char propName[1024];
11497 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11500 char getName[1024], setName[1024];
11501 OldList * args = MkList();
11503 DeclareProperty(prop, setName, getName);
11505 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11506 strcpy(propName, "__ecereProp_");
11507 FullClassNameCat(propName, prop._class.fullName, false);
11508 strcat(propName, "_");
11509 // strcat(propName, prop.name);
11510 FullClassNameCat(propName, prop.name, true);
11512 ListAdd(args, CopyExpression(object));
11513 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11514 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11515 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11517 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11520 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11525 Compiler_Error($"Invalid watched object\n");
11528 curExternal = external;
11529 curContext = context;
11532 FreeExpression(watcher);
11534 FreeExpression(object);
11535 FreeList(watches, FreePropertyWatch);
11538 Compiler_Error($"No observer specified and not inside a _class\n");
11542 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11544 ProcessStatement(propWatch.compound);
11550 case fireWatchersStmt:
11552 OldList * watches = stmt._watch.watches;
11553 Expression object = stmt._watch.object;
11555 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11556 // printf("%X\n", watches);
11557 // printf("%X\n", stmt._watch.watches);
11559 ProcessExpressionType(object);
11564 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11570 stmt.type = expressionStmt;
11571 stmt.expressions = MkList();
11573 // Check if we're inside a property set
11574 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11576 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
11580 //Compiler_Error($"No property specified and not inside a property set\n");
11584 for(propID = watches->first; propID; propID = propID.next)
11586 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11589 CreateFireWatcher(prop, object, stmt);
11592 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
11597 // Fire all properties!
11600 for(base = _class; base; base = base.base)
11602 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
11604 if(prop.isProperty && prop.isWatchable)
11606 CreateFireWatcher(prop, object, stmt);
11613 FreeExpression(object);
11614 FreeList(watches, FreeIdentifier);
11617 Compiler_Error($"Invalid object specified and not inside a class\n");
11621 case stopWatchingStmt:
11623 OldList * watches = stmt._watch.watches;
11624 Expression object = stmt._watch.object;
11625 Expression watcher = stmt._watch.watcher;
11628 ProcessExpressionType(object);
11630 ProcessExpressionType(watcher);
11633 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
11635 if(watcher || thisClass)
11641 stmt.type = expressionStmt;
11642 stmt.expressions = MkList();
11647 // eInstance_StopWatching(object, null, watcher);
11649 ListAdd(args, CopyExpression(object));
11650 ListAdd(args, MkExpConstant("0"));
11651 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11652 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11656 for(propID = watches->first; propID; propID = propID.next)
11658 char propName[1024];
11659 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11662 char getName[1024], setName[1024];
11663 OldList * args = MkList();
11665 DeclareProperty(prop, setName, getName);
11667 // eInstance_StopWatching(object, prop, watcher);
11668 strcpy(propName, "__ecereProp_");
11669 FullClassNameCat(propName, prop._class.fullName, false);
11670 strcat(propName, "_");
11671 // strcat(propName, prop.name);
11672 FullClassNameCat(propName, prop.name, true);
11673 MangleClassName(propName);
11675 ListAdd(args, CopyExpression(object));
11676 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11677 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11678 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11681 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11686 FreeExpression(object);
11688 FreeExpression(watcher);
11689 FreeList(watches, FreeIdentifier);
11692 Compiler_Error($"Invalid object specified and not inside a class\n");
11695 Compiler_Error($"No observer specified and not inside a class\n");
11702 static void ProcessFunction(FunctionDefinition function)
11704 Identifier id = GetDeclId(function.declarator);
11705 Symbol symbol = function.declarator ? function.declarator.symbol : null;
11706 Type type = symbol ? symbol.type : null;
11707 Class oldThisClass = thisClass;
11708 Context oldTopContext = topContext;
11710 yylloc = function.loc;
11711 // Process thisClass
11713 if(type && type.thisClass)
11715 Symbol classSym = type.thisClass;
11716 Class _class = type.thisClass.registered;
11717 char className[1024];
11718 char structName[1024];
11719 Declarator funcDecl;
11722 bool typedObject = false;
11724 if(_class && !_class.base)
11726 _class = currentClass;
11727 if(_class && !_class.symbol)
11728 _class.symbol = FindClass(_class.fullName);
11729 classSym = _class ? _class.symbol : null;
11730 typedObject = true;
11733 thisClass = _class;
11735 if(inCompiler && _class)
11737 if(type.kind == functionType)
11739 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
11741 //TypeName param = symbol.type.params.first;
11742 Type param = symbol.type.params.first;
11743 symbol.type.params.Remove(param);
11744 //FreeTypeName(param);
11747 if(type.classObjectType != classPointer)
11749 symbol.type.params.Insert(null, MkClassType(_class.fullName));
11750 symbol.type.staticMethod = true;
11751 symbol.type.thisClass = null;
11753 // HIGH DANGER: VERIFYING THIS...
11754 symbol.type.extraParam = false;
11758 strcpy(className, "__ecereClass_");
11759 FullClassNameCat(className, _class.fullName, true);
11761 MangleClassName(className);
11764 FullClassNameCat(structName, _class.fullName, false);
11769 funcDecl = GetFuncDecl(function.declarator);
11772 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11774 TypeName param = funcDecl.function.parameters->first;
11775 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11777 funcDecl.function.parameters->Remove(param);
11778 FreeTypeName(param);
11782 // DANGER: Watch for this... Check if it's a Conversion?
11783 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11785 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
11786 if(!function.propertyNoThis)
11788 TypeName thisParam;
11790 if(type.classObjectType != classPointer)
11792 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11793 if(!funcDecl.function.parameters)
11794 funcDecl.function.parameters = MkList();
11795 funcDecl.function.parameters->Insert(null, thisParam);
11800 if(type.classObjectType != classPointer)
11802 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
11803 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
11806 thisParam = TypeName
11808 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11809 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11811 funcDecl.function.parameters->Insert(null, thisParam);
11816 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11818 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11819 funcDecl = GetFuncDecl(initDecl.declarator);
11822 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11824 TypeName param = funcDecl.function.parameters->first;
11825 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11827 funcDecl.function.parameters->Remove(param);
11828 FreeTypeName(param);
11832 if(type.classObjectType != classPointer)
11834 // DANGER: Watch for this... Check if it's a Conversion?
11835 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11837 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11839 if(!funcDecl.function.parameters)
11840 funcDecl.function.parameters = MkList();
11841 funcDecl.function.parameters->Insert(null, thisParam);
11848 // Add this to the context
11851 if(type.classObjectType != classPointer)
11853 thisSymbol = Symbol
11855 string = CopyString("this");
11856 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
11858 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
11860 if(typedObject && thisSymbol.type)
11862 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
11863 thisSymbol.type.byReference = type.byReference;
11865 thisSymbol = Symbol { string = CopyString("class") };
11866 function.body.compound.context.symbols.Add(thisSymbol);
11872 // Pointer to class data
11874 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
11876 DataMember member = null;
11879 for(base = _class; base && base.type != systemClass; base = base.next)
11881 for(member = base.membersAndProperties.first; member; member = member.next)
11882 if(!member.isProperty)
11888 for(member = _class.membersAndProperties.first; member; member = member.next)
11889 if(!member.isProperty)
11893 char pointerName[1024];
11896 Initializer initializer;
11897 Expression exp, bytePtr;
11899 strcpy(pointerName, "__ecerePointer_");
11900 FullClassNameCat(pointerName, _class.fullName, false);
11902 char className[1024];
11903 strcpy(className, "__ecereClass_");
11904 FullClassNameCat(className, classSym.string, true);
11905 MangleClassName(className);
11908 DeclareClass(classSym, className);
11912 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
11917 sprintf(string, "%d", _class.offset);
11918 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
11922 // ([bytePtr] + [className]->offset)
11923 exp = QBrackets(MkExpOp(bytePtr, '+',
11924 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
11927 // (this ? [exp] : 0)
11928 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
11932 kind = pointerType;
11933 type = Type { refCount = 1, kind = voidType };
11938 yylloc = function.body.loc;
11939 // ([structName] *) [exp]
11940 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
11941 initializer = MkInitializerAssignment(
11942 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
11944 // [structName] * [pointerName] = [initializer];
11945 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
11948 Context prevContext = curContext;
11949 curContext = function.body.compound.context;
11951 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
11952 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
11954 curContext = prevContext;
11958 decl.symbol = null;
11960 if(!function.body.compound.declarations)
11961 function.body.compound.declarations = MkList();
11962 function.body.compound.declarations->Insert(null, decl);
11968 // Loop through the function and replace undeclared identifiers
11969 // which are a member of the class (methods, properties or data)
11970 // by "this.[member]"
11977 FreeSpecifier(id._class);
11980 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11982 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11983 id = GetDeclId(initDecl.declarator);
11985 FreeSpecifier(id._class);
11990 topContext = function.body.compound.context;
11992 FunctionDefinition oldFunction = curFunction;
11993 curFunction = function;
11995 ProcessStatement(function.body);
11997 // If this is a property set and no firewatchers has been done yet, add one here
11998 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12000 Statement prevCompound = curCompound;
12001 Context prevContext = curContext;
12003 Statement fireWatchers = MkFireWatchersStmt(null, null);
12004 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12005 ListAdd(function.body.compound.statements, fireWatchers);
12007 curCompound = function.body;
12008 curContext = function.body.compound.context;
12010 ProcessStatement(fireWatchers);
12012 curContext = prevContext;
12013 curCompound = prevCompound;
12017 curFunction = oldFunction;
12020 if(function.declarator)
12022 ProcessDeclarator(function.declarator);
12025 topContext = oldTopContext;
12026 thisClass = oldThisClass;
12029 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12030 static void ProcessClass(OldList definitions, Symbol symbol)
12033 External external = curExternal;
12034 Class regClass = symbol ? symbol.registered : null;
12036 // Process all functions
12037 for(def = definitions.first; def; def = def.next)
12039 if(def.type == functionClassDef)
12041 if(def.function.declarator)
12042 curExternal = def.function.declarator.symbol.pointerExternal;
12044 curExternal = external;
12046 ProcessFunction((FunctionDefinition)def.function);
12048 else if(def.type == declarationClassDef)
12050 if(def.decl.type == instDeclaration)
12052 thisClass = regClass;
12053 ProcessInstantiationType(def.decl.inst);
12059 Class backThisClass = thisClass;
12060 if(regClass) thisClass = regClass;
12061 ProcessDeclaration(def.decl);
12062 thisClass = backThisClass;
12065 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12067 MemberInit defProperty;
12069 // Add this to the context
12070 Symbol thisSymbol = Symbol
12072 string = CopyString("this");
12073 type = regClass ? MkClassType(regClass.fullName) : null;
12075 globalContext.symbols.Add((BTNode)thisSymbol);
12077 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12079 thisClass = regClass;
12080 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12084 globalContext.symbols.Remove((BTNode)thisSymbol);
12085 FreeSymbol(thisSymbol);
12087 else if(def.type == propertyClassDef && def.propertyDef)
12089 PropertyDef prop = def.propertyDef;
12091 // Add this to the context
12093 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12094 globalContext.symbols.Add(thisSymbol);
12097 thisClass = regClass;
12104 string = CopyString("this");
12105 type = MkClassType(regClass.fullName);
12107 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12110 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12111 ProcessStatement(prop.setStmt);
12119 string = CopyString("this");
12120 type = MkClassType(regClass.fullName);
12122 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12125 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12126 ProcessStatement(prop.getStmt);
12134 string = CopyString("this");
12135 type = MkClassType(regClass.fullName);
12137 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12140 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12141 ProcessStatement(prop.issetStmt);
12147 globalContext.symbols.Remove(thisSymbol);
12148 FreeSymbol(thisSymbol);
12151 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12153 PropertyWatch propertyWatch = def.propertyWatch;
12155 thisClass = regClass;
12156 if(propertyWatch.compound)
12160 string = CopyString("this");
12161 type = regClass ? MkClassType(regClass.fullName) : null;
12164 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12166 curExternal = null;
12167 ProcessStatement(propertyWatch.compound);
12174 void DeclareFunctionUtil(String s)
12176 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12181 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12182 strcpy(name, "__ecereFunction_");
12183 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12184 DeclareFunction(function, name);
12188 void ComputeDataTypes()
12192 External after = null;
12194 currentClass = null;
12196 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12198 for(external = ast->first; external; external = external.next)
12200 if(external.type == declarationExternal)
12202 Declaration decl = external.declaration;
12205 OldList * decls = decl.declarators;
12208 InitDeclarator initDecl = decls->first;
12211 Declarator declarator = initDecl.declarator;
12212 if(declarator && declarator.type == identifierDeclarator)
12214 Identifier id = declarator.identifier;
12215 if(id && id.string)
12217 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12219 external.symbol.id = -1001, external.symbol.idCode = -1001;
12230 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12231 ast->Insert(after, temp);
12232 curExternal = temp;
12234 DeclareFunctionUtil("eSystem_New");
12235 DeclareFunctionUtil("eSystem_New0");
12236 DeclareFunctionUtil("eSystem_Renew");
12237 DeclareFunctionUtil("eSystem_Renew0");
12238 DeclareFunctionUtil("eClass_GetProperty");
12240 DeclareStruct("ecere::com::Class", false);
12241 DeclareStruct("ecere::com::Instance", false);
12242 DeclareStruct("ecere::com::Property", false);
12243 DeclareStruct("ecere::com::DataMember", false);
12244 DeclareStruct("ecere::com::Method", false);
12245 DeclareStruct("ecere::com::SerialBuffer", false);
12246 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12250 for(external = ast->first; external; external = external.next)
12252 afterExternal = curExternal = external;
12253 if(external.type == functionExternal)
12255 currentClass = external.function._class;
12256 ProcessFunction(external.function);
12258 // There shouldn't be any _class member access here anyways...
12259 else if(external.type == declarationExternal)
12261 currentClass = null;
12262 ProcessDeclaration(external.declaration);
12264 else if(external.type == classExternal)
12266 ClassDefinition _class = external._class;
12267 currentClass = external.symbol.registered;
12268 if(_class.definitions)
12270 ProcessClass(_class.definitions, _class.symbol);
12274 // Free class data...
12275 ast->Remove(external);
12279 else if(external.type == nameSpaceExternal)
12281 thisNameSpace = external.id.string;
12284 currentClass = null;
12285 thisNameSpace = null;
12287 delete temp.symbol;