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", (int)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", (int)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;
761 type.alignment = type.type.alignment;
767 for(member = type.members.first; member; member = member.next)
769 uint addSize = ComputeTypeSize(member);
771 member.offset = size;
772 if(member.alignment && size % member.alignment)
773 member.offset += member.alignment - (size % member.alignment);
774 size = member.offset;
776 type.alignment = Max(type.alignment, member.alignment);
779 if(type.alignment && size % type.alignment)
780 size += type.alignment - (size % type.alignment);
786 for(member = type.members.first; member; member = member.next)
788 uint addSize = ComputeTypeSize(member);
790 member.offset = size;
791 if(member.alignment && size % member.alignment)
792 member.offset += member.alignment - (size % member.alignment);
793 size = member.offset;
795 type.alignment = Max(type.alignment, member.alignment);
796 size = Max(size, addSize);
798 if(type.alignment && size % type.alignment)
799 size += type.alignment - (size % type.alignment);
804 TemplateParameter param = type.templateParameter;
805 Type baseType = ProcessTemplateParameterType(param);
808 size = ComputeTypeSize(baseType);
809 type.alignment = baseType.alignment;
812 type.alignment = size = sizeof(uint64);
817 type.alignment = size = sizeof(enum { test });
822 type.alignment = size = targetBits / 8; //sizeof(void *);
827 type.computing = false;
833 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
835 // This function is in need of a major review when implementing private members etc.
836 DataMember topMember = isMember ? (DataMember) _class : null;
841 Context context = isMember ? null : SetupTemplatesContext(_class);
843 *addedPadding = false;
845 if(!isMember && _class.base)
847 maxSize = _class.structSize;
848 //if(_class.base.type != systemClass) // Commented out with new Instance _class
850 // DANGER: Testing this noHeadClass here...
851 if(_class.type == structClass || _class.type == noHeadClass)
852 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
855 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
856 if(maxSize > baseSize)
864 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
866 if(!member.isProperty)
872 if(member.dataTypeString)
874 OldList * specs = MkList(), * decls = MkList();
877 decl = SpecDeclFromString(member.dataTypeString, specs,
878 MkDeclaratorIdentifier(MkIdentifier(member.name)));
879 ListAdd(decls, MkStructDeclarator(decl, null));
880 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
883 member.dataType = ProcessType(specs, decl);
885 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
888 Type type = ProcessType(specs, decl);
889 DeclareType(member.dataType, false, false);
893 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
894 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
895 DeclareStruct(member.dataType._class.string, false);
898 ComputeTypeSize(member.dataType);
899 size = member.dataType.size;
900 alignment = member.dataType.alignment;
904 if(totalSize % alignment)
905 totalSize += alignment - (totalSize % alignment);
914 OldList * specs = MkList(), * list = MkList();
917 AddMembers(list, (Class)member, true, &size, topClass, null);
919 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
920 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
921 alignment = member.structAlignment;
925 if(totalSize % alignment)
926 totalSize += alignment - (totalSize % alignment);
936 if(topMember && topMember.type == unionMember)
937 *retSize = Max(*retSize, totalSize);
939 *retSize += totalSize;
941 else if(totalSize < maxSize && _class.type != systemClass)
944 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
945 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
946 if(totalSize + autoPadding < maxSize)
949 sprintf(sizeString, "%d", maxSize - totalSize);
950 ListAdd(declarations,
951 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
952 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
954 *addedPadding = true;
958 FinishTemplatesContext(context);
959 return topMember ? topMember.memberID : _class.memberID;
962 static int DeclareMembers(Class _class, bool isMember)
964 DataMember topMember = isMember ? (DataMember) _class : null;
967 Context context = isMember ? null : SetupTemplatesContext(_class);
969 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
970 DeclareMembers(_class.base, false);
972 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
974 if(!member.isProperty)
981 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
982 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
983 DeclareStruct(member.dataType._class.string, false);
985 if(!member.dataType && member.dataTypeString)
986 member.dataType = ProcessTypeString(member.dataTypeString, false);
988 DeclareType(member.dataType, false, false);
994 DeclareMembers((Class)member, true);
1001 FinishTemplatesContext(context);
1003 return topMember ? topMember.memberID : _class.memberID;
1006 void DeclareStruct(char * name, bool skipNoHead)
1008 External external = null;
1009 Symbol classSym = FindClass(name);
1011 if(!inCompiler || !classSym) return;
1013 // We don't need any declaration for bit classes...
1014 if(classSym.registered &&
1015 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1018 /*if(classSym.registered.templateClass)
1019 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1022 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1024 // Add typedef struct
1026 OldList * specifiers, * declarators;
1027 OldList * declarations = null;
1028 char structName[1024];
1029 external = (classSym.registered && classSym.registered.type == structClass) ?
1030 classSym.pointerExternal : classSym.structExternal;
1032 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1033 // Moved this one up because DeclareClass done later will need it
1035 classSym.declaring++;
1037 if(strchr(classSym.string, '<'))
1039 if(classSym.registered.templateClass)
1041 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1042 classSym.declaring--;
1048 DeclareMembers(classSym.registered, false);
1051 FullClassNameCat(structName, name, false);
1054 external = MkExternalDeclaration(null);*/
1058 bool addedPadding = false;
1059 classSym.declaredStructSym = true;
1061 declarations = MkList();
1063 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1065 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1066 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1068 if(!declarations->count || (declarations->count == 1 && addedPadding))
1070 FreeList(declarations, FreeClassDef);
1071 declarations = null;
1074 if(skipNoHead || declarations)
1076 if(external && external.declaration)
1078 ((Specifier)external.declaration.specifiers->first).definitions = declarations;
1080 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1083 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1086 if(classSym.structExternal)
1087 ast->Move(classSym.structExternal, curExternal.prev);
1088 ast->Move(classSym.pointerExternal, curExternal.prev);
1090 classSym.id = curExternal.symbol.idCode;
1091 classSym.idCode = curExternal.symbol.idCode;
1092 // external = classSym.pointerExternal;
1093 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1099 external = MkExternalDeclaration(null);
1101 specifiers = MkList();
1102 declarators = MkList();
1103 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1106 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1107 ListAdd(declarators, MkInitDeclarator(d, null));
1109 external.declaration = decl = MkDeclaration(specifiers, declarators);
1110 if(decl.symbol && !decl.symbol.pointerExternal)
1111 decl.symbol.pointerExternal = external;
1113 // For simple classes, keep the declaration as the external to move around
1114 if(classSym.registered && classSym.registered.type == structClass)
1116 char className[1024];
1117 strcpy(className, "__ecereClass_");
1118 FullClassNameCat(className, classSym.string, true);
1119 MangleClassName(className);
1122 DeclareClass(classSym, className);
1124 external.symbol = classSym;
1125 classSym.pointerExternal = external;
1126 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1127 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1131 char className[1024];
1132 strcpy(className, "__ecereClass_");
1133 FullClassNameCat(className, classSym.string, true);
1134 MangleClassName(className);
1136 // TOFIX: TESTING THIS...
1137 classSym.structExternal = external;
1138 DeclareClass(classSym, className);
1139 external.symbol = classSym;
1143 ast->Insert(curExternal ? curExternal.prev : null, external);
1147 classSym.declaring--;
1149 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1151 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1152 // Moved this one up because DeclareClass done later will need it
1155 classSym.declaring++;
1159 if(classSym.registered)
1160 DeclareMembers(classSym.registered, false);
1163 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1166 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1169 if(classSym.structExternal)
1170 ast->Move(classSym.structExternal, curExternal.prev);
1171 ast->Move(classSym.pointerExternal, curExternal.prev);
1173 classSym.id = curExternal.symbol.idCode;
1174 classSym.idCode = curExternal.symbol.idCode;
1175 // external = classSym.pointerExternal;
1176 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1179 classSym.declaring--;
1184 void DeclareProperty(Property prop, char * setName, char * getName)
1186 Symbol symbol = prop.symbol;
1187 char propName[1024];
1189 strcpy(setName, "__ecereProp_");
1190 FullClassNameCat(setName, prop._class.fullName, false);
1191 strcat(setName, "_Set_");
1192 // strcat(setName, prop.name);
1193 FullClassNameCat(setName, prop.name, true);
1195 strcpy(getName, "__ecereProp_");
1196 FullClassNameCat(getName, prop._class.fullName, false);
1197 strcat(getName, "_Get_");
1198 FullClassNameCat(getName, prop.name, true);
1199 // strcat(getName, prop.name);
1201 strcpy(propName, "__ecereProp_");
1202 FullClassNameCat(propName, prop._class.fullName, false);
1203 strcat(propName, "_");
1204 FullClassNameCat(propName, prop.name, true);
1205 // strcat(propName, prop.name);
1207 // To support "char *" property
1208 MangleClassName(getName);
1209 MangleClassName(setName);
1210 MangleClassName(propName);
1212 if(prop._class.type == structClass)
1213 DeclareStruct(prop._class.fullName, false);
1215 if(!symbol || curExternal.symbol.idCode < symbol.id)
1217 bool imported = false;
1218 bool dllImport = false;
1219 if(!symbol || symbol._import)
1224 if(!prop._class.symbol)
1225 prop._class.symbol = FindClass(prop._class.fullName);
1226 classSym = prop._class.symbol;
1227 if(classSym && !classSym._import)
1229 ModuleImport module;
1231 if(prop._class.module)
1232 module = FindModule(prop._class.module);
1234 module = mainModule;
1236 classSym._import = ClassImport
1238 name = CopyString(prop._class.fullName);
1239 isRemote = prop._class.isRemote;
1241 module.classes.Add(classSym._import);
1243 symbol = prop.symbol = Symbol { };
1244 symbol._import = (ClassImport)PropertyImport
1246 name = CopyString(prop.name);
1247 isVirtual = false; //prop.isVirtual;
1248 hasSet = prop.Set ? true : false;
1249 hasGet = prop.Get ? true : false;
1252 classSym._import.properties.Add(symbol._import);
1255 if(prop._class.module != privateModule && prop._class.module.importType != staticImport)
1261 Context context = SetupTemplatesContext(prop._class);
1262 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1263 FinishTemplatesContext(context);
1269 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1272 OldList * specifiers, * declarators;
1277 Declarator typeDecl;
1278 bool simple = false;
1280 specifiers = MkList();
1281 declarators = MkList();
1284 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1285 MkDeclaratorIdentifier(MkIdentifier("this"))));
1287 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1290 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1293 Context context = SetupTemplatesContext(prop._class);
1294 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1295 FinishTemplatesContext(context);
1298 // Make sure the simple _class's type is declared
1299 for(spec = specifiers->first; spec; spec = spec.next)
1301 if(spec.type == nameSpecifier /*SpecifierClass*/)
1303 if((!typeDecl || typeDecl.type == identifierDeclarator))
1305 Symbol classSym = spec.symbol; // FindClass(spec.name);
1306 symbol._class = classSym.registered;
1307 if(classSym.registered && classSym.registered.type == structClass)
1309 DeclareStruct(spec.name, false);
1317 d = PlugDeclarator(typeDecl, d);
1320 ListAdd(params, MkTypeName(specifiers,
1321 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1322 specifiers = MkList();
1325 d = MkDeclaratorFunction(d, params);
1329 specifiers->Insert(null, MkSpecifier(EXTERN));
1330 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1331 specifiers->Insert(null, MkSpecifier(STATIC));
1333 ListAdd(specifiers, MkSpecifier(VOID));
1335 ListAdd(declarators, MkInitDeclarator(d, null));
1337 decl = MkDeclaration(specifiers, declarators);
1339 external = MkExternalDeclaration(decl);
1340 ast->Insert(curExternal.prev, external);
1341 external.symbol = symbol;
1342 symbol.externalGet = external;
1344 ReplaceThisClassSpecifiers(specifiers, prop._class);
1347 FreeDeclarator(typeDecl);
1351 // Move declaration higher...
1352 ast->Move(symbol.externalGet, curExternal.prev);
1359 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1362 OldList * specifiers, * declarators;
1367 Declarator typeDecl;
1369 declarators = MkList();
1372 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1373 if(!prop.conversion || prop._class.type == structClass)
1375 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1376 MkDeclaratorIdentifier(MkIdentifier("this"))));
1379 specifiers = MkList();
1382 Context context = SetupTemplatesContext(prop._class);
1383 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1384 MkDeclaratorIdentifier(MkIdentifier("value")));
1385 FinishTemplatesContext(context);
1387 ListAdd(params, MkTypeName(specifiers, d));
1389 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1392 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1393 d = MkDeclaratorFunction(d, params);
1395 // Make sure the simple _class's type is declared
1396 for(spec = specifiers->first; spec; spec = spec.next)
1398 if(spec.type == nameSpecifier /*SpecifierClass*/)
1400 if((!typeDecl || typeDecl.type == identifierDeclarator))
1402 Symbol classSym = spec.symbol; // FindClass(spec.name);
1403 symbol._class = classSym.registered;
1404 if(classSym.registered && classSym.registered.type == structClass)
1405 DeclareStruct(spec.name, false);
1410 ListAdd(declarators, MkInitDeclarator(d, null));
1412 specifiers = MkList();
1415 specifiers->Insert(null, MkSpecifier(EXTERN));
1416 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1417 specifiers->Insert(null, MkSpecifier(STATIC));
1419 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1420 if(!prop.conversion || prop._class.type == structClass)
1421 ListAdd(specifiers, MkSpecifier(VOID));
1423 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1425 decl = MkDeclaration(specifiers, declarators);
1427 external = MkExternalDeclaration(decl);
1428 ast->Insert(curExternal.prev, external);
1429 external.symbol = symbol;
1430 symbol.externalSet = external;
1432 ReplaceThisClassSpecifiers(specifiers, prop._class);
1436 // Move declaration higher...
1437 ast->Move(symbol.externalSet, curExternal.prev);
1441 // Property (for Watchers)
1442 if(!symbol.externalPtr)
1446 OldList * specifiers = MkList();
1449 specifiers->Insert(null, MkSpecifier(EXTERN));
1451 specifiers->Insert(null, MkSpecifier(STATIC));
1453 ListAdd(specifiers, MkSpecifierName("Property"));
1456 OldList * list = MkList();
1457 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1458 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1462 strcpy(propName, "__ecerePropM_");
1463 FullClassNameCat(propName, prop._class.fullName, false);
1464 strcat(propName, "_");
1465 // strcat(propName, prop.name);
1466 FullClassNameCat(propName, prop.name, true);
1468 MangleClassName(propName);
1470 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1471 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1473 decl = MkDeclaration(specifiers, list);
1476 external = MkExternalDeclaration(decl);
1477 ast->Insert(curExternal.prev, external);
1478 external.symbol = symbol;
1479 symbol.externalPtr = external;
1483 // Move declaration higher...
1484 ast->Move(symbol.externalPtr, curExternal.prev);
1487 symbol.id = curExternal.symbol.idCode;
1491 // ***************** EXPRESSION PROCESSING ***************************
1492 public Type Dereference(Type source)
1497 if(source.kind == pointerType || source.kind == arrayType)
1500 source.type.refCount++;
1502 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1510 // Support dereferencing of no head classes for now...
1511 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1517 Compiler_Error($"cannot dereference type\n");
1522 static Type Reference(Type source)
1538 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1540 Identifier ident = member.identifiers ? member.identifiers->first : null;
1542 DataMember dataMember = null;
1543 Method method = null;
1544 bool freeType = false;
1546 yylloc = member.loc;
1552 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1556 dataMember = *curMember;
1562 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1563 DataMember _subMemberStack[256];
1564 int _subMemberStackPos = 0;
1566 // FILL MEMBER STACK
1568 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1571 dataMember = thisMember;
1572 if(curMember && thisMember.memberAccess == publicAccess)
1574 *curMember = thisMember;
1575 *curClass = thisMember._class;
1576 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
1577 *subMemberStackPos = _subMemberStackPos;
1584 method = eClass_FindMethod(_class, ident.string, privateModule);
1585 if(method && method.type == virtualMethod)
1597 if(!dataMember.dataType && dataMember.dataTypeString)
1599 //Context context = SetupTemplatesContext(dataMember._class);
1600 Context context = SetupTemplatesContext(_class);
1601 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1602 FinishTemplatesContext(context);
1604 type = dataMember.dataType;
1608 // This is for destination type...
1609 if(!method.dataType)
1610 ProcessMethodType(method);
1611 //DeclareMethod(method);
1612 // method.dataType = ((Symbol)method.symbol)->type;
1613 type = method.dataType;
1616 if(ident && ident.next)
1618 for(ident = ident.next; ident && type; ident = ident.next)
1620 if(type.kind == classType)
1622 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1624 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1626 type = dataMember.dataType;
1628 else if(type.kind == structType || type.kind == unionType)
1631 for(memberType = type.members.first; memberType; memberType = memberType.next)
1633 if(!strcmp(memberType.name, ident.string))
1643 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1644 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1647 ClassTemplateParameter curParam = null;
1649 for(sClass = _class; sClass; sClass = sClass.base)
1652 if(sClass.templateClass) sClass = sClass.templateClass;
1653 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1655 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1657 for(sClass = sClass.base; sClass; sClass = sClass.base)
1659 if(sClass.templateClass) sClass = sClass.templateClass;
1660 id += sClass.templateParams.count;
1671 ClassTemplateArgument arg = _class.templateArgs[id];
1672 if(arg.dataTypeString)
1675 type = ProcessTypeString(arg.dataTypeString, false);
1677 if(type && _class.templateClass)
1678 type.passAsTemplate = true;
1684 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1685 exp.destType.refCount++;
1691 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1693 Class expClass = type._class.registered;
1694 Class cClass = null;
1699 char templateString[1024];
1700 ClassTemplateParameter param;
1701 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1702 for(cClass = expClass; cClass; cClass = cClass.base)
1705 if(cClass.templateClass) cClass = cClass.templateClass;
1706 for(param = cClass.templateParams.first; param; param = param.next)
1710 ClassTemplateArgument arg;
1711 for(sClass = cClass.base; sClass; sClass = sClass.base)
1713 if(sClass.templateClass) sClass = sClass.templateClass;
1714 id += sClass.templateParams.count;
1716 arg = expClass.templateArgs[id];
1718 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1720 ClassTemplateParameter cParam;
1721 //int p = numParams - sClass.templateParams.count;
1724 if(sClass.templateClass) sClass = sClass.templateClass;
1726 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1728 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1729 p += nextClass.templateParams.count;
1732 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1734 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1736 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1738 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1739 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1751 strcat(argument, arg.name.string);
1752 strcat(argument, " = ");
1758 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1759 char expString[1024];
1760 OldList * specs = MkList();
1761 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1763 char * string = PrintHexUInt64(arg.expression.ui64);
1764 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1766 ProcessExpressionType(exp);
1767 ComputeExpression(exp);
1768 expString[0] = '\0';
1769 PrintExpression(exp, expString);
1770 strcat(argument, expString);
1772 FreeExpression(exp);
1777 strcat(argument, arg.member.name);
1780 case TemplateParameterType::type:
1782 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1783 strcat(argument, arg.dataTypeString);
1789 if(paramCount) strcat(templateString, ", ");
1790 if(lastParam != p - 1)
1792 strcat(templateString, param.name);
1793 strcat(templateString, " = ");
1795 strcat(templateString, argument);
1804 int len = strlen(templateString);
1805 if(templateString[len-1] == '<')
1809 if(templateString[len-1] == '>')
1810 templateString[len++] = ' ';
1811 templateString[len++] = '>';
1813 templateString[len++] = '\0';
1816 Context context = SetupTemplatesContext(_class);
1817 if(freeType) FreeType(type);
1818 type = ProcessTypeString(templateString, false);
1820 FinishTemplatesContext(context);
1824 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1826 ProcessExpressionType(member.initializer.exp);
1827 if(!member.initializer.exp.expType)
1831 char expString[10240];
1832 expString[0] = '\0';
1833 PrintExpression(member.initializer.exp, expString);
1834 ChangeCh(expString, '\n', ' ');
1835 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1838 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1839 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1841 Compiler_Error($"incompatible instance method %s\n", ident.string);
1844 else if(member.initializer)
1847 FreeType(member.exp.destType);
1848 member.exp.destType = type;
1849 if(member.exp.destType)
1850 member.exp.destType.refCount++;
1851 ProcessExpressionType(member.exp);
1854 ProcessInitializer(member.initializer, type);
1856 if(freeType) FreeType(type);
1860 if(_class && _class.type == unitClass)
1862 if(member.initializer)
1865 FreeType(member.exp.destType);
1866 member.exp.destType = MkClassType(_class.fullName);
1867 ProcessExpressionType(member.initializer, type);
1869 Type type = MkClassType(_class.fullName);
1870 ProcessInitializer(member.initializer, type);
1876 if(member.initializer)
1878 //ProcessExpressionType(member.exp);
1879 ProcessInitializer(member.initializer, null);
1885 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1889 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1891 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1895 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1900 void ProcessInstantiationType(Instantiation inst)
1905 MembersInit members;
1906 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1909 /*if(!inst._class.symbol)
1910 inst._class.symbol = FindClass(inst._class.name);*/
1911 classSym = inst._class.symbol;
1912 _class = classSym ? classSym.registered : null;
1914 // DANGER: Patch for mutex not declaring its struct when not needed
1915 if(!_class || _class.type != noHeadClass)
1916 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1918 afterExternal = afterExternal ? afterExternal : curExternal;
1921 ProcessExpressionType(inst.exp);
1923 inst.isConstant = true;
1926 DataMember curMember = null;
1927 Class curClass = null;
1928 DataMember subMemberStack[256];
1929 int subMemberStackPos = 0;
1931 for(members = inst.members->first; members; members = members.next)
1933 switch(members.type)
1935 case methodMembersInit:
1938 static uint instMethodID = 0;
1939 External external = curExternal;
1940 Context context = curContext;
1941 Declarator declarator = members.function.declarator;
1942 Identifier nameID = GetDeclId(declarator);
1943 char * unmangled = nameID ? nameID.string : null;
1945 External createdExternal = null;
1950 //members.function.dontMangle = true;
1951 strcpy(name, "__ecereInstMeth_");
1952 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
1954 strcat(name, nameID.string);
1956 sprintf(number, "_%08d", instMethodID++);
1957 strcat(name, number);
1958 nameID.string = CopyString(name);
1961 // Do modifications here...
1964 Symbol symbol = declarator.symbol;
1965 Method method = eClass_FindMethod(_class, unmangled, privateModule);
1967 if(method && method.type == virtualMethod)
1969 symbol.method = method;
1970 ProcessMethodType(method);
1972 if(!symbol.type.thisClass)
1974 if(method.dataType.thisClass && currentClass &&
1975 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
1977 if(!currentClass.symbol)
1978 currentClass.symbol = FindClass(currentClass.fullName);
1979 symbol.type.thisClass = currentClass.symbol;
1984 _class.symbol = FindClass(_class.fullName);
1985 symbol.type.thisClass = _class.symbol;
1988 // TESTING THIS HERE:
1989 DeclareType(symbol.type, true, true);
1994 Compiler_Error($"couldn't find virtual method %s in class %s\n",
1995 unmangled, classSym.string);
1999 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2000 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2004 FreeSpecifier(nameID._class);
2005 nameID._class = null;
2011 Type type = declarator.symbol.type;
2012 External oldExternal = curExternal;
2014 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2015 // *** It was commented out for problems such as
2017 class VirtualDesktop : Window
2019 clientSize = Size { };
2030 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2032 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2035 if(strcmp(declarator.symbol.string, name))
2037 printf("TOCHECK: Look out for this\n");
2038 delete declarator.symbol.string;
2039 declarator.symbol.string = CopyString(name);
2042 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2044 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2045 excludedSymbols->Remove(declarator.symbol);
2046 globalContext.symbols.Add((BTNode)declarator.symbol);
2047 if(strstr(declarator.symbol.string), "::")
2048 globalContext.hasNameSpace = true;
2053 //curExternal = curExternal.prev;
2054 //afterExternal = afterExternal->next;
2056 //ProcessFunction(afterExternal->function);
2058 //curExternal = afterExternal;
2060 External externalDecl;
2061 externalDecl = MkExternalDeclaration(null);
2062 ast->Insert(oldExternal.prev, externalDecl);
2064 // Which function does this process?
2065 if(createdExternal.function)
2067 ProcessFunction(createdExternal.function);
2069 //curExternal = oldExternal;
2072 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2074 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2075 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2077 //externalDecl = MkExternalDeclaration(decl);
2079 //***** ast->Insert(external.prev, externalDecl);
2080 //ast->Insert(curExternal.prev, externalDecl);
2081 externalDecl.declaration = decl;
2082 if(decl.symbol && !decl.symbol.pointerExternal)
2083 decl.symbol.pointerExternal = externalDecl;
2085 // Trying this out...
2086 declarator.symbol.pointerExternal = externalDecl;
2093 curExternal = declarator.symbol.pointerExternal;
2094 ProcessFunction((FunctionDefinition)members.function);
2096 curExternal = external;
2097 curContext = context;
2101 FreeClassFunction(members.function);
2103 // In this pass, turn this into a MemberInitData
2104 exp = QMkExpId(name);
2105 members.type = dataMembersInit;
2106 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2112 case dataMembersInit:
2114 if(members.dataMembers && classSym)
2117 Location oldyyloc = yylloc;
2118 for(member = members.dataMembers->first; member; member = member.next)
2120 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2121 if(member.initializer && !member.initializer.isConstant)
2122 inst.isConstant = false;
2134 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2136 // OPTIMIZATIONS: TESTING THIS...
2139 if(type.kind == functionType)
2144 for(param = type.params.first; param; param = param.next)
2145 DeclareType(param, declarePointers, true);
2147 DeclareType(type.returnType, declarePointers, true);
2149 else if(type.kind == pointerType && declarePointers)
2150 DeclareType(type.type, declarePointers, false);
2151 else if(type.kind == classType)
2153 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2154 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2156 else if(type.kind == structType || type.kind == unionType)
2159 for(member = type.members.first; member; member = member.next)
2160 DeclareType(member, false, false);
2162 else if(type.kind == arrayType)
2163 DeclareType(type.arrayType, declarePointers, false);
2167 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2169 ClassTemplateArgument * arg = null;
2171 ClassTemplateParameter curParam = null;
2173 for(sClass = _class; sClass; sClass = sClass.base)
2176 if(sClass.templateClass) sClass = sClass.templateClass;
2177 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2179 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2181 for(sClass = sClass.base; sClass; sClass = sClass.base)
2183 if(sClass.templateClass) sClass = sClass.templateClass;
2184 id += sClass.templateParams.count;
2194 arg = &_class.templateArgs[id];
2195 if(arg && param.type == type)
2196 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2201 public Context SetupTemplatesContext(Class _class)
2203 Context context = PushContext();
2204 context.templateTypesOnly = true;
2205 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2207 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2208 for(; param; param = param.next)
2210 if(param.type == type && param.identifier)
2212 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2213 curContext.templateTypes.Add((BTNode)type);
2220 for(sClass = _class; sClass; sClass = sClass.base)
2222 ClassTemplateParameter p;
2223 for(p = sClass.templateParams.first; p; p = p.next)
2225 //OldList * specs = MkList();
2226 //Declarator decl = null;
2227 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2230 TemplateParameter param = p.param;
2234 // ADD DATA TYPE HERE...
2235 p.param = param = TemplateParameter
2237 identifier = MkIdentifier(p.name), type = p.type,
2238 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2241 type = TemplatedType { key = (uintptr)p.name, param = param };
2242 curContext.templateTypes.Add((BTNode)type);
2250 public void FinishTemplatesContext(Context context)
2252 PopContext(context);
2253 FreeContext(context);
2257 public void ProcessMethodType(Method method)
2259 if(!method.dataType)
2261 Context context = SetupTemplatesContext(method._class);
2263 method.dataType = ProcessTypeString(method.dataTypeString, false);
2265 FinishTemplatesContext(context);
2267 if(method.type != virtualMethod && method.dataType)
2269 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2271 if(!method._class.symbol)
2272 method._class.symbol = FindClass(method._class.fullName);
2273 method.dataType.thisClass = method._class.symbol;
2277 // Why was this commented out? Working fine without now...
2280 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2281 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2288 char * par = strstr(type, "(");
2289 char * classOp = null;
2294 for(c = par-type-1; c >= 0; c++)
2296 if(type[c] == ':' && type[c+1] == ':')
2298 classOp = type + c - 1;
2299 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2306 else if(!isspace(type[c]))
2313 int typeLen = strlen(type);
2314 memcpy(temp, classOp, classOpLen);
2315 temp[classOpLen] = '\0';
2317 _class = eSystem_FindClass(module, temp);
2320 method.dataTypeString = new char[typeLen - classOpLen + 1];
2321 memcpy(method.dataTypeString, type, classOp - type);
2322 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2325 method.dataTypeString = type;
2331 public void ProcessPropertyType(Property prop)
2335 Context context = SetupTemplatesContext(prop._class);
2336 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2337 FinishTemplatesContext(context);
2341 public void DeclareMethod(Method method, char * name)
2343 Symbol symbol = method.symbol;
2344 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2346 bool imported = false;
2347 bool dllImport = false;
2349 if(!method.dataType)
2350 method.dataType = ProcessTypeString(method.dataTypeString, false);
2352 if(!symbol || symbol._import || method.type == virtualMethod)
2354 if(!symbol || method.type == virtualMethod)
2357 if(!method._class.symbol)
2358 method._class.symbol = FindClass(method._class.fullName);
2359 classSym = method._class.symbol;
2360 if(!classSym._import)
2362 ModuleImport module;
2364 if(method._class.module && method._class.module.name)
2365 module = FindModule(method._class.module);
2367 module = mainModule;
2368 classSym._import = ClassImport
2370 name = CopyString(method._class.fullName);
2371 isRemote = method._class.isRemote;
2373 module.classes.Add(classSym._import);
2377 symbol = method.symbol = Symbol { };
2381 symbol._import = (ClassImport)MethodImport
2383 name = CopyString(method.name);
2384 isVirtual = method.type == virtualMethod;
2386 classSym._import.methods.Add(symbol._import);
2390 // Set the symbol type
2394 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2396 else if(type.thisClass == (void *)-1)
2398 type.thisClass = null;
2401 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2402 symbol.type = method.dataType;
2403 if(symbol.type) symbol.type.refCount++;
2406 if(!method.thisClass || strcmp(method.thisClass, "void"))
2407 symbol.type.params.Insert(null,
2408 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2411 if(!method.dataType.dllExport)
2414 if(method._class.module != privateModule && method._class.module.importType != staticImport)
2420 if(!method.dataType)
2421 method.dataType = ((Symbol)method.symbol).type;
2422 //ProcessMethodType(method);
2425 if(method.type != virtualMethod && method.dataType)
2426 DeclareType(method.dataType, true, true);
2428 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2430 // We need a declaration here :)
2432 OldList * specifiers, * declarators;
2434 Declarator funcDecl;
2437 specifiers = MkList();
2438 declarators = MkList();
2442 ListAdd(specifiers, MkSpecifier(EXTERN));
2443 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2444 ListAdd(specifiers, MkSpecifier(STATIC));
2446 if(method.type == virtualMethod)
2448 ListAdd(specifiers, MkSpecifier(INT));
2449 d = MkDeclaratorIdentifier(MkIdentifier(name));
2453 d = MkDeclaratorIdentifier(MkIdentifier(name));
2456 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2458 Context context = SetupTemplatesContext(method._class);
2459 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2460 FinishTemplatesContext(context);
2462 funcDecl = GetFuncDecl(d);
2466 Specifier spec, next;
2467 for(spec = specifiers->first; spec; spec = next)
2470 if(spec.type == extendedSpecifier)
2472 specifiers->Remove(spec);
2473 FreeSpecifier(spec);
2478 // Add this parameter if not a static method
2479 if(method.dataType && !method.dataType.staticMethod)
2481 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2483 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2484 TypeName thisParam = MkTypeName(MkListOne(
2485 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2486 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2487 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2488 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2490 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2492 TypeName param = funcDecl.function.parameters->first;
2493 funcDecl.function.parameters->Remove(param);
2494 FreeTypeName(param);
2497 if(!funcDecl.function.parameters)
2498 funcDecl.function.parameters = MkList();
2499 funcDecl.function.parameters->Insert(null, thisParam);
2502 // Make sure we don't have empty parameter declarations for static methods...
2504 else if(!funcDecl.function.parameters)
2506 funcDecl.function.parameters = MkList();
2507 funcDecl.function.parameters->Insert(null,
2508 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2512 ProcessDeclarator(d);
2514 ListAdd(declarators, MkInitDeclarator(d, null));
2516 decl = MkDeclaration(specifiers, declarators);
2518 ReplaceThisClassSpecifiers(specifiers, method._class);
2520 // Keep a different symbol for the function definition than the declaration...
2521 if(symbol.pointerExternal)
2523 Symbol functionSymbol { };
2527 *functionSymbol = *symbol;
2528 functionSymbol.string = CopyString(symbol.string);
2529 if(functionSymbol.type)
2530 functionSymbol.type.refCount++;
2533 excludedSymbols->Add(functionSymbol);
2534 symbol.pointerExternal.symbol = functionSymbol;
2536 external = MkExternalDeclaration(decl);
2538 ast->Insert(curExternal ? curExternal.prev : null, external);
2539 external.symbol = symbol;
2540 symbol.pointerExternal = external;
2544 // Move declaration higher...
2545 ast->Move(symbol.pointerExternal, curExternal.prev);
2548 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2552 char * ReplaceThisClass(Class _class)
2554 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2558 ClassTemplateParameter param;
2561 char className[1024];
2562 strcpy(className, _class.fullName);
2563 for(param = _class.templateParams.first; param; param = param.next)
2565 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2567 if(first) strcat(className, "<");
2568 if(!first) strcat(className, ", ");
2569 if(lastParam + 1 != p)
2571 strcat(className, param.name);
2572 strcat(className, " = ");
2574 strcat(className, param.name);
2582 int len = strlen(className);
2583 if(className[len-1] == '>') className[len++] = ' ';
2584 className[len++] = '>';
2585 className[len++] = '\0';
2587 return CopyString(className);
2590 return CopyString(_class.fullName);
2593 Type ReplaceThisClassType(Class _class)
2595 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2599 ClassTemplateParameter param;
2601 char className[1024];
2602 strcpy(className, _class.fullName);
2604 for(param = _class.templateParams.first; param; param = param.next)
2606 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2608 if(first) strcat(className, "<");
2609 if(!first) strcat(className, ", ");
2610 if(lastParam + 1 != p)
2612 strcat(className, param.name);
2613 strcat(className, " = ");
2615 strcat(className, param.name);
2623 int len = strlen(className);
2624 if(className[len-1] == '>') className[len++] = ' ';
2625 className[len++] = '>';
2626 className[len++] = '\0';
2628 return MkClassType(className);
2629 //return ProcessTypeString(className, false);
2633 return MkClassType(_class.fullName);
2634 //return ProcessTypeString(_class.fullName, false);
2638 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2640 if(specs != null && _class)
2643 for(spec = specs.first; spec; spec = spec.next)
2645 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2647 spec.type = nameSpecifier;
2648 spec.name = ReplaceThisClass(_class);
2649 spec.symbol = FindClass(spec.name); //_class.symbol;
2655 // Returns imported or not
2656 bool DeclareFunction(GlobalFunction function, char * name)
2658 Symbol symbol = function.symbol;
2659 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2661 bool imported = false;
2662 bool dllImport = false;
2664 if(!function.dataType)
2666 function.dataType = ProcessTypeString(function.dataTypeString, false);
2667 if(!function.dataType.thisClass)
2668 function.dataType.staticMethod = true;
2675 ModuleImport module = FindModule(function.module);
2676 // WARNING: This is not added anywhere...
2677 symbol = function.symbol = Symbol { };
2681 if(!function.dataType.dllExport)
2683 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2684 module.functions.Add(symbol._import);
2687 // Set the symbol type
2689 symbol.type = ProcessTypeString(function.dataTypeString, false);
2690 if(!symbol.type.thisClass)
2691 symbol.type.staticMethod = true;
2694 imported = symbol._import ? true : false;
2695 if(imported && function.module != privateModule && function.module.importType != staticImport)
2699 DeclareType(function.dataType, true, true);
2703 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2705 // We need a declaration here :)
2707 OldList * specifiers, * declarators;
2709 Declarator funcDecl;
2712 specifiers = MkList();
2713 declarators = MkList();
2716 ListAdd(specifiers, MkSpecifier(EXTERN));
2719 ListAdd(specifiers, MkSpecifier(STATIC));
2722 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2725 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2727 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2728 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2729 if(function.module.importType == staticImport)
2732 for(spec = specifiers->first; spec; spec = spec.next)
2733 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2735 specifiers->Remove(spec);
2736 FreeSpecifier(spec);
2741 funcDecl = GetFuncDecl(d);
2743 // Make sure we don't have empty parameter declarations for static methods...
2744 if(funcDecl && !funcDecl.function.parameters)
2746 funcDecl.function.parameters = MkList();
2747 funcDecl.function.parameters->Insert(null,
2748 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2751 ListAdd(declarators, MkInitDeclarator(d, null));
2754 Context oldCtx = curContext;
2755 curContext = globalContext;
2756 decl = MkDeclaration(specifiers, declarators);
2757 curContext = oldCtx;
2760 // Keep a different symbol for the function definition than the declaration...
2761 if(symbol.pointerExternal)
2763 Symbol functionSymbol { };
2766 *functionSymbol = *symbol;
2767 functionSymbol.string = CopyString(symbol.string);
2768 if(functionSymbol.type)
2769 functionSymbol.type.refCount++;
2772 excludedSymbols->Add(functionSymbol);
2774 symbol.pointerExternal.symbol = functionSymbol;
2776 external = MkExternalDeclaration(decl);
2778 ast->Insert(curExternal.prev, external);
2779 external.symbol = symbol;
2780 symbol.pointerExternal = external;
2784 // Move declaration higher...
2785 ast->Move(symbol.pointerExternal, curExternal.prev);
2789 symbol.id = curExternal.symbol.idCode;
2792 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2795 void DeclareGlobalData(GlobalData data)
2797 Symbol symbol = data.symbol;
2798 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2803 symbol = data.symbol = Symbol { };
2806 data.dataType = ProcessTypeString(data.dataTypeString, false);
2807 DeclareType(data.dataType, true, true);
2810 if(!symbol.pointerExternal)
2812 // We need a declaration here :)
2814 OldList * specifiers, * declarators;
2818 specifiers = MkList();
2819 declarators = MkList();
2821 ListAdd(specifiers, MkSpecifier(EXTERN));
2822 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2823 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2825 ListAdd(declarators, MkInitDeclarator(d, null));
2827 decl = MkDeclaration(specifiers, declarators);
2828 external = MkExternalDeclaration(decl);
2830 ast->Insert(curExternal.prev, external);
2831 external.symbol = symbol;
2832 symbol.pointerExternal = external;
2836 // Move declaration higher...
2837 ast->Move(symbol.pointerExternal, curExternal.prev);
2841 symbol.id = curExternal.symbol.idCode;
2846 class Conversion : struct
2848 Conversion prev, next;
2854 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2858 // Property convert;
2860 if(source.kind == templateType && dest.kind != templateType)
2862 Type type = ProcessTemplateParameterType(source.templateParameter);
2863 if(type) source = type;
2866 if(dest.kind == templateType && source.kind != templateType)
2868 Type type = ProcessTemplateParameterType(dest.templateParameter);
2869 if(type) dest = type;
2872 if((dest.classObjectType == typedObject && source.classObjectType != anyObject) || (dest.classObjectType == anyObject && source.classObjectType != typedObject))
2877 if(source.classObjectType == anyObject && dest.classObjectType != typedObject)
2882 if((dest.kind == structType && source.kind == structType) ||
2883 (dest.kind == unionType && source.kind == unionType))
2885 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2886 (source.members.first && source.members.first == dest.members.first))
2890 if(dest.kind == ellipsisType && source.kind != voidType)
2893 if(dest.kind == pointerType && dest.type.kind == voidType &&
2894 ((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))
2895 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2897 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2899 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2901 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2902 ((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))
2903 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2905 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2907 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2910 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2912 if(source._class.registered && source._class.registered.type == unitClass)
2914 if(conversions != null)
2916 if(source._class.registered == dest._class.registered)
2921 Class sourceBase, destBase;
2922 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2923 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2924 if(sourceBase == destBase)
2928 // Don't match enum inheriting from other enum if resolving enumeration values
2929 // TESTING: !dest.classObjectType
2930 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2932 (!source._class.registered || source._class.registered.type != enumClass) ||
2933 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2937 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2939 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2940 source._class && source._class.registered && source._class.registered.type != enumClass)
2942 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2950 // JUST ADDED THIS...
2951 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
2956 // Just added this for Straight conversion of ColorAlpha => Color
2957 if(source.kind == classType)
2960 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
2963 for(convert = _class.conversions.first; convert; convert = convert.next)
2965 if(convert.memberAccess == publicAccess || _class.module == privateModule)
2967 Conversion after = (conversions != null) ? conversions.last : null;
2969 if(!convert.dataType)
2970 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
2971 if(MatchTypes(convert.dataType, dest, conversions, null, null, false, true, false, true))
2973 if(!conversions && !convert.Get)
2975 else if(conversions != null)
2977 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
2978 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
2979 (dest.kind != classType || dest._class.registered != _class.base))
2983 Conversion conv { convert = convert, isGet = true };
2984 // conversions.Add(conv);
2985 conversions.Insert(after, conv);
2997 if(dest.kind == classType)
3000 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3003 for(convert = _class.conversions.first; convert; convert = convert.next)
3005 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3007 // Conversion after = (conversions != null) ? conversions.last : null;
3009 if(!convert.dataType)
3010 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3011 // Just added this equality check to prevent recursion.... Make it safer?
3012 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3013 if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
3015 if(!conversions && !convert.Set)
3017 else if(conversions != null)
3019 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3020 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3021 (source.kind != classType || source._class.registered != _class.base))
3025 // *** Testing this! ***
3026 Conversion conv { convert = convert };
3027 conversions.Add(conv);
3028 //conversions.Insert(after, conv);
3036 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3038 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3039 (source.kind != classType || source._class.registered.type != structClass))
3043 // TESTING THIS... IS THIS OK??
3044 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3046 if(!dest._class.registered.dataType)
3047 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3048 // Only support this for classes...
3049 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3050 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3052 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3061 if(source.kind == classType)
3064 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3067 for(convert = _class.conversions.first; convert; convert = convert.next)
3069 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3071 Conversion after = (conversions != null) ? conversions.last : null;
3073 if(!convert.dataType)
3074 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3075 if(convert.dataType != source && MatchTypes(convert.dataType, dest, conversions, null, null, true, true, false, true))
3077 if(!conversions && !convert.Get)
3079 else if(conversions != null)
3081 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3082 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3083 (dest.kind != classType || dest._class.registered != _class.base))
3087 Conversion conv { convert = convert, isGet = true };
3089 // conversions.Add(conv);
3090 conversions.Insert(after, conv);
3099 // TESTING THIS... IS THIS OK??
3100 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3102 if(!source._class.registered.dataType)
3103 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3104 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, true, false, false))
3112 if(source.kind == classType || source.kind == subClassType)
3114 else if(dest.kind == source.kind &&
3115 (dest.kind != structType && dest.kind != unionType &&
3116 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3118 // RECENTLY ADDED THESE
3119 else if(dest.kind == doubleType && source.kind == floatType)
3121 else if(dest.kind == shortType && source.kind == charType)
3123 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == intSizeType /* Exception here for size_t */))
3125 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3127 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3129 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3131 else if(source.kind == enumType &&
3132 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3134 else if(dest.kind == enumType &&
3135 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3137 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3138 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3140 Type paramSource, paramDest;
3142 if(dest.kind == methodType)
3143 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3144 if(source.kind == methodType)
3145 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3147 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3148 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3149 if(dest.kind == methodType)
3150 dest = dest.method.dataType;
3151 if(source.kind == methodType)
3152 source = source.method.dataType;
3154 paramSource = source.params.first;
3155 if(paramSource && paramSource.kind == voidType) paramSource = null;
3156 paramDest = dest.params.first;
3157 if(paramDest && paramDest.kind == voidType) paramDest = null;
3160 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3161 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3163 // Source thisClass must be derived from destination thisClass
3164 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3165 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3167 if(paramDest && paramDest.kind == classType)
3168 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3170 Compiler_Error($"method class should not take an object\n");
3173 paramDest = paramDest.next;
3175 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3177 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3181 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3183 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3189 // THIS WAS BACKWARDS:
3190 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3191 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3194 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3196 Compiler_Error($"overriding class expected to be derived from method class\n");
3200 paramSource = paramSource.next;
3206 // Source thisClass must be derived from destination thisClass
3207 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3209 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3215 // THIS WAS BACKWARDS TOO??
3216 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3217 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3220 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3222 //Compiler_Error($"overriding class expected to be derived from method class\n");
3230 // Source return type must be derived from destination return type
3231 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3233 Compiler_Warning($"incompatible return type for function\n");
3239 for(; paramDest; paramDest = paramDest.next)
3243 //Compiler_Warning($"not enough parameters\n");
3244 Compiler_Error($"not enough parameters\n");
3248 Type paramDestType = paramDest;
3249 Type paramSourceType = paramSource;
3250 Type type = paramDestType;
3252 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3253 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3254 paramSource.kind != templateType)
3257 ClassTemplateParameter curParam = null;
3259 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3262 if(sClass.templateClass) sClass = sClass.templateClass;
3263 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3265 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3267 for(sClass = sClass.base; sClass; sClass = sClass.base)
3269 if(sClass.templateClass) sClass = sClass.templateClass;
3270 id += sClass.templateParams.count;
3281 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3282 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3286 // paramDest must be derived from paramSource
3287 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3288 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3292 PrintType(paramDest, type, false, true);
3293 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3295 if(paramDestType != paramDest)
3296 FreeType(paramDestType);
3299 if(paramDestType != paramDest)
3300 FreeType(paramDestType);
3303 paramSource = paramSource.next;
3307 Compiler_Error($"too many parameters\n");
3312 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3316 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3317 (source.kind == arrayType || source.kind == pointerType))
3319 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3326 static void FreeConvert(Conversion convert)
3328 if(convert.resultType)
3329 FreeType(convert.resultType);
3332 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3333 char * string, OldList conversions)
3337 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3339 Class _class = link.data;
3340 if(_class.type == enumClass)
3342 OldList converts { };
3344 type.kind = classType;
3347 _class.symbol = FindClass(_class.fullName);
3348 type._class = _class.symbol;
3350 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3353 Class enumClass = eSystem_FindClass(privateModule, "enum");
3357 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3359 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3360 for(value = e.values.first; value; value = value.next)
3362 if(!strcmp(value.name, string))
3367 FreeExpContents(sourceExp);
3368 FreeType(sourceExp.expType);
3370 sourceExp.isConstant = true;
3371 sourceExp.expType = MkClassType(baseClass.fullName);
3375 sourceExp.type = constantExp;
3376 if(!strcmp(baseClass.dataTypeString, "int"))
3377 sprintf(constant, "%d",(int)value.data);
3379 sprintf(constant, "0x%X",(int)value.data);
3380 sourceExp.constant = CopyString(constant);
3381 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3384 while(converts.first)
3386 Conversion convert = converts.first;
3387 converts.Remove(convert);
3388 conversions.Add(convert);
3397 converts.Free(FreeConvert);
3401 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3402 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3407 public bool ModuleVisibility(Module searchIn, Module searchFor)
3409 SubModule subModule;
3411 if(searchFor == searchIn)
3414 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3416 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3418 if(ModuleVisibility(subModule.module, searchFor))
3425 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3429 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3431 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3433 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3436 for(module = mainModule.application.allModules.first; module; module = module.next)
3438 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3444 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3446 Type source = sourceExp.expType;
3447 Type realDest = dest;
3448 Type backupSourceExpType = null;
3450 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3453 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3455 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3457 Class sourceBase, destBase;
3458 for(sourceBase = source._class.registered;
3459 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3460 sourceBase = sourceBase.base);
3461 for(destBase = dest._class.registered;
3462 destBase && destBase.base && destBase.base.type != systemClass;
3463 destBase = destBase.base);
3464 //if(source._class.registered == dest._class.registered)
3465 if(sourceBase == destBase)
3474 int64 value = MAXINT;
3479 if(sourceExp.type == constantExp)
3482 value = strtoll(sourceExp.constant, null, 0);
3484 value = strtoull(sourceExp.constant, null, 0);
3486 else if(sourceExp.type == opExp && sourceExp.op.op == '-' && !sourceExp.op.exp1 && sourceExp.op.exp2 && sourceExp.op.exp2.type == constantExp)
3489 value = -strtoll(sourceExp.op.exp2.constant, null, 0);
3491 value = -strtoull(sourceExp.op.exp2.constant, null, 0);
3494 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3495 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3498 source = Type { kind = intType, isSigned = false, refCount = 1 };
3501 if(dest.kind == classType)
3503 Class _class = dest._class ? dest._class.registered : null;
3505 if(_class && _class.type == unitClass)
3507 if(source.kind != classType)
3510 Type tempDest, tempSource;
3512 for(; _class.base.type != systemClass; _class = _class.base);
3514 tempDest = tempType;
3516 tempType.kind = classType;
3518 _class.symbol = FindClass(_class.fullName);
3520 tempType._class = _class.symbol;
3521 tempType.truth = dest.truth;
3523 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3525 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3526 backupSourceExpType = sourceExp.expType;
3527 sourceExp.expType = dest; dest.refCount++;
3528 //sourceExp.expType = MkClassType(_class.fullName);
3536 // Why wasn't there something like this?
3537 if(_class && _class.type == bitClass && source.kind != classType)
3539 if(!dest._class.registered.dataType)
3540 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3541 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3544 FreeType(sourceExp.expType);
3545 source = sourceExp.expType = MkClassType(dest._class.string);
3548 //source.kind = classType;
3549 //source._class = dest._class;
3553 // Adding two enumerations
3555 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3557 if(!source._class.registered.dataType)
3558 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3559 if(!dest._class.registered.dataType)
3560 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3562 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3565 source = sourceExp.expType = MkClassType(dest._class.string);
3568 //source.kind = classType;
3569 //source._class = dest._class;
3573 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3575 OldList * specs = MkList();
3579 ReadString(string, sourceExp.string);
3580 decl = SpecDeclFromString(string, specs, null);
3582 FreeExpContents(sourceExp);
3583 FreeType(sourceExp.expType);
3585 sourceExp.type = classExp;
3586 sourceExp._classExp.specifiers = specs;
3587 sourceExp._classExp.decl = decl;
3588 sourceExp.expType = dest;
3593 if(backupSourceExpType) FreeType(backupSourceExpType);
3597 else if(source.kind == classType)
3599 Class _class = source._class ? source._class.registered : null;
3601 if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3604 if(dest.kind != classType)
3606 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3607 if(!source._class.registered.dataType)
3608 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3611 dest = MkClassType(source._class.string);
3612 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3613 // dest = MkClassType(source._class.string);
3617 if(dest.kind != classType)
3620 Type tempDest, tempSource;
3622 if(!source._class.registered.dataType)
3623 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3625 for(; _class.base.type != systemClass; _class = _class.base);
3627 tempSource = tempType;
3628 tempType.kind = classType;
3629 tempType._class = FindClass(_class.fullName);
3630 tempType.truth = source.truth;
3631 tempType.classObjectType = source.classObjectType;
3634 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3636 // PUT THIS BACK TESTING UNITS?
3637 if(conversions.last)
3639 ((Conversion)(conversions.last)).resultType = dest;
3643 FreeType(sourceExp.expType);
3644 sourceExp.expType = MkClassType(_class.fullName);
3645 sourceExp.expType.truth = source.truth;
3646 sourceExp.expType.classObjectType = source.classObjectType;
3648 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3650 if(!sourceExp.destType)
3652 FreeType(sourceExp.destType);
3653 sourceExp.destType = sourceExp.expType;
3654 if(sourceExp.expType)
3655 sourceExp.expType.refCount++;
3658 //source = _class.dataType;
3661 // TOCHECK: TESTING THIS NEW CODE
3662 if(!_class.dataType)
3663 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3665 dest = MkClassType(source._class.string);
3666 dest.truth = source.truth;
3667 dest.classObjectType = source.classObjectType;
3670 source = _class.dataType;
3680 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3690 if(source.kind == classType)
3692 Class _class = source._class.registered;
3693 if(_class.type == unitClass)
3695 if(!_class.dataType)
3696 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3697 source = _class.dataType;
3701 if(dest.kind == classType)
3703 Class _class = dest._class ? dest._class.registered : null;
3704 if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
3705 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3707 if(_class.type == normalClass || _class.type == noHeadClass)
3709 Expression newExp { };
3710 *newExp = *sourceExp;
3711 if(sourceExp.destType) sourceExp.destType.refCount++;
3712 if(sourceExp.expType) sourceExp.expType.refCount++;
3713 sourceExp.type = castExp;
3714 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3715 sourceExp.cast.exp = newExp;
3716 FreeType(sourceExp.expType);
3717 sourceExp.expType = null;
3718 ProcessExpressionType(sourceExp);
3720 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3723 FreeType(sourceExp.expType);
3724 sourceExp.expType = dest;
3728 if(inCompiler) FreeType(dest);
3730 if(backupSourceExpType) FreeType(backupSourceExpType);
3734 if(!_class.dataType)
3735 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3737 dest = _class.dataType;
3741 // Accept lower precision types for units, since we want to keep the unit type
3742 if(dest.kind == doubleType &&
3743 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3744 source.kind == charType))
3746 specs = MkListOne(MkSpecifier(DOUBLE));
3748 else if(dest.kind == floatType &&
3749 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3750 source.kind == doubleType))
3752 specs = MkListOne(MkSpecifier(FLOAT));
3754 else if(dest.kind == int64Type && (source.kind == int64Type || 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(INT64));
3761 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3762 source.kind == floatType || source.kind == doubleType))
3765 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3766 ListAdd(specs, MkSpecifier(INT));
3768 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == intType ||
3769 source.kind == floatType || source.kind == doubleType))
3772 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3773 ListAdd(specs, MkSpecifier(SHORT));
3775 else if(dest.kind == charType && (source.kind == charType || source.kind == shortType || source.kind == intType ||
3776 source.kind == floatType || source.kind == doubleType))
3779 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3780 ListAdd(specs, MkSpecifier(CHAR));
3786 if(backupSourceExpType)
3788 // Failed to convert: revert previous exp type
3789 if(sourceExp.expType) FreeType(sourceExp.expType);
3790 sourceExp.expType = backupSourceExpType;
3795 else if(dest.kind == doubleType &&
3796 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3797 source.kind == charType))
3799 specs = MkListOne(MkSpecifier(DOUBLE));
3801 else if(dest.kind == floatType &&
3802 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3804 specs = MkListOne(MkSpecifier(FLOAT));
3806 else if(dest.kind == charType && (source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3807 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3810 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3811 ListAdd(specs, MkSpecifier(CHAR));
3813 else if(dest.kind == shortType && (source.kind == enumType || source.kind == charType || source.kind == shortType ||
3814 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3817 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3818 ListAdd(specs, MkSpecifier(SHORT));
3820 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType))
3823 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3824 ListAdd(specs, MkSpecifier(INT));
3826 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3829 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3830 ListAdd(specs, MkSpecifier(INT64));
3832 else if(dest.kind == enumType &&
3833 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType))
3835 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3841 if(backupSourceExpType)
3843 // Failed to convert: revert previous exp type
3844 if(sourceExp.expType) FreeType(sourceExp.expType);
3845 sourceExp.expType = backupSourceExpType;
3852 Expression newExp { };
3853 *newExp = *sourceExp;
3856 if(sourceExp.destType) sourceExp.destType.refCount++;
3857 if(sourceExp.expType) sourceExp.expType.refCount++;
3859 sourceExp.type = castExp;
3860 if(realDest.kind == classType)
3862 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3863 FreeList(specs, FreeSpecifier);
3866 sourceExp.cast.typeName = MkTypeName(specs, null);
3867 if(newExp.type == opExp)
3869 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3872 sourceExp.cast.exp = newExp;
3874 FreeType(sourceExp.expType);
3875 sourceExp.expType = null;
3876 ProcessExpressionType(sourceExp);
3879 FreeList(specs, FreeSpecifier);
3883 if(backupSourceExpType) FreeType(backupSourceExpType);
3889 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
3890 if(sourceExp.type == identifierExp)
3892 Identifier id = sourceExp.identifier;
3893 if(dest.kind == classType)
3895 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3897 Class _class = dest._class.registered;
3898 Class enumClass = eSystem_FindClass(privateModule, "enum");
3901 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
3904 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
3905 for(value = e.values.first; value; value = value.next)
3907 if(!strcmp(value.name, id.string))
3912 FreeExpContents(sourceExp);
3913 FreeType(sourceExp.expType);
3915 sourceExp.isConstant = true;
3916 sourceExp.expType = MkClassType(_class.fullName);
3920 sourceExp.type = constantExp;
3921 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
3922 sprintf(constant, "%d", (int) value.data);
3924 sprintf(constant, "0x%X", (int) value.data);
3925 sourceExp.constant = CopyString(constant);
3926 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
3935 // Loop through all enum classes
3936 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
3943 #define TERTIARY(o, name, m, t, p) \
3944 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
3946 exp.type = constantExp; \
3947 exp.string = p(op1.m ? op2.m : op3.m); \
3949 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3953 #define BINARY(o, name, m, t, p) \
3954 static bool name(Expression exp, Operand op1, Operand op2) \
3957 exp.type = constantExp; \
3958 exp.string = p(op1.m o value2); \
3960 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3964 #define BINARY_DIVIDE(o, name, m, t, p) \
3965 static bool name(Expression exp, Operand op1, Operand op2) \
3968 exp.type = constantExp; \
3969 exp.string = p(value2 ? (op1.m o value2) : 0); \
3971 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3975 #define UNARY(o, name, m, t, p) \
3976 static bool name(Expression exp, Operand op1) \
3978 exp.type = constantExp; \
3979 exp.string = p(o op1.m); \
3981 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3985 #define OPERATOR_ALL(macro, o, name) \
3986 macro(o, Int##name, i, int, PrintInt) \
3987 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
3988 macro(o, Short##name, s, short, PrintShort) \
3989 macro(o, UShort##name, us, unsigned short, PrintUShort) \
3990 macro(o, Char##name, c, char, PrintChar) \
3991 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
3992 macro(o, Float##name, f, float, PrintFloat) \
3993 macro(o, Double##name, d, double, PrintDouble)
3995 #define OPERATOR_INTTYPES(macro, o, name) \
3996 macro(o, Int##name, i, int, PrintInt) \
3997 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
3998 macro(o, Short##name, s, short, PrintShort) \
3999 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4000 macro(o, Char##name, c, char, PrintChar) \
4001 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4004 // binary arithmetic
4005 OPERATOR_ALL(BINARY, +, Add)
4006 OPERATOR_ALL(BINARY, -, Sub)
4007 OPERATOR_ALL(BINARY, *, Mul)
4008 OPERATOR_ALL(BINARY_DIVIDE, /, Div)
4009 OPERATOR_INTTYPES(BINARY_DIVIDE, %, Mod)
4012 OPERATOR_ALL(UNARY, -, Neg)
4014 // unary arithmetic increment and decrement
4015 OPERATOR_ALL(UNARY, ++, Inc)
4016 OPERATOR_ALL(UNARY, --, Dec)
4018 // binary arithmetic assignment
4019 OPERATOR_ALL(BINARY, =, Asign)
4020 OPERATOR_ALL(BINARY, +=, AddAsign)
4021 OPERATOR_ALL(BINARY, -=, SubAsign)
4022 OPERATOR_ALL(BINARY, *=, MulAsign)
4023 OPERATOR_ALL(BINARY_DIVIDE, /=, DivAsign)
4024 OPERATOR_INTTYPES(BINARY_DIVIDE, %=, ModAsign)
4027 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4028 OPERATOR_INTTYPES(BINARY, |, BitOr)
4029 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4030 OPERATOR_INTTYPES(BINARY, <<, LShift)
4031 OPERATOR_INTTYPES(BINARY, >>, RShift)
4034 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4036 // binary bitwise assignment
4037 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4038 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4039 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4040 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4041 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4043 // unary logical negation
4044 OPERATOR_INTTYPES(UNARY, !, Not)
4046 // binary logical equality
4047 OPERATOR_ALL(BINARY, ==, Equ)
4048 OPERATOR_ALL(BINARY, !=, Nqu)
4051 OPERATOR_ALL(BINARY, &&, And)
4052 OPERATOR_ALL(BINARY, ||, Or)
4054 // binary logical relational
4055 OPERATOR_ALL(BINARY, >, Grt)
4056 OPERATOR_ALL(BINARY, <, Sma)
4057 OPERATOR_ALL(BINARY, >=, GrtEqu)
4058 OPERATOR_ALL(BINARY, <=, SmaEqu)
4060 // tertiary condition operator
4061 OPERATOR_ALL(TERTIARY, ?, Cond)
4063 //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
4064 #define OPERATOR_TABLE_ALL(name, type) \
4065 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4067 type##Inc, type##Dec, \
4068 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4069 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4071 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4073 type##Equ, type##Nqu, \
4074 type##And, type##Or, \
4075 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4078 #define OPERATOR_TABLE_INTTYPES(name, type) \
4079 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4081 type##Inc, type##Dec, \
4082 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4083 null, null, null, null, null, \
4085 null, null, null, null, null, \
4087 type##Equ, type##Nqu, \
4088 type##And, type##Or, \
4089 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4092 OPERATOR_TABLE_ALL(int, Int)
4093 OPERATOR_TABLE_ALL(uint, UInt)
4094 OPERATOR_TABLE_ALL(short, Short)
4095 OPERATOR_TABLE_ALL(ushort, UShort)
4096 OPERATOR_TABLE_INTTYPES(float, Float)
4097 OPERATOR_TABLE_INTTYPES(double, Double)
4098 OPERATOR_TABLE_ALL(char, Char)
4099 OPERATOR_TABLE_ALL(uchar, UChar)
4101 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4102 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4103 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4104 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4105 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4106 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4107 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4108 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4110 public void ReadString(char * output, char * string)
4112 int len = strlen(string);
4114 bool quoted = false, escaped = false;
4115 for(c = 0; c<len; c++)
4117 char ch = string[c];
4122 case 'n': output[d] = '\n'; break;
4123 case 't': output[d] = '\t'; break;
4124 case 'a': output[d] = '\a'; break;
4125 case 'b': output[d] = '\b'; break;
4126 case 'f': output[d] = '\f'; break;
4127 case 'r': output[d] = '\r'; break;
4128 case 'v': output[d] = '\v'; break;
4129 case '\\': output[d] = '\\'; break;
4130 case '\"': output[d] = '\"'; break;
4131 default: output[d++] = '\\'; output[d] = ch;
4132 //default: output[d] = ch;
4153 public Operand GetOperand(Expression exp)
4156 Type type = exp.expType;
4159 while(type.kind == classType &&
4160 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4162 if(!type._class.registered.dataType)
4163 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4164 type = type._class.registered.dataType;
4167 op.kind = type.kind;
4168 op.type = exp.expType;
4169 if(exp.isConstant && exp.type == constantExp)
4175 if(exp.constant[0] == '\'')
4176 op.c = exp.constant[1];
4177 else if(type.isSigned)
4179 op.c = (char)strtol(exp.constant, null, 0);
4184 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4192 op.s = (short)strtol(exp.constant, null, 0);
4197 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4205 op.i = (int)strtol(exp.constant, null, 0);
4210 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4218 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4223 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4231 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4236 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4244 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4249 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4255 op.f = (float)strtod(exp.constant, null);
4259 op.d = (double)strtod(exp.constant, null);
4262 //case classType: For when we have operator overloading...
4263 // Pointer additions
4264 //case functionType:
4268 op.ui64 = _strtoui64(exp.constant, null, 0);
4269 op.kind = pointerType;
4279 static void UnusedFunction()
4282 a.OnGetString(0,0,0);
4285 extern int __ecereVMethodID_class_OnGetString;
4288 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4290 DataMember dataMember;
4291 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4293 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4294 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4298 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4300 void * ptr = inst.data + dataMember.offset + offset;
4301 char * result = null;
4302 exp.loc = member.loc = inst.loc;
4303 ((Identifier)member.identifiers->first).loc = inst.loc;
4305 if(!dataMember.dataType)
4306 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4307 type = dataMember.dataType;
4308 if(type.kind == classType)
4310 Class _class = type._class.registered;
4311 if(_class.type == enumClass)
4313 Class enumClass = eSystem_FindClass(privateModule, "enum");
4316 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4318 for(item = e.values.first; item; item = item.next)
4320 if((int)item.data == *(int *)ptr)
4328 exp.identifier = MkIdentifier(result);
4329 exp.type = identifierExp;
4330 exp.destType = MkClassType(_class.fullName);
4331 ProcessExpressionType(exp);
4335 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4337 if(!_class.dataType)
4338 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4339 type = _class.dataType;
4348 FreeExpContents(exp);
4350 exp.constant = PrintFloat(*(float*)ptr);
4351 exp.type = constantExp;
4356 FreeExpContents(exp);
4358 exp.constant = PrintDouble(*(double*)ptr);
4359 exp.type = constantExp;
4364 FreeExpContents(exp);
4366 exp.constant = PrintInt(*(int*)ptr);
4367 exp.type = constantExp;
4372 FreeExpContents(exp);
4374 exp.constant = PrintInt64(*(int64*)ptr);
4375 exp.type = constantExp;
4380 FreeExpContents(exp);
4381 // TODO: This should probably use proper type
4382 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4383 exp.type = constantExp;
4388 FreeExpContents(exp);
4389 // TODO: This should probably use proper type
4390 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4391 exp.type = constantExp;
4395 Compiler_Error($"Unhandled type populating instance\n");
4398 ListAdd(memberList, member);
4401 if(parentDataMember.type == unionMember)
4406 void PopulateInstance(Instantiation inst)
4408 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4409 Class _class = classSym.registered;
4410 DataMember dataMember;
4411 OldList * memberList = MkList();
4412 inst.members = MkListOne(MkMembersInitList(memberList));
4413 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4415 if(!dataMember.isProperty)
4417 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4418 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4422 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4424 void * ptr = inst.data + dataMember.offset;
4425 char * result = null;
4427 exp.loc = member.loc = inst.loc;
4428 ((Identifier)member.identifiers->first).loc = inst.loc;
4430 if(!dataMember.dataType)
4431 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4432 type = dataMember.dataType;
4433 if(type.kind == classType)
4435 Class _class = type._class.registered;
4436 if(_class.type == enumClass)
4438 Class enumClass = eSystem_FindClass(privateModule, "enum");
4441 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4443 for(item = e.values.first; item; item = item.next)
4445 if((int)item.data == *(int *)ptr)
4454 exp.identifier = MkIdentifier(result);
4455 exp.type = identifierExp;
4456 exp.destType = MkClassType(_class.fullName);
4457 ProcessExpressionType(exp);
4460 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4462 if(!_class.dataType)
4463 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4464 type = _class.dataType;
4473 exp.constant = PrintFloat(*(float*)ptr);
4474 exp.type = constantExp;
4479 exp.constant = PrintDouble(*(double*)ptr);
4480 exp.type = constantExp;
4485 exp.constant = PrintInt(*(int*)ptr);
4486 exp.type = constantExp;
4491 exp.constant = PrintInt64(*(int64*)ptr);
4492 exp.type = constantExp;
4497 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4498 exp.type = constantExp;
4502 Compiler_Error($"Unhandled type populating instance\n");
4505 ListAdd(memberList, member);
4511 void ComputeInstantiation(Expression exp)
4513 Instantiation inst = exp.instance;
4514 MembersInit members;
4515 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4516 Class _class = classSym ? classSym.registered : null;
4517 DataMember curMember = null;
4518 Class curClass = null;
4519 DataMember subMemberStack[256];
4520 int subMemberStackPos = 0;
4523 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4525 // Don't recompute the instantiation...
4526 // Non Simple classes will have become constants by now
4530 if(_class.type == normalClass || _class.type == noHeadClass)
4531 inst.data = (byte *)eInstance_New(_class);
4533 inst.data = new0 byte[_class.structSize];
4538 for(members = inst.members->first; members; members = members.next)
4540 switch(members.type)
4542 case dataMembersInit:
4544 if(members.dataMembers)
4547 for(member = members.dataMembers->first; member; member = member.next)
4549 Identifier ident = member.identifiers ? member.identifiers->first : null;
4552 Property prop = null;
4553 DataMember dataMember = null;
4554 Method method = null;
4555 uint dataMemberOffset;
4559 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4562 if(curMember.isProperty)
4563 prop = (Property)curMember;
4566 dataMember = curMember;
4568 // CHANGED THIS HERE
4569 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4570 // dataMemberOffset = dataMember.offset;
4577 prop = eClass_FindProperty(_class, ident.string, privateModule);
4581 if(prop.memberAccess == publicAccess)
4583 curMember = (DataMember)prop;
4584 curClass = prop._class;
4589 DataMember _subMemberStack[256];
4590 int _subMemberStackPos = 0;
4592 // FILL MEMBER STACK
4593 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4598 if(dataMember.memberAccess == publicAccess)
4600 curMember = dataMember;
4601 curClass = dataMember._class;
4602 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
4603 subMemberStackPos = _subMemberStackPos;
4609 if(found && member.initializer && member.initializer.type == expInitializer)
4611 Expression value = member.initializer.exp;
4615 type = prop.dataType;
4619 if(!dataMember.dataType)
4620 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4622 type = dataMember.dataType;
4625 if(ident && ident.next)
4627 // for(; ident && type; ident = ident.next)
4628 for(ident = ident.next; ident && type; ident = ident.next)
4630 if(type.kind == classType)
4632 prop = eClass_FindProperty(type._class.registered,
4633 ident.string, privateModule);
4635 type = prop.dataType;
4638 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4639 ident.string, &dataMemberOffset, privateModule, null, null);
4641 type = dataMember.dataType;
4644 else if(type.kind == structType || type.kind == unionType)
4647 for(memberType = type.members.first; memberType; memberType = memberType.next)
4649 if(!strcmp(memberType.name, ident.string))
4660 FreeType(value.destType);
4661 value.destType = type;
4662 if(type) type.refCount++;
4663 ComputeExpression(value);
4665 if(value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4667 if(type.kind == classType)
4669 Class _class = type._class.registered;
4670 if(_class.type == bitClass || _class.type == unitClass ||
4671 _class.type == enumClass)
4673 if(!_class.dataType)
4674 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4675 type = _class.dataType;
4681 void * ptr = inst.data + dataMemberOffset;
4683 if(value.type == constantExp)
4689 GetInt(value, (int*)ptr);
4694 GetInt64(value, (int64*)ptr);
4699 GetIntPtr(value, (intptr*)ptr);
4704 GetIntSize(value, (intsize*)ptr);
4709 GetFloat(value, (float*)ptr);
4714 GetDouble(value, (double *)ptr);
4719 else if(value.type == instanceExp)
4721 if(type.kind == classType)
4723 Class _class = type._class.registered;
4724 if(_class.type == structClass)
4726 ComputeTypeSize(type);
4727 if(value.instance.data)
4728 memcpy(ptr, value.instance.data, type.size);
4735 if(value.type == instanceExp && value.instance.data)
4737 void (*Set)(void *, void *) = (void *)prop.Set;
4738 Set(inst.data, value.instance.data);
4739 PopulateInstance(inst);
4741 else if(value.type == constantExp)
4747 void (*Set)(void *, double) = (void *)prop.Set;
4748 Set(inst.data, strtod(value.constant, null) );
4753 void (*Set)(void *, float) = (void *)prop.Set;
4754 Set(inst.data, (float)(strtod(value.constant, null)));
4759 void (*Set)(void *, int) = (void *)prop.Set;
4760 Set(inst.data, strtol(value.constant, null, 0));
4765 void (*Set)(void *, int64) = (void *)prop.Set;
4766 Set(inst.data, _strtoi64(value.constant, null, 0));
4771 void (*Set)(void *, intptr) = (void *)prop.Set;
4772 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
4777 void (*Set)(void *, intsize) = (void *)prop.Set;
4778 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
4783 else if(value.type == stringExp)
4786 ReadString(temp, value.string);
4787 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
4791 else if(_class.type == unitClass)
4795 // Only support converting units to units for now...
4796 if(value.type == constantExp)
4798 if(type.kind == classType)
4800 Class _class = type._class.registered;
4801 if(_class.type == unitClass)
4803 if(!_class.dataType)
4804 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4805 type = _class.dataType;
4808 // TODO: Assuming same base type for units...
4814 float (*Set)(float) = (void *)prop.Set;
4815 GetFloat(member.initializer.exp, &fValue);
4816 exp.constant = PrintFloat(Set(fValue));
4817 exp.type = constantExp;
4823 double (*Set)(double) = (void *)prop.Set;
4824 GetDouble(member.initializer.exp, &dValue);
4825 exp.constant = PrintDouble(Set(dValue));
4826 exp.type = constantExp;
4833 else if(_class.type == bitClass)
4837 if(value.type == instanceExp && value.instance.data)
4839 unsigned int (*Set)(void *) = (void *)prop.Set;
4840 bits = Set(value.instance.data);
4842 else if(value.type == constantExp)
4848 BitMember bitMember = (BitMember) dataMember;
4851 GetInt(value, &part);
4852 bits = (bits & ~bitMember.mask);
4853 if(!bitMember.dataType)
4854 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
4856 type = bitMember.dataType;
4858 if(type.kind == classType && type._class && type._class.registered)
4860 if(!type._class.registered.dataType)
4861 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4862 type = type._class.registered.dataType;
4869 bits |= ((char)part << bitMember.pos);
4871 bits |= ((unsigned char)part << bitMember.pos);
4875 bits |= ((short)part << bitMember.pos);
4877 bits |= ((unsigned short)part << bitMember.pos);
4882 bits |= ((int)part << bitMember.pos);
4884 bits |= ((unsigned int)part << bitMember.pos);
4888 bits |= ((int64)part << bitMember.pos);
4890 bits |= ((uint64)part << bitMember.pos);
4895 bits |= ((intptr)part << bitMember.pos);
4899 bits |= ((uintptr)part << bitMember.pos);
4905 bits |= ((ssize_t)(intsize)part << bitMember.pos);
4909 bits |= ((size_t) (uintsize)part << bitMember.pos);
4918 if(_class && _class.type == unitClass)
4920 ComputeExpression(member.initializer.exp);
4921 exp.constant = member.initializer.exp.constant;
4922 exp.type = constantExp;
4924 member.initializer.exp.constant = null;
4934 if(_class && _class.type == bitClass)
4936 exp.constant = PrintHexUInt(bits);
4937 exp.type = constantExp;
4939 if(exp.type != instanceExp)
4945 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
4947 if(exp.op.op == SIZEOF)
4949 FreeExpContents(exp);
4950 exp.type = constantExp;
4951 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
4962 // Provide default unary +
4963 Expression exp2 = exp.op.exp2;
4965 FreeExpContents(exp);
4966 FreeType(exp.expType);
4967 FreeType(exp.destType);
4973 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
4975 // unary arithmetic increment and decrement
4976 //OPERATOR_ALL(UNARY, ++, Inc)
4977 //OPERATOR_ALL(UNARY, --, Dec)
4980 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
4982 // unary logical negation
4984 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
4992 // binary arithmetic
4994 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
4997 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5000 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5003 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5006 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5008 // binary arithmetic assignment
5009 //OPERATOR_ALL(BINARY, =, Asign)
5010 //OPERATOR_ALL(BINARY, +=, AddAsign)
5011 //OPERATOR_ALL(BINARY, -=, SubAsign)
5012 //OPERATOR_ALL(BINARY, *=, MulAsign)
5013 //OPERATOR_ALL(BINARY, /=, DivAsign)
5014 //OPERATOR_ALL(BINARY, %=, ModAsign)
5019 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5023 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5026 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5029 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5032 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5034 // binary bitwise assignment
5035 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5036 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5037 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5038 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5039 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5040 // binary logical equality
5042 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5045 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5049 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5052 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5054 // binary logical relational
5056 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5059 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5062 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5065 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5072 void ComputeExpression(Expression exp)
5074 char expString[10240];
5075 expString[0] = '\0';
5077 PrintExpression(exp, expString);
5084 ComputeInstantiation(exp);
5093 Expression exp1, exp2 = null;
5097 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5099 ComputeExpression(exp.op.exp2);
5102 ComputeExpression(exp.op.exp1);
5105 op1 = GetOperand(exp1);
5106 if(op1.type) op1.type.refCount++;
5109 op2 = GetOperand(exp2);
5110 if(op2.type) op2.type.refCount++;
5116 op1 = GetOperand(exp1);
5117 if(op1.type) op1.type.refCount++;
5120 CallOperator(exp, exp1, exp2, op1, op2);
5127 if(exp.op.exp1 && exp.op.exp2)
5132 FreeExpContents(exp);
5133 op1.ops.BitAnd(exp, op1, op2);
5142 FreeExpContents(exp);
5143 op1.ops.Mul(exp, op1, op2);
5152 FreeExpContents(exp);
5153 op1.ops.Add(exp, op1, op2);
5158 // Provide default unary +
5159 Expression exp2 = exp.op.exp2;
5161 FreeExpContents(exp);
5162 FreeType(exp.expType);
5163 FreeType(exp.destType);
5174 FreeExpContents(exp);
5175 op1.ops.Sub(exp, op1, op2);
5182 FreeExpContents(exp);
5183 op1.ops.Neg(exp, op1);
5190 FreeExpContents(exp);
5191 op1.ops.BitNot(exp, op1);
5197 FreeExpContents(exp);
5198 op1.ops.Not(exp, op1);
5201 // Binary only operators
5205 FreeExpContents(exp);
5206 op1.ops.Div(exp, op1, op2);
5212 FreeExpContents(exp);
5213 op1.ops.Mod(exp, op1, op2);
5225 FreeExpContents(exp);
5226 op1.ops.Sma(exp, op1, op2);
5235 FreeExpContents(exp);
5236 op1.ops.Grt(exp, op1, op2);
5245 FreeExpContents(exp);
5246 op1.ops.SmaEqu(exp, op1, op2);
5255 FreeExpContents(exp);
5256 op1.ops.GrtEqu(exp, op1, op2);
5265 FreeExpContents(exp);
5266 op1.ops.Equ(exp, op1, op2);
5275 FreeExpContents(exp);
5276 op1.ops.Nqu(exp, op1, op2);
5283 FreeExpContents(exp);
5284 op1.ops.BitOr(exp, op1, op2);
5290 FreeExpContents(exp);
5291 op1.ops.BitXor(exp, op1, op2);
5299 FreeExpContents(exp);
5300 exp.type = constantExp;
5301 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5305 if(op1.type) FreeType(op1.type);
5306 if(op2.type) FreeType(op2.type);
5310 case extensionExpressionExp:
5313 for(e = exp.list->first; e; e = n)
5318 OldList * list = exp.list;
5319 ComputeExpression(e);
5320 //FreeExpContents(exp);
5321 FreeType(exp.expType);
5322 FreeType(exp.destType);
5339 exp.isConstant = true;
5341 ComputeExpression(exp.index.exp);
5342 if(!exp.index.exp.isConstant)
5343 exp.isConstant = false;
5345 for(e = exp.index.index->first; e; e = e.next)
5347 ComputeExpression(e);
5350 // Check if this type is int
5353 exp.isConstant = false;
5355 exp.expType = Dereference(exp.index.exp.expType);
5361 Expression memberExp = exp.member.exp;
5362 Identifier memberID = exp.member.member;
5365 ComputeExpression(exp.member.exp);
5366 type = exp.member.exp.expType;
5369 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);
5370 Property prop = null;
5371 DataMember member = null;
5372 Class convertTo = null;
5373 if(type.kind == subClassType && exp.member.exp.type == classExp)
5374 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5381 PrintType(type, string, false, true);
5382 classSym = FindClass(string);
5383 _class = classSym ? classSym.registered : null;
5386 if(exp.member.member)
5388 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5390 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5392 if(!prop && !member && _class && exp.member.member)
5394 Symbol classSym = FindClass(exp.member.member.string);
5396 _class = classSym ? classSym.registered : null;
5397 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5404 Type type = prop.dataType;
5405 // TODO: Assuming same base type for units...
5406 if(_class.type == unitClass)
5408 if(type.kind == classType)
5410 Class _class = type._class.registered;
5411 if(_class.type == unitClass)
5413 if(!_class.dataType)
5414 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5415 type = _class.dataType;
5423 float (*Get)(float) = (void *)prop.Get;
5424 GetFloat(exp.member.exp, &value);
5425 exp.constant = PrintFloat(Get ? Get(value) : value);
5426 exp.type = constantExp;
5432 double (*Get)(double);
5433 GetDouble(exp.member.exp, &value);
5436 Get = (void *)prop.Set;
5438 Get = (void *)prop.Get;
5439 exp.constant = PrintDouble(Get ? Get(value) : value);
5440 exp.type = constantExp;
5449 Expression value = exp.member.exp;
5452 ProcessPropertyType(prop);
5454 type = prop.dataType;
5457 // printf("Investigate this\n");
5459 else if(_class.type == structClass)
5465 Class propertyClass = type._class.registered;
5466 if(propertyClass.type == structClass && value.type == instanceExp)
5468 void (*Set)(void *, void *) = (void *)prop.Set;
5469 exp.instance = Instantiation { };
5470 exp.instance.data = new0 byte[_class.structSize];
5471 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5472 exp.instance.loc = exp.loc;
5473 exp.type = instanceExp;
5474 Set(exp.instance.data, value.instance.data);
5475 PopulateInstance(exp.instance);
5482 void (*Set)(void *, int) = (void *)prop.Set;
5484 exp.instance = Instantiation { };
5485 exp.instance.data = new0 byte[_class.structSize];
5486 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5487 exp.instance.loc = exp.loc;
5488 exp.type = instanceExp;
5490 GetInt(value, &intValue);
5492 Set(exp.instance.data, intValue);
5493 PopulateInstance(exp.instance);
5499 void (*Set)(void *, int64) = (void *)prop.Set;
5501 exp.instance = Instantiation { };
5502 exp.instance.data = new0 byte[_class.structSize];
5503 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5504 exp.instance.loc = exp.loc;
5505 exp.type = instanceExp;
5507 GetInt64(value, &intValue);
5509 Set(exp.instance.data, intValue);
5510 PopulateInstance(exp.instance);
5517 void (*Set)(void *, intptr) = (void *)prop.Set;
5519 exp.instance = Instantiation { };
5520 exp.instance.data = new0 byte[_class.structSize];
5521 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5522 exp.instance.loc = exp.loc;
5523 exp.type = instanceExp;
5525 GetIntPtr(value, &intValue);
5527 Set(exp.instance.data, intValue);
5528 PopulateInstance(exp.instance);
5535 void (*Set)(void *, intsize) = (void *)prop.Set;
5537 exp.instance = Instantiation { };
5538 exp.instance.data = new0 byte[_class.structSize];
5539 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5540 exp.instance.loc = exp.loc;
5541 exp.type = instanceExp;
5543 GetIntSize(value, &intValue);
5545 Set(exp.instance.data, intValue);
5546 PopulateInstance(exp.instance);
5552 void (*Set)(void *, double) = (void *)prop.Set;
5554 exp.instance = Instantiation { };
5555 exp.instance.data = new0 byte[_class.structSize];
5556 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5557 exp.instance.loc = exp.loc;
5558 exp.type = instanceExp;
5560 GetDouble(value, &doubleValue);
5562 Set(exp.instance.data, doubleValue);
5563 PopulateInstance(exp.instance);
5568 else if(_class.type == bitClass)
5574 Class propertyClass = type._class.registered;
5575 if(propertyClass.type == structClass && value.instance.data)
5577 unsigned int (*Set)(void *) = (void *)prop.Set;
5578 unsigned int bits = Set(value.instance.data);
5579 exp.constant = PrintHexUInt(bits);
5580 exp.type = constantExp;
5583 else if(_class.type == bitClass)
5586 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5589 GetUInt(exp.member.exp, &value);
5591 exp.constant = PrintHexUInt(bits);
5592 exp.type = constantExp;
5600 if(_class.type == bitClass)
5603 GetUInt(exp.member.exp, &value);
5609 Class _class = type._class.registered;
5610 if(_class.type == structClass)
5612 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5614 exp.instance = Instantiation { };
5615 exp.instance.data = new0 byte[_class.structSize];
5616 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5617 exp.instance.loc = exp.loc;
5618 //exp.instance.fullSet = true;
5619 exp.type = instanceExp;
5620 Get(value, exp.instance.data);
5621 PopulateInstance(exp.instance);
5623 else if(_class.type == bitClass)
5625 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5626 uint64 bits = Get(value);
5627 exp.constant = PrintHexUInt64(bits);
5628 exp.type = constantExp;
5634 else if(_class.type == structClass)
5636 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5641 Class _class = type._class.registered;
5642 if(_class.type == structClass && value)
5644 void (*Get)(void *, void *) = (void *)prop.Get;
5646 exp.instance = Instantiation { };
5647 exp.instance.data = new0 byte[_class.structSize];
5648 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5649 exp.instance.loc = exp.loc;
5650 //exp.instance.fullSet = true;
5651 exp.type = instanceExp;
5652 Get(value, exp.instance.data);
5653 PopulateInstance(exp.instance);
5661 char * value = exp.member.exp.instance.data;
5666 Class _class = type._class.registered;
5667 if(_class.type == normalClass)
5669 void *(*Get)(void *) = (void *)prop.Get;
5671 exp.instance = Instantiation { };
5672 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5673 exp.type = instanceExp;
5674 exp.instance.data = Get(value, exp.instance.data);
5686 exp.isConstant = false;
5694 if(exp.type != ExpressionType::memberExp)
5696 FreeExpression(memberExp);
5697 FreeIdentifier(memberID);
5703 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5704 FreeExpContents(exp);
5705 exp.constant = PrintUInt(ComputeTypeSize(type));
5706 exp.type = constantExp;
5712 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5713 if(classSym && classSym.registered)
5715 if(classSym.registered.fixed)
5717 FreeSpecifier(exp._class);
5718 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5719 exp.type = constantExp;
5723 char className[1024];
5724 strcpy(className, "__ecereClass_");
5725 FullClassNameCat(className, classSym.string, true);
5726 MangleClassName(className);
5728 FreeExpContents(exp);
5729 exp.type = pointerExp;
5730 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5731 exp.member.member = MkIdentifier("structSize");
5741 if(exp.type == castExp)
5744 ComputeExpression(exp.cast.exp);
5747 if(e && exp.expType)
5750 type = exp.destType;
5753 if(type.kind == classType)
5755 Class _class = type._class.registered;
5756 if(_class && (_class.type == unitClass || _class.type == bitClass))
5758 if(!_class.dataType)
5759 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5760 type = _class.dataType;
5771 FreeExpContents(exp);
5772 exp.constant = PrintChar(value);
5773 exp.type = constantExp;
5777 unsigned char value;
5778 GetUChar(e, &value);
5779 FreeExpContents(exp);
5780 exp.constant = PrintUChar(value);
5781 exp.type = constantExp;
5788 GetShort(e, &value);
5789 FreeExpContents(exp);
5790 exp.constant = PrintShort(value);
5791 exp.type = constantExp;
5795 unsigned short value;
5796 GetUShort(e, &value);
5797 FreeExpContents(exp);
5798 exp.constant = PrintUShort(value);
5799 exp.type = constantExp;
5807 FreeExpContents(exp);
5808 exp.constant = PrintInt(value);
5809 exp.type = constantExp;
5815 FreeExpContents(exp);
5816 exp.constant = PrintUInt(value);
5817 exp.type = constantExp;
5824 GetInt64(e, &value);
5825 FreeExpContents(exp);
5826 exp.constant = PrintInt64(value);
5827 exp.type = constantExp;
5832 GetUInt64(e, &value);
5833 FreeExpContents(exp);
5834 exp.constant = PrintUInt64(value);
5835 exp.type = constantExp;
5842 GetIntPtr(e, &value);
5843 FreeExpContents(exp);
5844 exp.constant = PrintInt64((int64)value);
5845 exp.type = constantExp;
5850 GetUIntPtr(e, &value);
5851 FreeExpContents(exp);
5852 exp.constant = PrintUInt64((uint64)value);
5853 exp.type = constantExp;
5860 GetIntSize(e, &value);
5861 FreeExpContents(exp);
5862 exp.constant = PrintInt64((int64)value);
5863 exp.type = constantExp;
5868 GetUIntSize(e, &value);
5869 FreeExpContents(exp);
5870 exp.constant = PrintUInt64((uint64)value);
5871 exp.type = constantExp;
5877 GetFloat(e, &value);
5878 FreeExpContents(exp);
5879 exp.constant = PrintFloat(value);
5880 exp.type = constantExp;
5886 GetDouble(e, &value);
5887 FreeExpContents(exp);
5888 exp.constant = PrintDouble(value);
5889 exp.type = constantExp;
5903 // Caring only about last expression for now...
5904 ComputeExpression(exp.cond.exp->last);
5905 if(exp.cond.elseExp)
5906 ComputeExpression(exp.cond.elseExp);
5908 ComputeExpression(exp.cond.cond);
5910 op1 = GetOperand(exp.cond.cond);
5911 if(op1.type) op1.type.refCount++;
5912 op2 = GetOperand(exp.cond.exp->last);
5913 if(op2.type) op2.type.refCount++;
5914 op3 = GetOperand(exp.cond.elseExp);
5915 if(op3.type) op3.type.refCount++;
5917 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
5918 if(op1.type) FreeType(op1.type);
5919 if(op2.type) FreeType(op2.type);
5920 if(op3.type) FreeType(op3.type);
5926 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
5931 OldList converts { };
5934 if(destType.kind == voidType)
5937 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
5941 // for(convert = converts.last; convert; convert = convert.prev)
5942 for(convert = converts.first; convert; convert = convert.next)
5944 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
5947 Expression newExp { };
5948 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
5950 // TODO: Check this...
5952 newExp.destType = null;
5957 exp.type = memberExp;
5958 exp.addedThis = true;
5959 exp.member.exp = newExp;
5960 FreeType(exp.member.exp.expType);
5962 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
5963 exp.member.exp.expType.classObjectType = objectType;
5964 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
5965 exp.member.memberType = propertyMember;
5966 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
5967 // TESTING THIS... for (int)degrees
5968 exp.needCast = true;
5969 if(exp.expType) exp.expType.refCount++;
5970 ApplyAnyObjectLogic(exp.member.exp);
5975 /*if(exp.isConstant)
5977 // Color { ColorRGB = [exp] };
5978 exp.type = instanceExp;
5979 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
5980 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
5981 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
5985 // If not constant, don't turn it yet into an instantiation
5986 // (Go through the deep members system first)
5987 exp.type = memberExp;
5988 exp.addedThis = true;
5989 exp.member.exp = newExp;
5991 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
5992 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
5993 newExp.expType._class.registered.type == noHeadClass)
5995 newExp.byReference = true;
5998 FreeType(exp.member.exp.expType);
5999 /*exp.member.exp.expType = convert.convert.dataType;
6000 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6001 exp.member.exp.expType = null;
6002 if(convert.convert.dataType)
6004 exp.member.exp.expType = { };
6005 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6006 exp.member.exp.expType.refCount = 1;
6007 exp.member.exp.expType.classObjectType = objectType;
6008 ApplyAnyObjectLogic(exp.member.exp);
6011 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6012 exp.member.memberType = reverseConversionMember;
6013 exp.expType = convert.resultType ? convert.resultType :
6014 MkClassType(convert.convert._class.fullName);
6015 exp.needCast = true;
6016 if(convert.resultType) convert.resultType.refCount++;
6022 FreeType(exp.expType);
6025 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6026 exp.needCast = true;
6027 if(exp.expType) exp.expType.refCount++;
6031 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6032 exp.needCast = true;
6033 if(convert.resultType)
6034 convert.resultType.refCount++;
6038 if(exp.isConstant && inCompiler)
6039 ComputeExpression(exp);
6041 converts.Free(FreeConvert);
6044 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6046 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6048 if(!result && exp.expType && exp.destType)
6050 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6051 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6052 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6053 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6057 // if(result) CheckTemplateTypes(exp);
6061 void CheckTemplateTypes(Expression exp)
6063 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6065 Expression newExp { };
6069 if(exp.destType) exp.destType.refCount++;
6070 if(exp.expType) exp.expType.refCount++;
6074 switch(exp.expType.kind)
6077 if(exp.destType.classObjectType)
6079 // We need to pass the address, just pass it along (Undo what was done above)
6080 if(exp.destType) exp.destType.refCount--;
6081 if(exp.expType) exp.expType.refCount--;
6086 // If we're looking for value:
6087 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6089 OldList * unionDefs = MkList();
6090 OldList * statements = MkList();
6091 context = PushContext();
6092 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6093 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6094 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6095 exp.type = extensionCompoundExp;
6096 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6097 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6098 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6099 exp.compound.compound.context = context;
6100 PopContext(context);
6105 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6106 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6110 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6112 Expression newExp { };
6116 if(exp.destType) exp.destType.refCount++;
6117 if(exp.expType) exp.expType.refCount++;
6121 switch(exp.expType.kind)
6124 if(exp.destType.classObjectType)
6126 // We need to pass the address, just pass it along (Undo what was done above)
6127 if(exp.destType) exp.destType.refCount--;
6128 if(exp.expType) exp.expType.refCount--;
6133 // If we're looking for value:
6134 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6136 OldList * unionDefs = MkList();
6137 OldList * statements = MkList();
6138 context = PushContext();
6139 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6140 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6141 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6142 exp.type = extensionCompoundExp;
6143 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6144 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6145 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6146 exp.compound.compound.context = context;
6147 PopContext(context);
6152 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6154 exp.type = bracketsExp;
6155 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6156 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6157 ProcessExpressionType(exp.list->first);
6162 exp.type = bracketsExp;
6163 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6164 newExp.needCast = true;
6165 ProcessExpressionType(exp.list->first);
6171 if(exp.expType.kind == templateType)
6173 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6176 FreeType(exp.destType);
6177 FreeType(exp.expType);
6182 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6187 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6188 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6192 char typeString[1024];
6194 OldList * specs = MkList();
6195 typeString[0] = '\0';
6196 PrintType(exp.expType, typeString, false, false);
6197 decl = SpecDeclFromString(typeString, specs, null);
6200 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6201 exp.cast.typeName = MkTypeName(specs, decl);
6202 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6203 exp.cast.exp.needCast = true;
6210 // TODO: The Symbol tree should be reorganized by namespaces
6212 // - Tree of all symbols within (stored without namespace)
6213 // - Tree of sub-namespaces
6215 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6217 int nsLen = strlen(nameSpace);
6219 // Start at the name space prefix
6220 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6222 char * s = symbol.string;
6223 if(!strncmp(s, nameSpace, nsLen))
6225 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6228 for(c = strlen(s)-1; c >= 0; c--)
6233 if(!strcmp(namePart, name))
6235 // TODO: Error on ambiguity
6245 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6248 char nameSpace[1024];
6250 bool gotColon = false;
6252 nameSpace[0] = '\0';
6253 for(c = strlen(name)-1; c >= 0; c--)
6260 namePart = name+c+1;
6261 while(c >= 0 && name[c] == ':') c--;
6264 // Try an exact match first
6265 Symbol symbol = (Symbol)tree.FindString(name);
6269 // Namespace specified
6270 memcpy(nameSpace, name, c + 1);
6273 return ScanWithNameSpace(tree, nameSpace, namePart);
6277 // Looking for a global symbol, e.g. ::Sleep()
6278 Symbol symbol = (Symbol)tree.FindString(namePart);
6283 // Name only (no namespace specified)
6284 Symbol symbol = (Symbol)tree.FindString(namePart);
6287 return ScanWithNameSpace(tree, "", namePart);
6292 static void ProcessDeclaration(Declaration decl);
6294 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6297 //Time startTime = GetTime();
6299 // Optimize this later? Do this before/less?
6301 Symbol symbol = null;
6302 // First, check if the identifier is declared inside the function
6303 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6305 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6307 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6313 strcpy(curName, thisNameSpace);
6314 strcat(curName, "::");
6315 strcat(curName, name);
6316 // Try to resolve in current namespace first
6317 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6320 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6323 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6325 if(symbol || ctx == endContext) break;
6327 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6329 if(symbol.pointerExternal.type == functionExternal)
6331 FunctionDefinition function = symbol.pointerExternal.function;
6333 // Modified this recently...
6334 Context tmpContext = curContext;
6336 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6337 curContext = tmpContext;
6339 symbol.pointerExternal.symbol = symbol;
6342 DeclareType(symbol.type, true, true);
6344 ast->Insert(curExternal.prev, symbol.pointerExternal);
6346 symbol.id = curExternal.symbol.idCode;
6349 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6351 ast->Move(symbol.pointerExternal, curExternal.prev);
6352 symbol.id = curExternal.symbol.idCode;
6356 //findSymbolTotalTime += GetTime() - startTime;
6361 static void GetTypeSpecs(Type type, OldList * specs)
6363 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6368 if(type._class.registered)
6370 if(!type._class.registered.dataType)
6371 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6372 GetTypeSpecs(type._class.registered.dataType, specs);
6376 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6377 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6378 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6379 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6380 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6381 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6382 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6385 ListAdd(specs, MkSpecifier(INT)); break;
6389 static void PrintArraySize(Type arrayType, char * string)
6394 if(arrayType.enumClass)
6395 strcat(size, arrayType.enumClass.string);
6396 else if(arrayType.arraySizeExp)
6397 PrintExpression(arrayType.arraySizeExp, size);
6399 strcat(string, size);
6402 // WARNING : This function expects a null terminated string since it recursively concatenate...
6403 static void PrintTypeSpecs(Type type, char * string, bool fullName)
6408 strcat(string, "const ");
6413 Symbol c = type._class;
6416 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6417 // look into merging with thisclass ?
6418 if(type.classObjectType == typedObject)
6419 strcat(string, "typed_object");
6421 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6425 case voidType: strcat(string, "void"); break;
6426 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6427 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6428 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6429 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6430 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6431 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6432 case floatType: strcat(string, "float"); break;
6433 case doubleType: strcat(string, "double"); break;
6437 strcat(string, "struct ");
6438 strcat(string, type.enumName);
6440 else if(type.typeName)
6441 strcat(string, type.typeName);
6445 strcat(string, "struct { ");
6446 for(member = type.members.first; member; member = member.next)
6448 PrintType(member, string, true, fullName);
6449 strcat(string,"; ");
6457 strcat(string, "union ");
6458 strcat(string, type.enumName);
6460 else if(type.typeName)
6461 strcat(string, type.typeName);
6464 strcat(string, "union ");
6465 strcat(string,"(unnamed)");
6471 strcat(string, "enum ");
6472 strcat(string, type.enumName);
6474 else if(type.typeName)
6475 strcat(string, type.typeName);
6477 strcat(string, "enum");
6480 strcat(string, "...");
6483 strcat(string, "subclass(");
6484 strcat(string, type._class ? type._class.string : "int");
6485 strcat(string, ")");
6488 strcat(string, type.templateParameter.identifier.string);
6491 strcat(string, "thisclass");
6494 strcat(string, "__builtin_va_list");
6500 static void PrintName(Type type, char * string, bool fullName)
6502 if(type.name && type.name[0])
6504 strcat(string, " ");
6506 strcat(string, type.name);
6509 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6510 if(name) name += 2; else name = type.name;
6511 strcat(string, name);
6516 static void PrePrintType(Type type, char * string, bool printName, bool fullName)
6518 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6520 if((type.kind == functionType || type.kind == methodType) && type.dllExport)
6521 strcat(string, "dllexport ");
6522 if(type.constant && (type.kind == functionType || type.kind == methodType))
6523 strcat(string, " const");
6524 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, printName, fullName);
6525 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6526 strcat(string, " (");
6527 if(type.kind == pointerType)
6528 strcat(string, (type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType) ? "*" : " *");
6529 if(type.constant && type.kind == pointerType)
6530 strcat(string, " const");
6533 PrintTypeSpecs(type, string, fullName);
6534 if(printName && type.name)
6535 PrintName(type, string, fullName);
6538 static void PostPrintType(Type type, char * string, bool fullName)
6540 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6541 strcat(string, ")");
6542 if(type.kind == arrayType)
6543 PrintArraySize(type, string);
6544 else if(type.kind == functionType)
6547 strcat(string, "(");
6548 for(param = type.params.first; param; param = param.next)
6550 PrintType(param, string, true, fullName);
6551 if(param.next) strcat(string, ", ");
6553 strcat(string, ")");
6555 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6556 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
6560 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6562 void PrintType(Type type, char * string, bool printName, bool fullName)
6564 PrePrintType(type, string, printName, fullName);
6565 PostPrintType(type, string, fullName);
6566 if(type.bitFieldCount)
6569 sprintf(count, ":%d", type.bitFieldCount);
6570 strcat(string, count);
6574 static Type FindMember(Type type, char * string)
6577 for(memberType = type.members.first; memberType; memberType = memberType.next)
6579 if(!memberType.name)
6581 Type subType = FindMember(memberType, string);
6585 else if(!strcmp(memberType.name, string))
6591 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6594 for(memberType = type.members.first; memberType; memberType = memberType.next)
6596 if(!memberType.name)
6598 Type subType = FindMember(memberType, string);
6601 *offset += memberType.offset;
6605 else if(!strcmp(memberType.name, string))
6607 *offset += memberType.offset;
6614 Expression ParseExpressionString(char * expression)
6616 fileInput = TempFile { };
6617 fileInput.Write(expression, 1, strlen(expression));
6618 fileInput.Seek(0, start);
6621 parsedExpression = null;
6623 expression_yyparse();
6626 return parsedExpression;
6629 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6631 Identifier id = exp.identifier;
6632 Method method = null;
6633 Property prop = null;
6634 DataMember member = null;
6635 ClassProperty classProp = null;
6637 if(_class && _class.type == enumClass)
6639 NamedLink value = null;
6640 Class enumClass = eSystem_FindClass(privateModule, "enum");
6644 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6646 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6647 for(value = e.values.first; value; value = value.next)
6649 if(!strcmp(value.name, id.string))
6656 FreeExpContents(exp);
6658 exp.type = constantExp;
6659 exp.isConstant = true;
6660 if(!strcmp(baseClass.dataTypeString, "int"))
6661 sprintf(constant, "%d",(int)value.data);
6663 sprintf(constant, "0x%X",(int)value.data);
6664 exp.constant = CopyString(constant);
6665 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6666 exp.expType = MkClassType(baseClass.fullName);
6674 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6676 ProcessMethodType(method);
6683 // TOCHECK: Put it back to what it was...
6684 // methodClass = _class;
6685 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6690 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
6693 ProcessPropertyType(prop);
6694 exp.expType = prop.dataType;
6695 if(prop.dataType) prop.dataType.refCount++;
6698 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
6700 if(!member.dataType)
6701 member.dataType = ProcessTypeString(member.dataTypeString, false);
6702 exp.expType = member.dataType;
6703 if(member.dataType) member.dataType.refCount++;
6706 else if((classProp = eClass_FindClassProperty(_class, id.string)))
6708 if(!classProp.dataType)
6709 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
6711 if(classProp.constant)
6713 FreeExpContents(exp);
6715 exp.isConstant = true;
6716 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
6718 //char constant[256];
6719 exp.type = stringExp;
6720 exp.constant = QMkString((char *)classProp.Get(_class));
6725 exp.type = constantExp;
6726 sprintf(constant, "%d", (int)classProp.Get(_class));
6727 exp.constant = CopyString(constant);
6735 exp.expType = classProp.dataType;
6736 if(classProp.dataType) classProp.dataType.refCount++;
6742 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
6744 BinaryTree * tree = &nameSpace.functions;
6745 GlobalData data = (GlobalData)tree->FindString(name);
6749 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
6751 data = ScanGlobalData(child, name);
6759 static GlobalData FindGlobalData(char * name)
6762 NameSpace * nameSpace;
6763 nameSpace = globalData;
6764 for(c = 0; name[c]; c++)
6766 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
6768 NameSpace * newSpace;
6769 char * spaceName = new char[c - start + 1];
6770 strncpy(spaceName, name + start, c - start);
6771 spaceName[c-start] = '\0';
6772 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
6776 nameSpace = newSpace;
6777 if(name[c] == ':') c++;
6783 return ScanGlobalData(nameSpace, name + start);
6788 static int definedExpStackPos;
6789 static void * definedExpStack[512];
6791 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
6792 void ReplaceExpContents(Expression checkedExp, Expression newExp)
6794 Expression prev = checkedExp.prev, next = checkedExp.next;
6796 FreeExpContents(checkedExp);
6797 FreeType(checkedExp.expType);
6798 FreeType(checkedExp.destType);
6800 *checkedExp = *newExp;
6804 checkedExp.prev = prev;
6805 checkedExp.next = next;
6808 void ApplyAnyObjectLogic(Expression e)
6810 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
6811 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
6813 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
6814 //ellipsisDestType = destType;
6817 Type type = e.expType;
6818 Class _class = null;
6819 //Type destType = e.destType;
6821 if(type.kind == classType && type._class && type._class.registered)
6823 _class = type._class.registered;
6825 else if(type.kind == subClassType)
6827 _class = FindClass("ecere::com::Class").registered;
6831 char string[1024] = "";
6834 PrintType(type, string, false, true);
6835 classSym = FindClass(string);
6836 if(classSym) _class = classSym.registered;
6839 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...
6840 (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
6841 destType.byReference)))
6843 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
6845 Expression checkedExp = e, newExp;
6847 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6849 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6851 if(checkedExp.type == extensionCompoundExp)
6853 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6856 checkedExp = checkedExp.list->last;
6858 else if(checkedExp.type == castExp)
6859 checkedExp = checkedExp.cast.exp;
6862 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
6864 newExp = checkedExp.op.exp2;
6865 checkedExp.op.exp2 = null;
6866 FreeExpContents(checkedExp);
6868 if(e.expType && e.expType.passAsTemplate)
6871 ComputeTypeSize(e.expType);
6872 sprintf(size, "%d", e.expType.size);
6873 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
6874 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
6875 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
6878 ReplaceExpContents(checkedExp, newExp);
6879 e.byReference = true;
6881 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
6883 Expression checkedExp, newExp;
6886 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
6888 e.type == identifierExp ||
6889 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
6890 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
6891 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
6894 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
6896 Context context = PushContext();
6898 OldList * specs = MkList();
6899 char typeString[1024];
6900 Expression newExp { };
6902 typeString[0] = '\0';
6905 //if(e.destType) e.destType.refCount++;
6906 // if(exp.expType) exp.expType.refCount++;
6909 newExp.expType = null;
6911 PrintType(e.expType, typeString, false, true);
6912 decl = SpecDeclFromString(typeString, specs, null);
6913 newExp.destType = ProcessType(specs, decl);
6915 curContext = context;
6916 e.type = extensionCompoundExp;
6918 // We need a current compound for this
6922 OldList * stmts = MkList();
6923 sprintf(name, "__internalValue%03X", internalValueCounter++);
6924 if(!curCompound.compound.declarations)
6925 curCompound.compound.declarations = MkList();
6926 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
6927 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
6928 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
6929 e.compound = MkCompoundStmt(null, stmts);
6932 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
6935 e.compound = MkCompoundStmt(
6936 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
6937 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
6939 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
6943 Type type = e.destType;
6945 CopyTypeInto(e.destType, type);
6946 e.destType.refCount = 1;
6947 e.destType.classObjectType = none;
6951 e.compound.compound.context = context;
6952 PopContext(context);
6953 curContext = context.parent;
6957 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
6959 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6961 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6963 if(checkedExp.type == extensionCompoundExp)
6965 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6968 checkedExp = checkedExp.list->last;
6970 else if(checkedExp.type == castExp)
6971 checkedExp = checkedExp.cast.exp;
6974 Expression operand { };
6975 operand = *checkedExp;
6976 checkedExp.destType = null;
6977 checkedExp.expType = null;
6979 checkedExp.type = opExp;
6980 checkedExp.op.op = '&';
6981 checkedExp.op.exp1 = null;
6982 checkedExp.op.exp2 = operand;
6984 //newExp = MkExpOp(null, '&', checkedExp);
6986 //ReplaceExpContents(checkedExp, newExp);
6993 // If expression type is a simple class, make it an address
6994 // FixReference(e, true);
6997 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
6998 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
6999 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7001 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
7003 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7007 Expression thisExp { };
7010 thisExp.prev = null;
7011 thisExp.next = null;
7014 e.type = bracketsExp;
7015 e.list = MkListOne(MkExpOp(null, '*', MkExpBrackets(MkListOne(thisExp))));
7016 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7017 ((Expression)e.list->first).byReference = true;
7019 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7021 e.expType = thisExp.expType;
7022 e.expType.refCount++;
7027 CopyTypeInto(e.expType, thisExp.expType);
7028 e.expType.byReference = false;
7029 e.expType.refCount = 1;
7031 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7032 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7034 e.expType.classObjectType = none;
7039 // TOFIX: Try this for a nice IDE crash!
7041 // The other way around
7044 if(destType && e.expType &&
7045 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7046 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7047 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7049 if(destType.kind == ellipsisType)
7051 Compiler_Error($"Unspecified type\n");
7053 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7055 bool byReference = e.expType.byReference;
7056 Expression thisExp { };
7058 OldList * specs = MkList();
7059 char typeString[1024]; // Watch buffer overruns
7061 ClassObjectType backupClassObjectType;
7063 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7068 backupClassObjectType = type.classObjectType;
7070 type.classObjectType = none;
7072 typeString[0] = '\0';
7073 PrintType(type, typeString, false, true);
7074 decl = SpecDeclFromString(typeString, specs, null);
7076 type.classObjectType = backupClassObjectType;
7079 thisExp.prev = null;
7080 thisExp.next = null;
7083 if( ( type.kind == classType && type._class && type._class.registered && strcmp(type._class.registered.fullName, "ecere::com::Instance") &&
7084 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7085 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7086 (type.kind != pointerType && type.kind != arrayType && type.kind != classType) ||
7087 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7092 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7097 e.cast.typeName = MkTypeName(specs, decl);
7098 e.cast.exp = thisExp;
7099 e.byReference = true;
7102 e.destType = destType;
7104 destType.refCount++;
7109 void ProcessExpressionType(Expression exp)
7111 bool unresolved = false;
7112 Location oldyylloc = yylloc;
7113 bool notByReference = false;
7115 char debugExpString[4096];
7116 debugExpString[0] = '\0';
7117 PrintExpression(exp, debugExpString);
7119 if(!exp || exp.expType)
7122 //eSystem_Logf("%s\n", expString);
7124 // Testing this here
7130 Identifier id = exp.identifier;
7133 // DOING THIS LATER NOW...
7134 if(id._class && id._class.name)
7136 id.classSym = id._class.symbol; // FindClass(id._class.name);
7137 /* TODO: Name Space Fix ups
7139 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7143 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7145 exp.expType = ProcessTypeString("Module", true);
7148 else */if(strstr(id.string, "__ecereClass") == id.string)
7150 exp.expType = ProcessTypeString("ecere::com::Class", true);
7153 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7155 // Added this here as well
7156 ReplaceClassMembers(exp, thisClass);
7157 if(exp.type != identifierExp)
7159 ProcessExpressionType(exp);
7163 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7168 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7169 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7170 if(!symbol/* && exp.destType*/)
7172 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7178 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7179 if(exp.type != identifierExp)
7181 ProcessExpressionType(exp);
7185 // Static methods called from inside the _class
7186 else if(currentClass && !id._class)
7188 if(ResolveIdWithClass(exp, currentClass, true))
7191 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7195 // If we manage to resolve this symbol
7198 Type type = symbol.type;
7199 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7201 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7203 Context context = SetupTemplatesContext(_class);
7204 type = ReplaceThisClassType(_class);
7205 FinishTemplatesContext(context);
7206 if(type) type.refCount = 0; // We'll be incrementing it right below...
7209 FreeSpecifier(id._class);
7212 id.string = CopyString(symbol.string);
7218 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7219 // Add missing cases here... enum Classes...
7220 exp.isConstant = true;
7222 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7223 if(symbol.isParam || !strcmp(id.string, "this"))
7225 if(_class && _class.type == structClass)
7226 exp.byReference = true;
7228 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7229 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7230 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7231 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7233 Identifier id = exp.identifier;
7234 exp.type = bracketsExp;
7235 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7239 if(symbol.isIterator)
7241 if(symbol.isIterator == 3)
7243 exp.type = bracketsExp;
7244 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7245 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7247 ProcessExpressionType(exp);
7249 else if(symbol.isIterator != 4)
7251 exp.type = memberExp;
7252 exp.member.exp = MkExpIdentifier(exp.identifier);
7253 exp.member.exp.expType = exp.expType;
7254 /*if(symbol.isIterator == 6)
7255 exp.member.member = MkIdentifier("key");
7257 exp.member.member = MkIdentifier("data");
7259 ProcessExpressionType(exp);
7266 DefinedExpression definedExp = null;
7267 if(thisNameSpace && !(id._class && !id._class.name))
7270 strcpy(name, thisNameSpace);
7272 strcat(name, id.string);
7273 definedExp = eSystem_FindDefine(privateModule, name);
7276 definedExp = eSystem_FindDefine(privateModule, id.string);
7280 for(c = 0; c<definedExpStackPos; c++)
7281 if(definedExpStack[c] == definedExp)
7283 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7285 Location backupYylloc = yylloc;
7286 definedExpStack[definedExpStackPos++] = definedExp;
7287 fileInput = TempFile { };
7288 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7289 fileInput.Seek(0, start);
7292 parsedExpression = null;
7294 expression_yyparse();
7297 yylloc = backupYylloc;
7299 if(parsedExpression)
7302 exp.type = bracketsExp;
7303 exp.list = MkListOne(parsedExpression);
7304 parsedExpression.loc = yylloc;
7305 ProcessExpressionType(exp);
7306 definedExpStackPos--;
7309 definedExpStackPos--;
7315 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7321 GlobalData data = null;
7322 if(thisNameSpace && !(id._class && !id._class.name))
7325 strcpy(name, thisNameSpace);
7327 strcat(name, id.string);
7328 data = FindGlobalData(name);
7331 data = FindGlobalData(id.string);
7334 DeclareGlobalData(data);
7335 exp.expType = data.dataType;
7336 if(data.dataType) data.dataType.refCount++;
7339 id.string = CopyString(data.fullName);
7340 FreeSpecifier(id._class);
7347 GlobalFunction function = null;
7348 if(thisNameSpace && !(id._class && !id._class.name))
7351 strcpy(name, thisNameSpace);
7353 strcat(name, id.string);
7354 function = eSystem_FindFunction(privateModule, name);
7357 function = eSystem_FindFunction(privateModule, id.string);
7362 id.string = CopyString(function.name);
7365 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7366 strcpy(name, "__ecereFunction_");
7367 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7368 if(DeclareFunction(function, name))
7371 id.string = CopyString(name);
7373 exp.expType = function.dataType;
7374 if(function.dataType) function.dataType.refCount++;
7376 FreeSpecifier(id._class);
7393 if(!exp.instance._class)
7395 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7397 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7401 //classSym = FindClass(exp.instance._class.fullName);
7402 //_class = classSym ? classSym.registered : null;
7404 ProcessInstantiationType(exp.instance);
7405 exp.isConstant = exp.instance.isConstant;
7408 if(_class.type == unitClass && _class.base.type != systemClass)
7411 Type destType = exp.destType;
7413 exp.destType = MkClassType(_class.base.fullName);
7414 exp.expType = MkClassType(_class.fullName);
7415 CheckExpressionType(exp, exp.destType, true);
7417 exp.destType = destType;
7419 exp.expType = MkClassType(_class.fullName);
7422 if(exp.instance._class)
7424 exp.expType = MkClassType(exp.instance._class.name);
7425 /*if(exp.expType._class && exp.expType._class.registered &&
7426 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7427 exp.expType.byReference = true;*/
7442 if(exp.constant[0] == '\'')
7444 if((int)((byte *)exp.constant)[1] > 127)
7447 unichar ch = UTF8GetChar(exp.constant + 1, &nb);
7448 if(nb < 2) ch = exp.constant[1];
7449 delete exp.constant;
7450 exp.constant = PrintUInt(ch);
7451 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7452 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7453 type._class = FindClass("unichar");
7455 type.isSigned = false;
7459 type.kind = charType;
7460 type.isSigned = true;
7463 else if(strchr(exp.constant, '.'))
7465 char ch = exp.constant[strlen(exp.constant)-1];
7467 type.kind = floatType;
7469 type.kind = doubleType;
7470 type.isSigned = true;
7474 if(exp.constant[0] == '0' && exp.constant[1])
7475 type.isSigned = false;
7476 else if(strchr(exp.constant, 'L') || strchr(exp.constant, 'l'))
7477 type.isSigned = false;
7478 else if(strtoll(exp.constant, null, 0) > MAXINT)
7479 type.isSigned = false;
7481 type.isSigned = true;
7482 type.kind = intType;
7484 exp.isConstant = true;
7490 exp.isConstant = true; // Why wasn't this constant?
7506 ProcessExpressionType(exp._new.size);
7511 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7513 DeclareType(exp.expType.type, false, false);
7517 ProcessExpressionType(exp._renew.size);
7518 ProcessExpressionType(exp._renew.exp);
7523 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7525 DeclareType(exp.expType.type, false, false);
7529 bool assign = false, boolResult = false, boolOps = false;
7530 Type type1 = null, type2 = null;
7531 bool useDestType = false, useSideType = false;
7532 Location oldyylloc = yylloc;
7533 bool useSideUnit = false;
7535 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7544 // Assignment Operators
7558 // boolean Operators
7560 // Expect boolean operators
7562 //boolResult = true;
7566 // Expect boolean operands
7577 // Gives boolean result
7585 // Just added these... testing
7590 // DANGER: Verify units
7595 if(exp.op.op != '*' || exp.op.exp1)
7602 /*// Implement speed etc.
7608 if(exp.op.op == '&')
7610 // Added this here earlier for Iterator address as key
7611 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7613 Identifier id = exp.op.exp2.identifier;
7614 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7615 if(symbol && symbol.isIterator == 2)
7617 exp.type = memberExp;
7618 exp.member.exp = exp.op.exp2;
7619 exp.member.member = MkIdentifier("key");
7621 exp.op.exp2.expType = symbol.type;
7622 symbol.type.refCount++;
7623 ProcessExpressionType(exp);
7627 // exp.op.exp2.usage.usageRef = true;
7631 //dummy.kind = TypeDummy;
7635 if(exp.destType && exp.destType.kind == classType &&
7636 exp.destType._class && exp.destType._class.registered && useDestType &&
7638 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
7639 exp.destType._class.registered.type == enumClass ||
7640 exp.destType._class.registered.type == bitClass
7643 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
7645 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7646 exp.op.exp1.destType = exp.destType;
7648 exp.destType.refCount++;
7652 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7653 exp.op.exp1.destType = dummy;
7657 // TESTING THIS HERE...
7658 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
7659 ProcessExpressionType(exp.op.exp1);
7660 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
7662 if(exp.op.exp1.destType == dummy)
7665 exp.op.exp1.destType = null;
7667 type1 = exp.op.exp1.expType;
7672 char expString[10240];
7673 expString[0] = '\0';
7674 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
7678 exp.op.exp2.destType = exp.op.exp1.expType;
7679 if(exp.op.exp1.expType)
7680 exp.op.exp1.expType.refCount++;
7684 exp.op.exp2.destType = exp.destType;
7686 exp.destType.refCount++;
7689 if(type1) type1.refCount++;
7690 exp.expType = type1;
7695 PrintExpression(exp.op.exp2, expString);
7697 if(type1 && type1.kind == pointerType)
7699 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 ||
7700 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
7701 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
7702 else if(exp.op.op == '=')
7704 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7705 exp.op.exp2.destType = type1;
7712 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
7713 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/* ||
7714 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
7717 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7718 exp.op.exp2.destType = type1;
7723 if(type1) type1.refCount++;
7724 exp.expType = type1;
7726 else if(exp.destType && exp.destType.kind == classType &&
7727 exp.destType._class && exp.destType._class.registered &&
7729 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
7730 (exp.destType._class.registered.type == enumClass && useDestType))
7733 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7734 exp.op.exp2.destType = exp.destType;
7736 exp.destType.refCount++;
7740 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7741 exp.op.exp2.destType = dummy;
7745 // TESTING THIS HERE... (DANGEROUS)
7746 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
7747 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
7749 FreeType(exp.op.exp2.destType);
7750 exp.op.exp2.destType = type1;
7753 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
7754 ProcessExpressionType(exp.op.exp2);
7755 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
7757 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
7759 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)
7761 if(exp.op.op != '=' && type1.type.kind == voidType)
7762 Compiler_Error($"void *: unknown size\n");
7764 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||
7765 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
7766 (exp.op.exp2.expType._class.registered.type == normalClass ||
7767 exp.op.exp2.expType._class.registered.type == structClass ||
7768 exp.op.exp2.expType._class.registered.type == noHeadClass)))
7770 if(exp.op.op == ADD_ASSIGN)
7771 Compiler_Error($"cannot add two pointers\n");
7773 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
7774 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
7776 if(exp.op.op == ADD_ASSIGN)
7777 Compiler_Error($"cannot add two pointers\n");
7781 char type1String[1024];
7782 char type2String[1024];
7783 type1String[0] = '\0';
7784 type2String[0] = '\0';
7786 PrintType(exp.op.exp2.expType, type1String, false, true);
7787 PrintType(type1, type2String, false, true);
7788 ChangeCh(expString, '\n', ' ');
7789 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
7793 if(exp.op.exp2.destType == dummy)
7796 exp.op.exp2.destType = null;
7799 type2 = exp.op.exp2.expType;
7802 dummy.kind = voidType;
7804 if(exp.op.op == SIZEOF)
7811 exp.isConstant = true;
7813 // Get type of dereferenced pointer
7814 else if(exp.op.op == '*' && !exp.op.exp1)
7816 exp.expType = Dereference(type2);
7817 if(type2 && type2.kind == classType)
7818 notByReference = true;
7820 else if(exp.op.op == '&' && !exp.op.exp1)
7821 exp.expType = Reference(type2);
7828 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7829 exp.op.exp1.destType = MkClassType("bool");
7830 exp.op.exp1.destType.truth = true;
7831 if(!exp.op.exp1.expType)
7832 ProcessExpressionType(exp.op.exp1);
7834 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
7835 FreeType(exp.op.exp1.expType);
7836 exp.op.exp1.expType = MkClassType("bool");
7837 exp.op.exp1.expType.truth = true;
7841 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7842 exp.op.exp2.destType = MkClassType("bool");
7843 exp.op.exp2.destType.truth = true;
7844 if(!exp.op.exp2.expType)
7845 ProcessExpressionType(exp.op.exp2);
7847 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
7848 FreeType(exp.op.exp2.expType);
7849 exp.op.exp2.expType = MkClassType("bool");
7850 exp.op.exp2.expType.truth = true;
7853 else if(exp.op.exp1 && exp.op.exp2 &&
7856 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
7857 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
7858 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
7859 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
7861 if(type1 && type2 &&
7862 // If either both are class or both are not class
7863 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
7865 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7866 exp.op.exp2.destType = type1;
7868 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7869 exp.op.exp1.destType = type2;
7871 // Warning here for adding Radians + Degrees with no destination type
7872 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
7873 type1._class.registered && type1._class.registered.type == unitClass &&
7874 type2._class.registered && type2._class.registered.type == unitClass &&
7875 type1._class.registered != type2._class.registered)
7876 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
7877 type1._class.string, type2._class.string, type1._class.string);
7879 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
7881 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7884 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7886 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
7887 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
7890 ProcessExpressionType(exp.op.exp1);
7892 if(type2.kind != pointerType)
7894 ProcessExpressionType(classExp);
7896 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
7897 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
7898 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
7900 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
7903 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
7904 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
7905 MkPointer(null, null), null)))),
7906 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
7908 if(!exp.op.exp2.expType)
7909 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
7911 ProcessExpressionType(exp.op.exp2);
7916 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)))
7918 if(type1.kind != classType && type1.type.kind == voidType)
7919 Compiler_Error($"void *: unknown size\n");
7920 exp.expType = type1;
7921 if(type1) type1.refCount++;
7923 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)))
7925 if(type2.kind != classType && type2.type.kind == voidType)
7926 Compiler_Error($"void *: unknown size\n");
7927 exp.expType = type2;
7928 if(type2) type2.refCount++;
7930 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
7931 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
7933 Compiler_Warning($"different levels of indirection\n");
7937 bool success = false;
7938 if(type1.kind == pointerType && type2.kind == pointerType)
7940 if(exp.op.op == '+')
7941 Compiler_Error($"cannot add two pointers\n");
7942 else if(exp.op.op == '-')
7944 // Pointer Subtraction gives integer
7945 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
7954 if(type1.type.kind == templateType)
7956 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
7959 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
7961 ProcessExpressionType(classExp);
7963 exp.type = bracketsExp;
7964 exp.list = MkListOne(MkExpOp(
7965 MkExpBrackets(MkListOne(MkExpOp(
7966 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
7968 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
7970 //MkExpMember(classExp, MkIdentifier("typeSize"))
7972 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
7973 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
7975 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
7978 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
7979 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
7980 MkPointer(null, null), null)))),
7981 MkExpMember(classExp, MkIdentifier("typeSize")))))
7986 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
7995 if(!success && exp.op.exp1.type == constantExp)
7997 // If first expression is constant, try to match that first
7998 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8000 if(exp.expType) FreeType(exp.expType);
8001 exp.expType = exp.op.exp1.destType;
8002 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8005 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8007 if(exp.expType) FreeType(exp.expType);
8008 exp.expType = exp.op.exp2.destType;
8009 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8015 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8017 if(exp.expType) FreeType(exp.expType);
8018 exp.expType = exp.op.exp2.destType;
8019 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8022 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8024 if(exp.expType) FreeType(exp.expType);
8025 exp.expType = exp.op.exp1.destType;
8026 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8032 char expString1[10240];
8033 char expString2[10240];
8036 expString1[0] = '\0';
8037 expString2[0] = '\0';
8042 PrintExpression(exp.op.exp1, expString1);
8043 ChangeCh(expString1, '\n', ' ');
8044 PrintExpression(exp.op.exp2, expString2);
8045 ChangeCh(expString2, '\n', ' ');
8046 PrintType(exp.op.exp1.expType, type1, false, true);
8047 PrintType(exp.op.exp2.expType, type2, false, true);
8050 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8054 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8055 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8057 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8058 // Convert e.g. / 4 into / 4.0
8059 exp.op.exp1.destType = type2._class.registered.dataType;
8060 if(type2._class.registered.dataType)
8061 type2._class.registered.dataType.refCount++;
8062 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8063 exp.expType = type2;
8064 if(type2) type2.refCount++;
8066 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8068 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8069 // Convert e.g. / 4 into / 4.0
8070 exp.op.exp2.destType = type1._class.registered.dataType;
8071 if(type1._class.registered.dataType)
8072 type1._class.registered.dataType.refCount++;
8073 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8074 exp.expType = type1;
8075 if(type1) type1.refCount++;
8081 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8083 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8085 if(!type1._class.registered.dataType)
8086 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8087 exp.op.exp2.destType = type1._class.registered.dataType;
8088 exp.op.exp2.destType.refCount++;
8090 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8091 type2 = exp.op.exp2.destType;
8093 exp.expType = type2;
8097 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8099 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8101 if(!type2._class.registered.dataType)
8102 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8103 exp.op.exp1.destType = type2._class.registered.dataType;
8104 exp.op.exp1.destType.refCount++;
8106 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8107 type1 = exp.op.exp1.destType;
8108 exp.expType = type1;
8112 // TESTING THIS NEW CODE
8113 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8115 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8117 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8119 if(exp.expType) FreeType(exp.expType);
8120 exp.expType = exp.op.exp1.expType;
8121 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8126 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8128 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8130 if(exp.expType) FreeType(exp.expType);
8131 exp.expType = exp.op.exp2.expType;
8132 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8140 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8141 exp.op.exp2.destType = type1;
8145 // Maybe this was meant to be an enum...
8146 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8148 Type oldType = exp.op.exp2.expType;
8149 exp.op.exp2.expType = null;
8150 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8153 exp.op.exp2.expType = oldType;
8158 // TESTING THIS HERE... LATEST ADDITION
8159 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8161 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8162 exp.op.exp2.destType = type2._class.registered.dataType;
8163 if(type2._class.registered.dataType)
8164 type2._class.registered.dataType.refCount++;
8165 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8167 //exp.expType = type2._class.registered.dataType; //type2;
8168 //if(type2) type2.refCount++;
8171 // TESTING THIS HERE... LATEST ADDITION
8172 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8174 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8175 exp.op.exp1.destType = type1._class.registered.dataType;
8176 if(type1._class.registered.dataType)
8177 type1._class.registered.dataType.refCount++;
8178 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8179 exp.expType = type1._class.registered.dataType; //type1;
8180 if(type1) type1.refCount++;
8184 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8186 if(exp.expType) FreeType(exp.expType);
8187 exp.expType = exp.op.exp2.destType;
8188 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8190 else if(type1 && type2)
8192 char expString1[10240];
8193 char expString2[10240];
8194 char type1String[1024];
8195 char type2String[1024];
8196 expString1[0] = '\0';
8197 expString2[0] = '\0';
8198 type1String[0] = '\0';
8199 type2String[0] = '\0';
8202 PrintExpression(exp.op.exp1, expString1);
8203 ChangeCh(expString1, '\n', ' ');
8204 PrintExpression(exp.op.exp2, expString2);
8205 ChangeCh(expString2, '\n', ' ');
8206 PrintType(exp.op.exp1.expType, type1String, false, true);
8207 PrintType(exp.op.exp2.expType, type2String, false, true);
8210 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8212 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8214 exp.expType = exp.op.exp1.expType;
8215 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8217 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8219 exp.expType = exp.op.exp2.expType;
8220 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8227 // Maybe this was meant to be an enum...
8228 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8230 Type oldType = exp.op.exp1.expType;
8231 exp.op.exp1.expType = null;
8232 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8235 exp.op.exp1.expType = oldType;
8238 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8239 exp.op.exp1.destType = type2;
8242 // TESTING THIS HERE... LATEST ADDITION
8243 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8245 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8246 exp.op.exp1.destType = type1._class.registered.dataType;
8247 if(type1._class.registered.dataType)
8248 type1._class.registered.dataType.refCount++;
8251 // TESTING THIS HERE... LATEST ADDITION
8252 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8254 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8255 exp.op.exp2.destType = type2._class.registered.dataType;
8256 if(type2._class.registered.dataType)
8257 type2._class.registered.dataType.refCount++;
8261 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8263 if(exp.expType) FreeType(exp.expType);
8264 exp.expType = exp.op.exp1.destType;
8265 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8269 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8271 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8273 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8274 // Convert e.g. / 4 into / 4.0
8275 exp.op.exp1.destType = type2._class.registered.dataType;
8276 if(type2._class.registered.dataType)
8277 type2._class.registered.dataType.refCount++;
8278 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8280 if(exp.op.op == '!')
8282 exp.expType = MkClassType("bool");
8283 exp.expType.truth = true;
8287 exp.expType = type2;
8288 if(type2) type2.refCount++;
8291 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8293 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8295 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8296 // Convert e.g. / 4 into / 4.0
8297 exp.op.exp2.destType = type1._class.registered.dataType;
8298 if(type1._class.registered.dataType)
8299 type1._class.registered.dataType.refCount++;
8300 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8302 exp.expType = type1;
8303 if(type1) type1.refCount++;
8308 if(exp.op.exp1 && !exp.op.exp1.expType)
8310 char expString[10000];
8311 expString[0] = '\0';
8314 PrintExpression(exp.op.exp1, expString);
8315 ChangeCh(expString, '\n', ' ');
8318 Compiler_Error($"couldn't determine type of %s\n", expString);
8320 if(exp.op.exp2 && !exp.op.exp2.expType)
8322 char expString[10240];
8323 expString[0] = '\0';
8326 PrintExpression(exp.op.exp2, expString);
8327 ChangeCh(expString, '\n', ' ');
8330 Compiler_Error($"couldn't determine type of %s\n", expString);
8335 FreeType(exp.expType);
8336 exp.expType = MkClassType("bool");
8337 exp.expType.truth = true;
8340 if(exp.op.op != SIZEOF)
8341 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8342 (!exp.op.exp2 || exp.op.exp2.isConstant);
8344 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8346 DeclareType(exp.op.exp2.expType, false, false);
8355 case extensionExpressionExp:
8358 exp.isConstant = true;
8359 for(e = exp.list->first; e; e = e.next)
8364 FreeType(e.destType);
8365 e.destType = exp.destType;
8366 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8368 ProcessExpressionType(e);
8370 exp.destType.count--;
8371 if(!exp.expType && !e.next)
8373 exp.expType = e.expType;
8374 if(e.expType) e.expType.refCount++;
8377 exp.isConstant = false;
8380 // In case a cast became a member...
8381 e = exp.list->first;
8382 if(!e.next && e.type == memberExp)
8384 // Preserve prev, next
8385 Expression next = exp.next, prev = exp.prev;
8388 FreeType(exp.expType);
8389 FreeType(exp.destType);
8399 ProcessExpressionType(exp);
8406 exp.isConstant = true;
8408 ProcessExpressionType(exp.index.exp);
8409 if(!exp.index.exp.isConstant)
8410 exp.isConstant = false;
8412 if(exp.index.exp.expType)
8414 Type source = exp.index.exp.expType;
8415 if(source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
8416 eClass_IsDerived(source._class.registered, containerClass) &&
8417 source._class.registered.templateArgs)
8419 Class _class = source._class.registered;
8420 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8422 if(exp.index.index && exp.index.index->last)
8424 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8429 for(e = exp.index.index->first; e; e = e.next)
8431 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8433 if(e.destType) FreeType(e.destType);
8434 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8436 ProcessExpressionType(e);
8439 // Check if this type is int
8442 exp.isConstant = false;
8446 exp.expType = Dereference(exp.index.exp.expType);
8448 DeclareType(exp.expType, false, false);
8455 Type methodType = null;
8461 PrintExpression(exp.call.exp, name);
8462 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8464 //exp.call.exp.expType = null;
8465 PrintExpression(exp.call.exp, name);
8468 if(exp.call.exp.type == identifierExp)
8470 Expression idExp = exp.call.exp;
8471 Identifier id = idExp.identifier;
8472 if(!strcmp(id.string, "__builtin_frame_address"))
8474 exp.expType = ProcessTypeString("void *", true);
8475 if(exp.call.arguments && exp.call.arguments->first)
8476 ProcessExpressionType(exp.call.arguments->first);
8479 else if(!strcmp(id.string, "__ENDIAN_PAD"))
8481 exp.expType = ProcessTypeString("int", true);
8482 if(exp.call.arguments && exp.call.arguments->first)
8483 ProcessExpressionType(exp.call.arguments->first);
8486 else if(!strcmp(id.string, "Max") ||
8487 !strcmp(id.string, "Min") ||
8488 !strcmp(id.string, "Sgn") ||
8489 !strcmp(id.string, "Abs"))
8491 Expression a = null;
8492 Expression b = null;
8493 Expression tempExp1 = null, tempExp2 = null;
8494 if((!strcmp(id.string, "Max") ||
8495 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8497 a = exp.call.arguments->first;
8498 b = exp.call.arguments->last;
8502 else if(exp.call.arguments->count == 1)
8504 a = exp.call.arguments->first;
8510 exp.call.arguments->Clear();
8511 idExp.identifier = null;
8513 FreeExpContents(exp);
8515 ProcessExpressionType(a);
8517 ProcessExpressionType(b);
8519 exp.type = bracketsExp;
8520 exp.list = MkList();
8522 if(a.expType && (!b || b.expType))
8524 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8526 // Use the simpleStruct name/ids for now...
8529 OldList * specs = MkList();
8530 OldList * decls = MkList();
8532 char temp1[1024], temp2[1024];
8534 GetTypeSpecs(a.expType, specs);
8536 if(a && !a.isConstant && a.type != identifierExp)
8538 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8539 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8540 tempExp1 = QMkExpId(temp1);
8541 tempExp1.expType = a.expType;
8543 a.expType.refCount++;
8544 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8546 if(b && !b.isConstant && b.type != identifierExp)
8548 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8549 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8550 tempExp2 = QMkExpId(temp2);
8551 tempExp2.expType = b.expType;
8553 b.expType.refCount++;
8554 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8557 decl = MkDeclaration(specs, decls);
8558 if(!curCompound.compound.declarations)
8559 curCompound.compound.declarations = MkList();
8560 curCompound.compound.declarations->Insert(null, decl);
8565 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8567 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8569 MkExpCondition(MkExpBrackets(MkListOne(
8570 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8571 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8572 exp.expType = a.expType;
8574 a.expType.refCount++;
8576 else if(!strcmp(id.string, "Abs"))
8579 MkExpCondition(MkExpBrackets(MkListOne(
8580 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8581 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8582 exp.expType = a.expType;
8584 a.expType.refCount++;
8586 else if(!strcmp(id.string, "Sgn"))
8588 // ((!(a))?(0):(((a)<0)?(-1):(1)))
8590 MkExpCondition(MkExpBrackets(MkListOne(
8591 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
8592 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
8593 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8594 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
8595 exp.expType = ProcessTypeString("int", false);
8598 FreeExpression(tempExp1);
8599 if(tempExp2) FreeExpression(tempExp2);
8613 if(!exp.call.exp.destType)
8615 exp.call.exp.destType = dummy;
8618 ProcessExpressionType(exp.call.exp);
8619 if(exp.call.exp.destType == dummy)
8622 exp.call.exp.destType = null;
8627 // Check argument types against parameter types
8628 functionType = exp.call.exp.expType;
8630 if(functionType && functionType.kind == TypeKind::methodType)
8632 methodType = functionType;
8633 functionType = methodType.method.dataType;
8635 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
8636 // TOCHECK: Instead of doing this here could this be done per param?
8637 if(exp.call.exp.expType.usedClass)
8639 char typeString[1024];
8640 typeString[0] = '\0';
8641 PrintType(functionType, typeString, true, true);
8642 if(strstr(typeString, "thisclass"))
8644 OldList * specs = MkList();
8647 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
8649 decl = SpecDeclFromString(typeString, specs, null);
8651 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
8652 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
8653 exp.call.exp.expType.usedClass))
8654 thisClassParams = false;
8656 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
8658 Class backupThisClass = thisClass;
8659 thisClass = exp.call.exp.expType.usedClass;
8660 ProcessDeclarator(decl);
8661 thisClass = backupThisClass;
8664 thisClassParams = true;
8666 functionType = ProcessType(specs, decl);
8667 functionType.refCount = 0;
8668 FinishTemplatesContext(context);
8671 FreeList(specs, FreeSpecifier);
8672 FreeDeclarator(decl);
8676 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
8678 Type type = functionType.type;
8679 if(!functionType.refCount)
8681 functionType.type = null;
8682 FreeType(functionType);
8684 //methodType = functionType;
8685 functionType = type;
8687 if(functionType && functionType.kind != TypeKind::functionType)
8689 Compiler_Error($"called object %s is not a function\n", name);
8691 else if(functionType)
8693 bool emptyParams = false, noParams = false;
8694 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
8695 Type type = functionType.params.first;
8696 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
8698 Location oldyylloc = yylloc;
8700 if(!type) emptyParams = true;
8703 if(functionType.extraParam && e && functionType.thisClass)
8705 e.destType = MkClassType(functionType.thisClass.string);
8709 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
8710 if(!functionType.staticMethod)
8712 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
8713 memberExp.member.exp.expType._class)
8715 type = MkClassType(memberExp.member.exp.expType._class.string);
8720 type = functionType.params.first;
8725 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
8727 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
8732 type = functionType.params.first;
8740 if(type && type.kind == voidType)
8743 if(!type.refCount) FreeType(type);
8747 for( ; e; e = e.next)
8749 if(!type && !emptyParams)
8752 if(methodType && methodType.methodClass)
8753 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
8754 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
8755 noParams ? 0 : functionType.params.count);
8757 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
8758 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
8759 noParams ? 0 : functionType.params.count);
8763 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
8765 Type templatedType = null;
8766 Class _class = methodType.usedClass;
8767 ClassTemplateParameter curParam = null;
8769 if(_class && _class.templateArgs /*&& _class.templateClass*/)
8772 for(sClass = _class; sClass; sClass = sClass.base)
8774 if(sClass.templateClass) sClass = sClass.templateClass;
8776 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
8778 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
8781 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
8783 if(nextClass.templateClass) nextClass = nextClass.templateClass;
8784 id += nextClass.templateParams.count;
8793 if(curParam && _class.templateArgs[id].dataTypeString)
8795 ClassTemplateArgument arg = _class.templateArgs[id];
8797 Context context = SetupTemplatesContext(_class);
8800 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
8801 templatedType = ProcessTypeString(arg.dataTypeString, false);
8802 FinishTemplatesContext(context);
8804 e.destType = templatedType;
8807 templatedType.passAsTemplate = true;
8808 // templatedType.refCount++;
8814 if(type) type.refCount++;
8819 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
8821 e.destType = type.prev;
8822 e.destType.refCount++;
8827 if(type) type.refCount++;
8830 // Don't reach the end for the ellipsis
8831 if(type && type.kind != ellipsisType)
8833 Type next = type.next;
8834 if(!type.refCount) FreeType(type);
8839 if(type && type.kind != ellipsisType)
8841 if(methodType && methodType.methodClass)
8842 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
8843 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
8844 functionType.params.count + extra);
8846 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
8847 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
8848 functionType.params.count + extra);
8851 if(type && !type.refCount) FreeType(type);
8858 kind = TypeKind::functionType;
8861 if(exp.call.exp.type == identifierExp)
8863 char * string = exp.call.exp.identifier.string;
8867 Location oldyylloc = yylloc;
8869 yylloc = exp.call.exp.identifier.loc;
8870 if(strstr(string, "__builtin_") == string);
8872 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
8873 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
8874 globalContext.symbols.Add((BTNode)symbol);
8875 if(strstr(symbol.string, "::"))
8876 globalContext.hasNameSpace = true;
8881 else if(exp.call.exp.type == memberExp)
8883 /*Compiler_Warning($"%s undefined; assuming returning int\n",
8884 exp.call.exp.member.member.string);*/
8887 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
8889 if(!functionType.returnType)
8891 functionType.returnType = Type
8898 if(functionType && functionType.kind == TypeKind::functionType)
8900 exp.expType = functionType.returnType;
8902 if(functionType.returnType)
8903 functionType.returnType.refCount++;
8905 if(!functionType.refCount)
8906 FreeType(functionType);
8909 if(exp.call.arguments)
8911 for(e = exp.call.arguments->first; e; e = e.next)
8913 Type destType = e.destType;
8914 ProcessExpressionType(e);
8922 Location oldyylloc = yylloc;
8923 bool thisPtr = (exp.member.exp && exp.member.exp.type == identifierExp && !strcmp(exp.member.exp.identifier.string, "this"));
8924 exp.thisPtr = thisPtr;
8926 // DOING THIS LATER NOW...
8927 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
8929 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
8930 /* TODO: Name Space Fix ups
8931 if(!exp.member.member.classSym)
8932 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
8936 ProcessExpressionType(exp.member.exp);
8937 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
8938 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
8940 exp.isConstant = false;
8943 exp.isConstant = exp.member.exp.isConstant;
8944 type = exp.member.exp.expType;
8948 if(type && (type.kind == templateType))
8950 Class _class = thisClass ? thisClass : currentClass;
8951 ClassTemplateParameter param = null;
8954 for(param = _class.templateParams.first; param; param = param.next)
8956 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
8960 if(param && param.defaultArg.member)
8962 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
8965 Expression expMember = exp.member.exp;
8967 OldList * specs = MkList();
8968 char thisClassTypeString[1024];
8970 FreeIdentifier(exp.member.member);
8972 ProcessExpressionType(argExp);
8975 char * colon = strstr(param.defaultArg.memberString, "::");
8978 char className[1024];
8981 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
8982 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
8985 strcpy(thisClassTypeString, _class.fullName);
8988 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
8990 exp.expType = ProcessType(specs, decl);
8991 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
8993 Class expClass = exp.expType._class.registered;
8994 Class cClass = null;
8999 char templateString[1024];
9000 ClassTemplateParameter param;
9001 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9002 for(cClass = expClass; cClass; cClass = cClass.base)
9005 for(param = cClass.templateParams.first; param; param = param.next)
9009 ClassTemplateArgument arg;
9010 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9011 arg = expClass.templateArgs[id];
9013 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9015 ClassTemplateParameter cParam;
9016 //int p = numParams - sClass.templateParams.count;
9019 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9021 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9023 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9025 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9027 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9028 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9040 strcat(argument, arg.name.string);
9041 strcat(argument, " = ");
9047 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9048 char expString[1024];
9049 OldList * specs = MkList();
9050 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9052 char * string = PrintHexUInt64(arg.expression.ui64);
9053 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9055 ProcessExpressionType(exp);
9056 ComputeExpression(exp);
9057 expString[0] = '\0';
9058 PrintExpression(exp, expString);
9059 strcat(argument, expString);
9061 FreeExpression(exp);
9066 strcat(argument, arg.member.name);
9069 case TemplateParameterType::type:
9071 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9073 if(!strcmp(arg.dataTypeString, "thisclass"))
9074 strcat(argument, thisClassTypeString);
9076 strcat(argument, arg.dataTypeString);
9083 if(paramCount) strcat(templateString, ", ");
9084 if(lastParam != p - 1)
9086 strcat(templateString, param.name);
9087 strcat(templateString, " = ");
9089 strcat(templateString, argument);
9098 int len = strlen(templateString);
9099 if(templateString[len-1] == '>') templateString[len++] = ' ';
9100 templateString[len++] = '>';
9101 templateString[len++] = '\0';
9104 Context context = SetupTemplatesContext(_class);
9105 FreeType(exp.expType);
9106 exp.expType = ProcessTypeString(templateString, false);
9107 FinishTemplatesContext(context);
9111 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9112 exp.type = bracketsExp;
9113 exp.list = MkListOne(MkExpOp(null, '*',
9118 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9119 MkExpBrackets(MkListOne(
9120 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9122 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9124 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9129 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9130 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9132 type = ProcessTemplateParameterType(type.templateParameter);
9136 if(type && (type.kind == templateType));
9137 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9139 Identifier id = exp.member.member;
9140 TypeKind typeKind = type.kind;
9141 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9142 if(typeKind == subClassType && exp.member.exp.type == classExp)
9144 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9145 typeKind = classType;
9148 if(id && (typeKind == intType || typeKind == enumType))
9149 _class = eSystem_FindClass(privateModule, "int");
9154 (exp.member.exp.type == identifierExp &&
9155 !strcmp(exp.member.exp.identifier.string, "this"));*/
9156 Property prop = null;
9157 Method method = null;
9158 DataMember member = null;
9159 Property revConvert = null;
9160 ClassProperty classProp = null;
9162 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9163 exp.member.memberType = propertyMember;
9165 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9166 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9168 if(typeKind != subClassType)
9170 // Prioritize data members over properties for "this"
9171 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9173 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9174 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9176 prop = eClass_FindProperty(_class, id.string, privateModule);
9180 if(!member && !prop)
9181 prop = eClass_FindProperty(_class, id.string, privateModule);
9182 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9183 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9184 exp.member.thisPtr = true;
9186 // Prioritize properties over data members otherwise
9189 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9192 prop = eClass_FindProperty(_class, id.string, null);
9193 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9194 member = eClass_FindDataMember(_class, id.string, null, null, null);
9197 if(!prop && !member)
9199 method = eClass_FindMethod(_class, id.string, null);
9202 prop = eClass_FindProperty(_class, id.string, privateModule);
9203 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9204 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9210 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9217 if(!prop && !member)
9218 method = eClass_FindMethod(_class, id.string, privateModule);
9219 if(!prop && !member && !method)
9221 if(typeKind == subClassType)
9223 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9226 exp.member.memberType = classPropertyMember;
9227 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9231 // Assume this is a class_data member
9232 char structName[1024];
9233 Identifier id = exp.member.member;
9234 Expression classExp = exp.member.exp;
9237 FreeType(classExp.expType);
9238 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9240 strcpy(structName, "__ecereClassData_");
9241 FullClassNameCat(structName, type._class.string, false);
9242 exp.type = pointerExp;
9243 exp.member.member = id;
9245 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9246 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9247 MkExpBrackets(MkListOne(MkExpOp(
9248 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9249 MkExpMember(classExp, MkIdentifier("data"))), '+',
9250 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9255 ProcessExpressionType(exp);
9261 // Check for reverse conversion
9262 // (Convert in an instantiation later, so that we can use
9263 // deep properties system)
9264 Symbol classSym = FindClass(id.string);
9267 Class convertClass = classSym.registered;
9269 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9276 exp.member.memberType = propertyMember;
9278 ProcessPropertyType(prop);
9279 exp.expType = prop.dataType;
9280 if(prop.dataType) prop.dataType.refCount++;
9284 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9286 FreeExpContents(exp);
9287 exp.type = identifierExp;
9288 exp.identifier = MkIdentifier("class");
9289 ProcessExpressionType(exp);
9293 exp.member.memberType = dataMember;
9294 DeclareStruct(_class.fullName, false);
9295 if(!member.dataType)
9297 Context context = SetupTemplatesContext(_class);
9298 member.dataType = ProcessTypeString(member.dataTypeString, false);
9299 FinishTemplatesContext(context);
9301 exp.expType = member.dataType;
9302 if(member.dataType) member.dataType.refCount++;
9306 exp.member.memberType = reverseConversionMember;
9307 exp.expType = MkClassType(revConvert._class.fullName);
9315 exp.type = identifierExp;
9316 exp.identifier = exp.member.member;
9319 exp.member.memberType = methodMember;
9321 if(!method.dataType)
9322 ProcessMethodType(method);
9330 // Tricky spot here... To use instance versus class virtual table
9331 // Put it back to what it was... What did we break?
9333 // Had to put it back for overriding Main of Thread global instance
9335 //exp.expType.methodClass = _class;
9336 exp.expType.methodClass = (id && id._class) ? _class : null;
9338 // Need the actual class used for templated classes
9339 exp.expType.usedClass = _class;
9343 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9345 FreeExpContents(exp);
9346 exp.type = identifierExp;
9347 exp.identifier = MkIdentifier("class");
9348 ProcessExpressionType(exp);
9351 yylloc = exp.member.member.loc;
9352 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9354 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9357 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9362 while(tClass && !tClass.templateClass) tClass = tClass.base;
9364 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9367 ClassTemplateParameter curParam = null;
9370 for(sClass = tClass; sClass; sClass = sClass.base)
9373 if(sClass.templateClass) sClass = sClass.templateClass;
9374 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9376 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9378 for(sClass = sClass.base; sClass; sClass = sClass.base)
9379 id += sClass.templateParams.count;
9387 if(curParam && tClass.templateArgs[id].dataTypeString)
9389 ClassTemplateArgument arg = tClass.templateArgs[id];
9390 Context context = SetupTemplatesContext(tClass);
9392 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9393 FreeType(exp.expType);
9394 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9397 if(exp.expType.kind == thisClassType)
9399 FreeType(exp.expType);
9400 exp.expType = ReplaceThisClassType(_class);
9403 if(tClass.templateClass)
9404 exp.expType.passAsTemplate = true;
9405 //exp.expType.refCount++;
9408 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9409 //exp.destType.refCount++;
9411 if(exp.destType.kind == thisClassType)
9413 FreeType(exp.destType);
9414 exp.destType = ReplaceThisClassType(_class);
9418 FinishTemplatesContext(context);
9421 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9422 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9425 ClassTemplateParameter curParam = null;
9428 for(sClass = tClass; sClass; sClass = sClass.base)
9431 if(sClass.templateClass) sClass = sClass.templateClass;
9432 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9434 if(curParam.type == TemplateParameterType::type &&
9435 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9437 for(sClass = sClass.base; sClass; sClass = sClass.base)
9438 id += sClass.templateParams.count;
9448 ClassTemplateArgument arg = tClass.templateArgs[id];
9449 Context context = SetupTemplatesContext(tClass);
9452 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9454 basicType = ProcessTypeString(arg.dataTypeString, false);
9457 if(basicType.kind == thisClassType)
9459 FreeType(basicType);
9460 basicType = ReplaceThisClassType(_class);
9463 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9464 if(tClass.templateClass)
9465 basicType.passAsTemplate = true;
9468 FreeType(exp.expType);
9470 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9471 //exp.expType.refCount++;
9474 exp.destType = exp.expType;
9475 exp.destType.refCount++;
9479 Expression newExp { };
9480 OldList * specs = MkList();
9482 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9484 if(exp.destType) exp.destType.refCount++;
9485 if(exp.expType) exp.expType.refCount++;
9487 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9488 exp.cast.exp = newExp;
9489 //FreeType(exp.expType);
9490 //exp.expType = null;
9491 //ProcessExpressionType(sourceExp);
9494 FinishTemplatesContext(context);
9497 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9499 Class expClass = exp.expType._class.registered;
9502 Class cClass = null;
9507 char templateString[1024];
9508 ClassTemplateParameter param;
9509 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9510 while(cClass != expClass)
9513 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9516 for(param = cClass.templateParams.first; param; param = param.next)
9518 Class cClassCur = null;
9521 ClassTemplateParameter paramCur = null;
9522 ClassTemplateArgument arg;
9523 while(cClassCur != tClass && !paramCur)
9526 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
9527 cClassCur = sClassCur;
9529 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
9531 if(!strcmp(paramCur.name, param.name))
9539 if(paramCur && paramCur.type == TemplateParameterType::type)
9540 arg = tClass.templateArgs[cp];
9542 arg = expClass.templateArgs[p];
9549 strcat(argument, arg.name.string);
9550 strcat(argument, " = ");
9556 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9557 char expString[1024];
9558 OldList * specs = MkList();
9559 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9561 char * string = PrintHexUInt64(arg.expression.ui64);
9562 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9564 ProcessExpressionType(exp);
9565 ComputeExpression(exp);
9566 expString[0] = '\0';
9567 PrintExpression(exp, expString);
9568 strcat(argument, expString);
9570 FreeExpression(exp);
9575 strcat(argument, arg.member.name);
9578 case TemplateParameterType::type:
9580 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9581 strcat(argument, arg.dataTypeString);
9587 if(paramCount) strcat(templateString, ", ");
9588 if(lastParam != p - 1)
9590 strcat(templateString, param.name);
9591 strcat(templateString, " = ");
9593 strcat(templateString, argument);
9602 int len = strlen(templateString);
9603 if(templateString[len-1] == '>') templateString[len++] = ' ';
9604 templateString[len++] = '>';
9605 templateString[len++] = '\0';
9608 FreeType(exp.expType);
9610 Context context = SetupTemplatesContext(tClass);
9611 exp.expType = ProcessTypeString(templateString, false);
9612 FinishTemplatesContext(context);
9619 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
9621 else if(type && (type.kind == structType || type.kind == unionType))
9623 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
9626 exp.expType = memberType;
9628 memberType.refCount++;
9633 char expString[10240];
9634 expString[0] = '\0';
9635 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
9636 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
9639 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
9641 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9643 Identifier id = exp.member.member;
9644 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9647 FreeType(exp.expType);
9648 exp.expType = ReplaceThisClassType(_class);
9655 // Convert x->y into (*x).y
9658 Type destType = exp.destType;
9660 // DOING THIS LATER NOW...
9661 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9663 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9664 /* TODO: Name Space Fix ups
9665 if(!exp.member.member.classSym)
9666 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
9670 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
9671 exp.type = memberExp;
9674 ProcessExpressionType(exp);
9681 //ComputeExpression(exp);
9683 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
9684 if(classSym && classSym.registered)
9686 if(classSym.registered.type == noHeadClass)
9690 DeclareStruct(classSym.string, false);
9691 FreeSpecifier(exp._class);
9692 exp.type = typeSizeExp;
9693 FullClassNameCat(name, classSym.string, false);
9694 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
9698 if(classSym.registered.fixed)
9700 FreeSpecifier(exp._class);
9701 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
9702 exp.type = constantExp;
9706 char className[1024];
9707 strcpy(className, "__ecereClass_");
9708 FullClassNameCat(className, classSym.string, true);
9709 MangleClassName(className);
9711 DeclareClass(classSym, className);
9713 FreeExpContents(exp);
9714 exp.type = pointerExp;
9715 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
9716 exp.member.member = MkIdentifier("structSize");
9726 // exp.isConstant = true;
9731 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
9738 exp.isConstant = true;
9740 DeclareType(type, false, false);
9746 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
9748 FreeType(exp.cast.exp.destType);
9749 exp.cast.exp.destType = type;
9751 ProcessExpressionType(exp.cast.exp);
9756 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
9757 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
9759 void * prev = exp.prev, * next = exp.next;
9760 Type expType = exp.cast.exp.destType;
9761 Expression castExp = exp.cast.exp;
9762 Type destType = exp.destType;
9764 if(expType) expType.refCount++;
9766 //FreeType(exp.destType);
9767 FreeType(exp.expType);
9768 FreeTypeName(exp.cast.typeName);
9771 FreeType(exp.expType);
9772 FreeType(exp.destType);
9774 exp.expType = expType;
9775 exp.destType = destType;
9785 exp.isConstant = exp.cast.exp.isConstant;
9790 case extensionInitializerExp:
9792 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
9795 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
9796 // ProcessInitializer(exp.initializer.initializer, type);
9802 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
9803 ProcessExpressionType(exp.vaArg.exp);
9811 exp.isConstant = true;
9813 FreeType(exp.cond.cond.destType);
9814 exp.cond.cond.destType = MkClassType("bool");
9815 exp.cond.cond.destType.truth = true;
9816 ProcessExpressionType(exp.cond.cond);
9817 if(!exp.cond.cond.isConstant)
9818 exp.isConstant = false;
9819 for(e = exp.cond.exp->first; e; e = e.next)
9823 FreeType(e.destType);
9824 e.destType = exp.destType;
9825 if(e.destType) e.destType.refCount++;
9827 ProcessExpressionType(e);
9830 exp.expType = e.expType;
9831 if(e.expType) e.expType.refCount++;
9834 exp.isConstant = false;
9837 FreeType(exp.cond.elseExp.destType);
9838 // Added this check if we failed to find an expType
9839 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
9842 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
9844 if(exp.cond.elseExp.destType)
9845 exp.cond.elseExp.destType.refCount++;
9846 ProcessExpressionType(exp.cond.elseExp);
9848 // FIXED THIS: Was done before calling process on elseExp
9849 if(!exp.cond.elseExp.isConstant)
9850 exp.isConstant = false;
9853 case extensionCompoundExp:
9855 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
9857 Statement last = exp.compound.compound.statements->last;
9858 if(last.type == expressionStmt && last.expressions && last.expressions->last)
9860 ((Expression)last.expressions->last).destType = exp.destType;
9862 exp.destType.refCount++;
9864 ProcessStatement(exp.compound);
9865 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
9867 exp.expType.refCount++;
9873 Specifier spec = exp._classExp.specifiers->first;
9874 if(spec && spec.type == nameSpecifier)
9876 exp.expType = MkClassType(spec.name);
9877 exp.expType.kind = subClassType;
9878 exp.byReference = true;
9882 exp.expType = MkClassType("ecere::com::Class");
9883 exp.byReference = true;
9889 Class _class = thisClass ? thisClass : currentClass;
9892 Identifier id = exp.classData.id;
9893 char structName[1024];
9894 Expression classExp;
9895 strcpy(structName, "__ecereClassData_");
9896 FullClassNameCat(structName, _class.fullName, false);
9897 exp.type = pointerExp;
9898 exp.member.member = id;
9899 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
9900 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
9902 classExp = MkExpIdentifier(MkIdentifier("class"));
9904 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9905 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9906 MkExpBrackets(MkListOne(MkExpOp(
9907 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9908 MkExpMember(classExp, MkIdentifier("data"))), '+',
9909 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
9912 ProcessExpressionType(exp);
9920 char * typeString = null;
9921 char typeStringBuf[1024];
9922 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
9923 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
9925 Class templateClass = exp.destType._class.registered;
9926 typeString = templateClass.templateArgs[2].dataTypeString;
9930 // Guess type from expressions in the array
9932 for(e = exp.list->first; e; e = e.next)
9934 ProcessExpressionType(e);
9937 if(!type) { type = e.expType; type.refCount++; }
9940 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
9941 if(!MatchTypeExpression(e, type, null, false))
9947 e = exp.list->first;
9948 ProcessExpressionType(e);
9951 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
9952 if(!MatchTypeExpression(e, type, null, false))
9954 FreeType(e.expType);
9965 FreeType(e.expType);
9972 typeStringBuf[0] = '\0';
9973 PrintType(type, typeStringBuf, false, true);
9974 typeString = typeStringBuf;
9982 (Container)& (struct BuiltInContainer)
9984 ._vTbl = class(BuiltInContainer)._vTbl,
9985 ._class = class(BuiltInContainer),
9987 .data = (int[]){ 1, 7, 3, 4, 5 },
9992 char templateString[1024];
9993 OldList * initializers = MkList();
9994 OldList * structInitializers = MkList();
9995 OldList * specs = MkList();
9997 Declarator decl = SpecDeclFromString(typeString, specs, null);
9998 sprintf(templateString, "Container<%s>", typeString);
10003 type = ProcessTypeString(typeString, false);
10004 while(e = exp.list->first)
10006 exp.list->Remove(e);
10009 ProcessExpressionType(e);
10010 ListAdd(initializers, MkInitializerAssignment(e));
10016 DeclareStruct("ecere::com::BuiltInContainer", false);
10018 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10019 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10020 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10021 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10022 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10023 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10024 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10025 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10026 MkInitializerList(initializers))));
10027 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10028 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10029 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10030 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10031 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10032 exp.expType = ProcessTypeString(templateString, false);
10033 exp.type = bracketsExp;
10034 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10036 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10037 MkInitializerList(structInitializers)))));
10038 ProcessExpressionType(expExt);
10042 exp.expType = ProcessTypeString("Container", false);
10043 Compiler_Error($"Couldn't determine type of array elements\n");
10049 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10051 FreeType(exp.expType);
10052 exp.expType = ReplaceThisClassType(thisClass);
10055 // Resolve structures here
10056 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10058 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10059 // TODO: Fix members reference...
10062 if(exp.expType.kind != enumType)
10065 String enumName = CopyString(exp.expType.enumName);
10067 // Fixed a memory leak on self-referencing C structs typedefs
10068 // by instantiating a new type rather than simply copying members
10069 // into exp.expType
10070 FreeType(exp.expType);
10071 exp.expType = Type { };
10072 exp.expType.kind = symbol.type.kind;
10073 exp.expType.refCount++;
10074 exp.expType.enumName = enumName;
10076 exp.expType.members = symbol.type.members;
10077 for(member = symbol.type.members.first; member; member = member.next)
10083 for(member = symbol.type.members.first; member; member = member.next)
10085 NamedLink value { name = CopyString(member.name) };
10086 exp.expType.members.Add(value);
10093 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10094 else if(exp.destType && !exp.destType.keepCast)
10096 if(!CheckExpressionType(exp, exp.destType, false))
10098 if(!exp.destType.count || unresolved)
10103 if(exp.destType.kind != ellipsisType)
10109 char expString[10240];
10110 expString[0] = '\0';
10112 PrintType(exp.destType, type2, false, true);
10114 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10116 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10117 else if(exp.type != dummyExp)
10118 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10123 char expString[10240] ;
10124 expString[0] = '\0';
10125 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10128 Compiler_Error($"unresolved identifier %s\n", expString);
10129 else if(exp.type != dummyExp)
10130 Compiler_Error($"couldn't determine type of %s\n", expString);
10141 PrintType(exp.expType, type1, false, true);
10142 PrintType(exp.destType, type2, false, true);
10145 //CheckExpressionType(exp, exp.destType, false);
10147 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10148 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10149 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10152 char expString[10240];
10153 expString[0] = '\0';
10154 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10157 CheckExpressionType(exp, exp.destType, false);
10159 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10160 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10161 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10163 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10164 FreeType(exp.expType);
10165 exp.destType.refCount++;
10166 exp.expType = exp.destType;
10171 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10173 Expression newExp { };
10174 char typeString[1024];
10175 OldList * specs = MkList();
10178 typeString[0] = '\0';
10182 if(exp.expType) exp.expType.refCount++;
10183 if(exp.expType) exp.expType.refCount++;
10184 exp.type = castExp;
10185 newExp.destType = exp.expType;
10187 PrintType(exp.expType, typeString, false, false);
10188 decl = SpecDeclFromString(typeString, specs, null);
10190 exp.cast.typeName = MkTypeName(specs, decl);
10191 exp.cast.exp = newExp;
10194 else if(unresolved)
10196 if(exp.identifier._class && exp.identifier._class.name)
10197 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10198 else if(exp.identifier.string && exp.identifier.string[0])
10199 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10201 else if(!exp.expType && exp.type != dummyExp)
10203 char expString[10240];
10204 expString[0] = '\0';
10205 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10206 Compiler_Error($"couldn't determine type of %s\n", expString);
10209 // Let's try to support any_object & typed_object here:
10210 ApplyAnyObjectLogic(exp);
10212 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10213 exp.expType._class.registered.type == noHeadClass)
10215 exp.byReference = true;
10217 /*else if(!notByReference && exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10218 exp.destType._class.registered.type == noHeadClass)
10220 exp.byReference = true;
10222 yylloc = oldyylloc;
10225 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10227 // THIS CODE WILL FIND NEXT MEMBER...
10230 *curMember = (*curMember).next;
10232 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10234 *curMember = subMemberStack[--(*subMemberStackPos)];
10235 *curMember = (*curMember).next;
10238 // SKIP ALL PROPERTIES HERE...
10239 while((*curMember) && (*curMember).isProperty)
10240 *curMember = (*curMember).next;
10242 if(subMemberStackPos)
10244 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10246 subMemberStack[(*subMemberStackPos)++] = *curMember;
10248 *curMember = (*curMember).members.first;
10249 while(*curMember && (*curMember).isProperty)
10250 *curMember = (*curMember).next;
10258 if(subMemberStackPos && *subMemberStackPos)
10260 *curMember = subMemberStack[--(*subMemberStackPos)];
10261 *curMember = (*curMember).next;
10265 Class lastCurClass = *curClass;
10267 if(*curClass == _class) break; // REACHED THE END
10269 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10270 *curMember = (*curClass).membersAndProperties.first;
10273 while((*curMember) && (*curMember).isProperty)
10274 *curMember = (*curMember).next;
10275 if(subMemberStackPos)
10277 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10279 subMemberStack[(*subMemberStackPos)++] = *curMember;
10281 *curMember = (*curMember).members.first;
10282 while(*curMember && (*curMember).isProperty)
10283 *curMember = (*curMember).next;
10291 static void ProcessInitializer(Initializer init, Type type)
10295 case expInitializer:
10296 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10298 // TESTING THIS FOR SHUTTING = 0 WARNING
10299 if(init.exp && !init.exp.destType)
10301 FreeType(init.exp.destType);
10302 init.exp.destType = type;
10303 if(type) type.refCount++;
10307 ProcessExpressionType(init.exp);
10308 init.isConstant = init.exp.isConstant;
10314 Expression exp = init.exp;
10315 Instantiation inst = exp.instance;
10316 MembersInit members;
10318 init.type = listInitializer;
10319 init.list = MkList();
10323 for(members = inst.members->first; members; members = members.next)
10325 if(members.type == dataMembersInit)
10328 for(member = members.dataMembers->first; member; member = member.next)
10330 ListAdd(init.list, member.initializer);
10331 member.initializer = null;
10334 // Discard all MembersInitMethod
10337 FreeExpression(exp);
10339 case listInitializer:
10342 Type initializerType = null;
10343 Class curClass = null;
10344 DataMember curMember = null;
10345 DataMember subMemberStack[256];
10346 int subMemberStackPos = 0;
10348 if(type && type.kind == arrayType)
10349 initializerType = Dereference(type);
10350 else if(type && (type.kind == structType || type.kind == unionType))
10351 initializerType = type.members.first;
10353 for(i = init.list->first; i; i = i.next)
10355 if(type && type.kind == classType && type._class && type._class.registered)
10357 // 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)
10358 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10359 // TODO: Generate error on initializing a private data member this way from another module...
10362 if(!curMember.dataType)
10363 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10364 initializerType = curMember.dataType;
10367 ProcessInitializer(i, initializerType);
10368 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10369 initializerType = initializerType.next;
10371 init.isConstant = false;
10374 if(type && type.kind == arrayType)
10375 FreeType(initializerType);
10377 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10379 Compiler_Error($"Assigning list initializer to non list\n");
10386 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10390 case baseSpecifier:
10392 if(spec.specifier == THISCLASS)
10396 spec.type = nameSpecifier;
10397 spec.name = ReplaceThisClass(thisClass);
10398 spec.symbol = FindClass(spec.name);
10399 ProcessSpecifier(spec, declareStruct);
10404 case nameSpecifier:
10406 Symbol symbol = FindType(curContext, spec.name);
10408 DeclareType(symbol.type, true, true);
10409 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10410 DeclareStruct(spec.name, false);
10413 case enumSpecifier:
10418 for(e = spec.list->first; e; e = e.next)
10421 ProcessExpressionType(e.exp);
10426 case structSpecifier:
10427 case unionSpecifier:
10429 if(spec.definitions)
10432 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10434 ProcessClass(spec.definitions, symbol);
10437 for(def = spec.definitions->first; def; def = def.next)
10439 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10440 ProcessDeclaration(def.decl);
10447 case classSpecifier:
10449 Symbol classSym = FindClass(spec.name);
10450 if(classSym && classSym.registered && classSym.registered.type == structClass)
10451 DeclareStruct(spec.name, false);
10459 static void ProcessDeclarator(Declarator decl)
10463 case identifierDeclarator:
10464 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10466 FreeSpecifier(decl.identifier._class);
10467 decl.identifier._class = null;
10470 case arrayDeclarator:
10472 ProcessExpressionType(decl.array.exp);
10473 case structDeclarator:
10474 case bracketsDeclarator:
10475 case functionDeclarator:
10476 case pointerDeclarator:
10477 case extendedDeclarator:
10478 case extendedDeclaratorEnd:
10479 if(decl.declarator)
10480 ProcessDeclarator(decl.declarator);
10481 if(decl.type == functionDeclarator)
10483 Identifier id = GetDeclId(decl);
10484 if(id && id._class)
10488 qualifiers = MkListOne(id._class);
10491 if(!decl.function.parameters)
10492 decl.function.parameters = MkList();
10493 decl.function.parameters->Insert(null, param);
10496 if(decl.function.parameters)
10500 for(param = decl.function.parameters->first; param; param = param.next)
10502 if(param.qualifiers && param.qualifiers->first)
10504 Specifier spec = param.qualifiers->first;
10505 if(spec && spec.specifier == TYPED_OBJECT)
10507 Declarator d = param.declarator;
10510 qualifiers = MkListOne(MkSpecifier(VOID));
10511 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10514 FreeList(param.qualifiers, FreeSpecifier);
10516 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10517 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10519 decl.function.parameters->Insert(param, newParam);
10522 else if(spec && spec.specifier == ANY_OBJECT)
10524 Declarator d = param.declarator;
10526 FreeList(param.qualifiers, FreeSpecifier);
10528 param.qualifiers = MkListOne(MkSpecifier(VOID));
10529 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10531 else if(spec.specifier == THISCLASS)
10535 spec.type = nameSpecifier;
10536 spec.name = ReplaceThisClass(thisClass);
10537 spec.symbol = FindClass(spec.name);
10538 ProcessSpecifier(spec, false);
10543 if(param.declarator)
10544 ProcessDeclarator(param.declarator);
10552 static void ProcessDeclaration(Declaration decl)
10557 case initDeclaration:
10559 bool declareStruct = false;
10561 lineNum = decl.pos.line;
10562 column = decl.pos.col;
10565 if(decl.declarators)
10569 for(d = decl.declarators->first; d; d = d.next)
10571 Type type, subType;
10572 ProcessDeclarator(d.declarator);
10574 type = ProcessType(decl.specifiers, d.declarator);
10578 ProcessInitializer(d.initializer, type);
10580 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
10582 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
10583 d.initializer.exp.type == instanceExp)
10585 if(type.kind == classType && type._class ==
10586 d.initializer.exp.expType._class)
10588 Instantiation inst = d.initializer.exp.instance;
10589 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
10591 d.initializer.exp.instance = null;
10592 if(decl.specifiers)
10593 FreeList(decl.specifiers, FreeSpecifier);
10594 FreeList(decl.declarators, FreeInitDeclarator);
10598 decl.type = instDeclaration;
10603 for(subType = type; subType;)
10605 if(subType.kind == classType)
10607 declareStruct = true;
10610 else if(subType.kind == pointerType)
10612 else if(subType.kind == arrayType)
10613 subType = subType.arrayType;
10623 if(decl.specifiers)
10626 for(s = decl.specifiers->first; s; s = s.next)
10628 ProcessSpecifier(s, declareStruct);
10633 case instDeclaration:
10635 ProcessInstantiationType(decl.inst);
10638 case structDeclaration:
10642 bool declareStruct = false;
10644 if(decl.declarators)
10646 for(d = decl.declarators->first; d; d = d.next)
10648 Type type = ProcessType(decl.specifiers, d.declarator);
10650 ProcessDeclarator(d);
10651 for(subType = type; subType;)
10653 if(subType.kind == classType)
10655 declareStruct = true;
10658 else if(subType.kind == pointerType)
10660 else if(subType.kind == arrayType)
10661 subType = subType.arrayType;
10668 if(decl.specifiers)
10670 for(spec = decl.specifiers->first; spec; spec = spec.next)
10671 ProcessSpecifier(spec, declareStruct);
10678 static FunctionDefinition curFunction;
10680 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
10682 char propName[1024], propNameM[1024];
10683 char getName[1024], setName[1024];
10686 DeclareProperty(prop, setName, getName);
10688 // eInstance_FireWatchers(object, prop);
10689 strcpy(propName, "__ecereProp_");
10690 FullClassNameCat(propName, prop._class.fullName, false);
10691 strcat(propName, "_");
10692 // strcat(propName, prop.name);
10693 FullClassNameCat(propName, prop.name, true);
10694 MangleClassName(propName);
10696 strcpy(propNameM, "__ecerePropM_");
10697 FullClassNameCat(propNameM, prop._class.fullName, false);
10698 strcat(propNameM, "_");
10699 // strcat(propNameM, prop.name);
10700 FullClassNameCat(propNameM, prop.name, true);
10701 MangleClassName(propNameM);
10703 if(prop.isWatchable)
10706 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10707 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10708 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10711 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10712 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10713 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10719 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10720 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10721 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10724 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10725 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10726 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10729 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
10730 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
10731 curFunction.propSet.fireWatchersDone = true;
10734 static void ProcessStatement(Statement stmt)
10738 lineNum = stmt.pos.line;
10739 column = stmt.pos.col;
10744 ProcessStatement(stmt.labeled.stmt);
10747 // This expression should be constant...
10748 if(stmt.caseStmt.exp)
10750 FreeType(stmt.caseStmt.exp.destType);
10751 stmt.caseStmt.exp.destType = curSwitchType;
10752 if(curSwitchType) curSwitchType.refCount++;
10753 ProcessExpressionType(stmt.caseStmt.exp);
10754 ComputeExpression(stmt.caseStmt.exp);
10756 if(stmt.caseStmt.stmt)
10757 ProcessStatement(stmt.caseStmt.stmt);
10761 if(stmt.compound.context)
10766 Statement prevCompound = curCompound;
10767 Context prevContext = curContext;
10769 if(!stmt.compound.isSwitch)
10771 curCompound = stmt;
10772 curContext = stmt.compound.context;
10775 if(stmt.compound.declarations)
10777 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
10778 ProcessDeclaration(decl);
10780 if(stmt.compound.statements)
10782 for(s = stmt.compound.statements->first; s; s = s.next)
10783 ProcessStatement(s);
10786 curContext = prevContext;
10787 curCompound = prevCompound;
10791 case expressionStmt:
10794 if(stmt.expressions)
10796 for(exp = stmt.expressions->first; exp; exp = exp.next)
10797 ProcessExpressionType(exp);
10805 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
10806 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
10807 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
10808 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
10810 ProcessExpressionType(exp);
10812 if(stmt.ifStmt.stmt)
10813 ProcessStatement(stmt.ifStmt.stmt);
10814 if(stmt.ifStmt.elseStmt)
10815 ProcessStatement(stmt.ifStmt.elseStmt);
10820 Type oldSwitchType = curSwitchType;
10821 if(stmt.switchStmt.exp)
10824 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
10834 e.exp.destType = destType;
10837 ProcessExpressionType(exp);
10840 curSwitchType = exp.expType;
10843 ProcessStatement(stmt.switchStmt.stmt);
10844 curSwitchType = oldSwitchType;
10849 if(stmt.whileStmt.exp)
10853 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
10854 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
10855 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
10856 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
10858 ProcessExpressionType(exp);
10861 if(stmt.whileStmt.stmt)
10862 ProcessStatement(stmt.whileStmt.stmt);
10867 if(stmt.doWhile.exp)
10871 if(stmt.doWhile.exp->last)
10873 FreeType(((Expression)stmt.doWhile.exp->last).destType);
10874 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
10875 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
10877 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
10879 ProcessExpressionType(exp);
10882 if(stmt.doWhile.stmt)
10883 ProcessStatement(stmt.doWhile.stmt);
10889 if(stmt.forStmt.init)
10890 ProcessStatement(stmt.forStmt.init);
10892 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
10894 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
10895 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
10896 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
10899 if(stmt.forStmt.check)
10900 ProcessStatement(stmt.forStmt.check);
10901 if(stmt.forStmt.increment)
10903 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
10904 ProcessExpressionType(exp);
10907 if(stmt.forStmt.stmt)
10908 ProcessStatement(stmt.forStmt.stmt);
10913 Identifier id = stmt.forEachStmt.id;
10914 OldList * exp = stmt.forEachStmt.exp;
10915 OldList * filter = stmt.forEachStmt.filter;
10916 Statement block = stmt.forEachStmt.stmt;
10917 char iteratorType[1024];
10920 bool isBuiltin = exp && exp->last &&
10921 (((Expression)exp->last).type == ExpressionType::arrayExp ||
10922 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
10923 Expression arrayExp;
10924 char * typeString = null;
10925 int builtinCount = 0;
10927 for(e = exp ? exp->first : null; e; e = e.next)
10931 FreeType(e.destType);
10932 e.destType = ProcessTypeString("Container", false);
10934 if(!isBuiltin || e.next)
10935 ProcessExpressionType(e);
10938 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
10939 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
10940 eClass_IsDerived(source._class.registered, containerClass)))
10942 Class _class = source ? source._class.registered : null;
10944 Expression expIt = null;
10945 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
10946 Class arrayClass = eSystem_FindClass(privateModule, "Array");
10947 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
10948 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
10949 stmt.type = compoundStmt;
10951 stmt.compound.context = Context { };
10952 stmt.compound.context.parent = curContext;
10953 curContext = stmt.compound.context;
10955 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
10957 Class mapClass = eSystem_FindClass(privateModule, "Map");
10958 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
10959 isCustomAVLTree = true;
10960 if(eClass_IsDerived(source._class.registered, avlTreeClass))
10962 else if(eClass_IsDerived(source._class.registered, mapClass))
10965 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
10966 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
10968 Class listClass = eSystem_FindClass(privateModule, "List");
10970 isList = eClass_IsDerived(source._class.registered, listClass);
10976 OldList * specs = MkList();
10977 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
10978 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
10979 stmt.compound.declarations = MkListOne(
10980 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
10981 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
10982 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
10983 MkInitializerAssignment(MkExpBrackets(exp))))));
10988 char typeStringBuf[1024];
10990 // TODO: Merge this code?
10991 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
10992 if(((Expression)exp->last).type == castExp)
10994 TypeName typeName = ((Expression)exp->last).cast.typeName;
10996 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
10999 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11000 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11001 arrayExp.destType._class.registered.templateArgs)
11003 Class templateClass = arrayExp.destType._class.registered;
11004 typeString = templateClass.templateArgs[2].dataTypeString;
11006 else if(arrayExp.list)
11008 // Guess type from expressions in the array
11010 for(e = arrayExp.list->first; e; e = e.next)
11012 ProcessExpressionType(e);
11015 if(!type) { type = e.expType; type.refCount++; }
11018 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11019 if(!MatchTypeExpression(e, type, null, false))
11025 e = arrayExp.list->first;
11026 ProcessExpressionType(e);
11029 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11030 if(!MatchTypeExpression(e, type, null, false))
11032 FreeType(e.expType);
11043 FreeType(e.expType);
11050 typeStringBuf[0] = '\0';
11051 PrintType(type, typeStringBuf, false, true);
11052 typeString = typeStringBuf;
11058 OldList * initializers = MkList();
11060 OldList * specs = MkList();
11065 builtinCount = arrayExp.list->count;
11066 type = ProcessTypeString(typeString, false);
11067 while(e = arrayExp.list->first)
11069 arrayExp.list->Remove(e);
11072 ProcessExpressionType(e);
11073 ListAdd(initializers, MkInitializerAssignment(e));
11076 delete arrayExp.list;
11078 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11079 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11080 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11082 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorArray(PlugDeclarator(
11083 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorIdentifier(MkIdentifier("__internalArray"))), null), MkInitializerList(initializers)))));
11085 FreeList(exp, FreeExpression);
11089 arrayExp.expType = ProcessTypeString("Container", false);
11090 Compiler_Error($"Couldn't determine type of array elements\n");
11095 OldList * specs = MkList();
11097 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11098 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11099 stmt.compound.declarations = MkListOne(
11100 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11101 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11102 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11103 MkInitializerAssignment(MkExpBrackets(exp))))));
11106 else if(isLinkList && !isList)
11109 OldList * specs = MkList();
11110 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11111 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11112 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11113 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11114 MkInitializerAssignment(MkExpBrackets(exp))))));
11116 /*else if(isCustomAVLTree)
11119 OldList * specs = MkList();
11120 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11121 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11122 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11123 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11124 MkInitializerAssignment(MkExpBrackets(exp))))));
11126 else if(_class.templateArgs)
11129 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11131 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11133 stmt.compound.declarations = MkListOne(
11134 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11135 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11136 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11138 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11140 if(block && block.type == compoundStmt && block.compound.context)
11142 block.compound.context.parent = stmt.compound.context;
11146 block = MkIfStmt(filter, block, null);
11150 stmt.compound.statements = MkListOne(MkForStmt(
11151 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11152 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11153 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11154 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11156 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11157 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11158 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11163 //OldList * specs = MkList();
11164 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11166 sprintf(count, "%d", builtinCount);
11168 stmt.compound.statements = MkListOne(MkForStmt(
11169 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11170 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11171 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11172 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11176 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11177 stmt.compound.statements = MkListOne(MkForStmt(
11178 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11179 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11180 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11181 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11184 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11185 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11186 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11188 else if(isLinkList && !isList)
11190 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11191 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11192 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11193 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11195 stmt.compound.statements = MkListOne(MkForStmt(
11196 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11197 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11198 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11203 OldList * specs = MkList();
11204 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11205 stmt.compound.statements = MkListOne(MkForStmt(
11206 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11207 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11208 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11209 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11210 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11213 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11214 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11215 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11217 /*else if(isCustomAVLTree)
11219 stmt.compound.statements = MkListOne(MkForStmt(
11220 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11221 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11222 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11223 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11226 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11227 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11228 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11232 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11233 MkIdentifier("Next")), null)), block));
11235 ProcessExpressionType(expIt);
11236 if(stmt.compound.declarations->first)
11237 ProcessDeclaration(stmt.compound.declarations->first);
11240 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11242 ProcessStatement(stmt);
11243 curContext = stmt.compound.context.parent;
11248 Compiler_Error($"Expression is not a container\n");
11261 if(stmt.expressions)
11263 for(exp = stmt.expressions->first; exp; exp = exp.next)
11267 if(curFunction && !curFunction.type)
11268 curFunction.type = ProcessType(
11269 curFunction.specifiers, curFunction.declarator);
11270 FreeType(exp.destType);
11271 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11272 if(exp.destType) exp.destType.refCount++;
11274 ProcessExpressionType(exp);
11279 case badDeclarationStmt:
11281 ProcessDeclaration(stmt.decl);
11287 if(stmt.asmStmt.inputFields)
11289 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11290 if(field.expression)
11291 ProcessExpressionType(field.expression);
11293 if(stmt.asmStmt.outputFields)
11295 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11296 if(field.expression)
11297 ProcessExpressionType(field.expression);
11299 if(stmt.asmStmt.clobberedFields)
11301 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11303 if(field.expression)
11304 ProcessExpressionType(field.expression);
11311 PropertyWatch propWatch;
11312 OldList * watches = stmt._watch.watches;
11313 Expression object = stmt._watch.object;
11314 Expression watcher = stmt._watch.watcher;
11316 ProcessExpressionType(watcher);
11318 ProcessExpressionType(object);
11322 if(watcher || thisClass)
11324 External external = curExternal;
11325 Context context = curContext;
11327 stmt.type = expressionStmt;
11328 stmt.expressions = MkList();
11330 curExternal = external.prev;
11332 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11334 ClassFunction func;
11335 char watcherName[1024];
11336 Class watcherClass = watcher ?
11337 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11338 External createdExternal;
11340 // Create a declaration above
11341 External externalDecl = MkExternalDeclaration(null);
11342 ast->Insert(curExternal.prev, externalDecl);
11344 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11345 if(propWatch.deleteWatch)
11346 strcat(watcherName, "_delete");
11350 for(propID = propWatch.properties->first; propID; propID = propID.next)
11352 strcat(watcherName, "_");
11353 strcat(watcherName, propID.string);
11357 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11359 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11360 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11361 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11362 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11363 ProcessClassFunctionBody(func, propWatch.compound);
11364 propWatch.compound = null;
11366 //afterExternal = afterExternal ? afterExternal : curExternal;
11368 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11369 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11371 createdExternal.symbol.idCode = external.symbol.idCode;
11373 curExternal = createdExternal;
11374 ProcessFunction(createdExternal.function);
11377 // Create a declaration above
11379 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11380 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11381 externalDecl.declaration = decl;
11382 if(decl.symbol && !decl.symbol.pointerExternal)
11383 decl.symbol.pointerExternal = externalDecl;
11386 if(propWatch.deleteWatch)
11388 OldList * args = MkList();
11389 ListAdd(args, CopyExpression(object));
11390 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11391 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11392 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11396 Class _class = object.expType._class.registered;
11399 for(propID = propWatch.properties->first; propID; propID = propID.next)
11401 char propName[1024];
11402 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11405 char getName[1024], setName[1024];
11406 OldList * args = MkList();
11408 DeclareProperty(prop, setName, getName);
11410 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11411 strcpy(propName, "__ecereProp_");
11412 FullClassNameCat(propName, prop._class.fullName, false);
11413 strcat(propName, "_");
11414 // strcat(propName, prop.name);
11415 FullClassNameCat(propName, prop.name, true);
11417 ListAdd(args, CopyExpression(object));
11418 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11419 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11420 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11422 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11425 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11430 Compiler_Error($"Invalid watched object\n");
11433 curExternal = external;
11434 curContext = context;
11437 FreeExpression(watcher);
11439 FreeExpression(object);
11440 FreeList(watches, FreePropertyWatch);
11443 Compiler_Error($"No observer specified and not inside a _class\n");
11447 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11449 ProcessStatement(propWatch.compound);
11455 case fireWatchersStmt:
11457 OldList * watches = stmt._watch.watches;
11458 Expression object = stmt._watch.object;
11460 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11461 // printf("%X\n", watches);
11462 // printf("%X\n", stmt._watch.watches);
11464 ProcessExpressionType(object);
11469 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11475 stmt.type = expressionStmt;
11476 stmt.expressions = MkList();
11478 // Check if we're inside a property set
11479 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11481 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
11485 //Compiler_Error($"No property specified and not inside a property set\n");
11489 for(propID = watches->first; propID; propID = propID.next)
11491 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11494 CreateFireWatcher(prop, object, stmt);
11497 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
11502 // Fire all properties!
11505 for(base = _class; base; base = base.base)
11507 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
11509 if(prop.isProperty && prop.isWatchable)
11511 CreateFireWatcher(prop, object, stmt);
11518 FreeExpression(object);
11519 FreeList(watches, FreeIdentifier);
11522 Compiler_Error($"Invalid object specified and not inside a class\n");
11526 case stopWatchingStmt:
11528 OldList * watches = stmt._watch.watches;
11529 Expression object = stmt._watch.object;
11530 Expression watcher = stmt._watch.watcher;
11533 ProcessExpressionType(object);
11535 ProcessExpressionType(watcher);
11538 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
11540 if(watcher || thisClass)
11546 stmt.type = expressionStmt;
11547 stmt.expressions = MkList();
11552 // eInstance_StopWatching(object, null, watcher);
11554 ListAdd(args, CopyExpression(object));
11555 ListAdd(args, MkExpConstant("0"));
11556 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11557 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11561 for(propID = watches->first; propID; propID = propID.next)
11563 char propName[1024];
11564 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11567 char getName[1024], setName[1024];
11568 OldList * args = MkList();
11570 DeclareProperty(prop, setName, getName);
11572 // eInstance_StopWatching(object, prop, watcher);
11573 strcpy(propName, "__ecereProp_");
11574 FullClassNameCat(propName, prop._class.fullName, false);
11575 strcat(propName, "_");
11576 // strcat(propName, prop.name);
11577 FullClassNameCat(propName, prop.name, true);
11578 MangleClassName(propName);
11580 ListAdd(args, CopyExpression(object));
11581 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11582 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11583 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11586 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11591 FreeExpression(object);
11593 FreeExpression(watcher);
11594 FreeList(watches, FreeIdentifier);
11597 Compiler_Error($"Invalid object specified and not inside a class\n");
11600 Compiler_Error($"No observer specified and not inside a class\n");
11607 static void ProcessFunction(FunctionDefinition function)
11609 Identifier id = GetDeclId(function.declarator);
11610 Symbol symbol = function.declarator ? function.declarator.symbol : null;
11611 Type type = symbol ? symbol.type : null;
11612 Class oldThisClass = thisClass;
11613 Context oldTopContext = topContext;
11615 yylloc = function.loc;
11616 // Process thisClass
11618 if(type && type.thisClass)
11620 Symbol classSym = type.thisClass;
11621 Class _class = type.thisClass.registered;
11622 char className[1024];
11623 char structName[1024];
11624 Declarator funcDecl;
11627 bool typedObject = false;
11629 if(_class && !_class.base)
11631 _class = currentClass;
11632 if(_class && !_class.symbol)
11633 _class.symbol = FindClass(_class.fullName);
11634 classSym = _class ? _class.symbol : null;
11635 typedObject = true;
11638 thisClass = _class;
11640 if(inCompiler && _class)
11642 if(type.kind == functionType)
11644 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
11646 //TypeName param = symbol.type.params.first;
11647 Type param = symbol.type.params.first;
11648 symbol.type.params.Remove(param);
11649 //FreeTypeName(param);
11652 if(type.classObjectType != classPointer)
11654 symbol.type.params.Insert(null, MkClassType(_class.fullName));
11655 symbol.type.staticMethod = true;
11656 symbol.type.thisClass = null;
11658 // HIGH DANGER: VERIFYING THIS...
11659 symbol.type.extraParam = false;
11663 strcpy(className, "__ecereClass_");
11664 FullClassNameCat(className, _class.fullName, true);
11666 MangleClassName(className);
11669 FullClassNameCat(structName, _class.fullName, false);
11674 funcDecl = GetFuncDecl(function.declarator);
11677 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11679 TypeName param = funcDecl.function.parameters->first;
11680 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11682 funcDecl.function.parameters->Remove(param);
11683 FreeTypeName(param);
11687 // DANGER: Watch for this... Check if it's a Conversion?
11688 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11690 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
11691 if(!function.propertyNoThis)
11693 TypeName thisParam;
11695 if(type.classObjectType != classPointer)
11697 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11698 if(!funcDecl.function.parameters)
11699 funcDecl.function.parameters = MkList();
11700 funcDecl.function.parameters->Insert(null, thisParam);
11705 if(type.classObjectType != classPointer)
11707 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
11708 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
11711 thisParam = TypeName
11713 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11714 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11716 funcDecl.function.parameters->Insert(null, thisParam);
11721 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11723 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11724 funcDecl = GetFuncDecl(initDecl.declarator);
11727 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11729 TypeName param = funcDecl.function.parameters->first;
11730 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11732 funcDecl.function.parameters->Remove(param);
11733 FreeTypeName(param);
11737 if(type.classObjectType != classPointer)
11739 // DANGER: Watch for this... Check if it's a Conversion?
11740 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11742 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11744 if(!funcDecl.function.parameters)
11745 funcDecl.function.parameters = MkList();
11746 funcDecl.function.parameters->Insert(null, thisParam);
11753 // Add this to the context
11756 if(type.classObjectType != classPointer)
11758 thisSymbol = Symbol
11760 string = CopyString("this");
11761 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
11763 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
11765 if(typedObject && thisSymbol.type)
11767 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
11768 thisSymbol.type.byReference = type.byReference;
11770 thisSymbol = Symbol { string = CopyString("class") };
11771 function.body.compound.context.symbols.Add(thisSymbol);
11777 // Pointer to class data
11779 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
11781 DataMember member = null;
11784 for(base = _class; base && base.type != systemClass; base = base.next)
11786 for(member = base.membersAndProperties.first; member; member = member.next)
11787 if(!member.isProperty)
11793 for(member = _class.membersAndProperties.first; member; member = member.next)
11794 if(!member.isProperty)
11798 char pointerName[1024];
11801 Initializer initializer;
11802 Expression exp, bytePtr;
11804 strcpy(pointerName, "__ecerePointer_");
11805 FullClassNameCat(pointerName, _class.fullName, false);
11807 char className[1024];
11808 strcpy(className, "__ecereClass_");
11809 FullClassNameCat(className, classSym.string, true);
11810 MangleClassName(className);
11813 DeclareClass(classSym, className);
11817 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
11822 sprintf(string, "%d", _class.offset);
11823 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
11827 // ([bytePtr] + [className]->offset)
11828 exp = QBrackets(MkExpOp(bytePtr, '+',
11829 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
11832 // (this ? [exp] : 0)
11833 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
11837 kind = pointerType;
11838 type = Type { refCount = 1, kind = voidType };
11843 yylloc = function.body.loc;
11844 // ([structName] *) [exp]
11845 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
11846 initializer = MkInitializerAssignment(
11847 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
11849 // [structName] * [pointerName] = [initializer];
11850 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
11853 Context prevContext = curContext;
11854 curContext = function.body.compound.context;
11856 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
11857 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
11859 curContext = prevContext;
11863 decl.symbol = null;
11865 if(!function.body.compound.declarations)
11866 function.body.compound.declarations = MkList();
11867 function.body.compound.declarations->Insert(null, decl);
11873 // Loop through the function and replace undeclared identifiers
11874 // which are a member of the class (methods, properties or data)
11875 // by "this.[member]"
11882 FreeSpecifier(id._class);
11885 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
11887 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
11888 id = GetDeclId(initDecl.declarator);
11890 FreeSpecifier(id._class);
11895 topContext = function.body.compound.context;
11897 FunctionDefinition oldFunction = curFunction;
11898 curFunction = function;
11900 ProcessStatement(function.body);
11902 // If this is a property set and no firewatchers has been done yet, add one here
11903 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
11905 Statement prevCompound = curCompound;
11906 Context prevContext = curContext;
11908 Statement fireWatchers = MkFireWatchersStmt(null, null);
11909 if(!function.body.compound.statements) function.body.compound.statements = MkList();
11910 ListAdd(function.body.compound.statements, fireWatchers);
11912 curCompound = function.body;
11913 curContext = function.body.compound.context;
11915 ProcessStatement(fireWatchers);
11917 curContext = prevContext;
11918 curCompound = prevCompound;
11922 curFunction = oldFunction;
11925 if(function.declarator)
11927 ProcessDeclarator(function.declarator);
11930 topContext = oldTopContext;
11931 thisClass = oldThisClass;
11934 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
11935 static void ProcessClass(OldList definitions, Symbol symbol)
11938 External external = curExternal;
11939 Class regClass = symbol ? symbol.registered : null;
11941 // Process all functions
11942 for(def = definitions.first; def; def = def.next)
11944 if(def.type == functionClassDef)
11946 if(def.function.declarator)
11947 curExternal = def.function.declarator.symbol.pointerExternal;
11949 curExternal = external;
11951 ProcessFunction((FunctionDefinition)def.function);
11953 else if(def.type == declarationClassDef)
11955 if(def.decl.type == instDeclaration)
11957 thisClass = regClass;
11958 ProcessInstantiationType(def.decl.inst);
11964 Class backThisClass = thisClass;
11965 if(regClass) thisClass = regClass;
11966 ProcessDeclaration(def.decl);
11967 thisClass = backThisClass;
11970 else if(def.type == defaultPropertiesClassDef && def.defProperties)
11972 MemberInit defProperty;
11974 // Add this to the context
11975 Symbol thisSymbol = Symbol
11977 string = CopyString("this");
11978 type = regClass ? MkClassType(regClass.fullName) : null;
11980 globalContext.symbols.Add((BTNode)thisSymbol);
11982 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
11984 thisClass = regClass;
11985 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
11989 globalContext.symbols.Remove((BTNode)thisSymbol);
11990 FreeSymbol(thisSymbol);
11992 else if(def.type == propertyClassDef && def.propertyDef)
11994 PropertyDef prop = def.propertyDef;
11996 // Add this to the context
11998 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
11999 globalContext.symbols.Add(thisSymbol);
12002 thisClass = regClass;
12009 string = CopyString("this");
12010 type = MkClassType(regClass.fullName);
12012 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12015 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12016 ProcessStatement(prop.setStmt);
12024 string = CopyString("this");
12025 type = MkClassType(regClass.fullName);
12027 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12030 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12031 ProcessStatement(prop.getStmt);
12039 string = CopyString("this");
12040 type = MkClassType(regClass.fullName);
12042 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12045 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12046 ProcessStatement(prop.issetStmt);
12052 globalContext.symbols.Remove(thisSymbol);
12053 FreeSymbol(thisSymbol);
12056 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12058 PropertyWatch propertyWatch = def.propertyWatch;
12060 thisClass = regClass;
12061 if(propertyWatch.compound)
12065 string = CopyString("this");
12066 type = regClass ? MkClassType(regClass.fullName) : null;
12069 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12071 curExternal = null;
12072 ProcessStatement(propertyWatch.compound);
12079 void DeclareFunctionUtil(String s)
12081 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12086 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12087 strcpy(name, "__ecereFunction_");
12088 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12089 DeclareFunction(function, name);
12093 void ComputeDataTypes()
12097 External after = null;
12099 currentClass = null;
12101 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12103 for(external = ast->first; external; external = external.next)
12105 if(external.type == declarationExternal)
12107 Declaration decl = external.declaration;
12110 OldList * decls = decl.declarators;
12113 InitDeclarator initDecl = decls->first;
12116 Declarator declarator = initDecl.declarator;
12117 if(declarator && declarator.type == identifierDeclarator)
12119 Identifier id = declarator.identifier;
12120 if(id && id.string)
12122 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12124 external.symbol.id = -1001, external.symbol.idCode = -1001;
12135 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12136 ast->Insert(after, temp);
12137 curExternal = temp;
12139 DeclareFunctionUtil("eSystem_New");
12140 DeclareFunctionUtil("eSystem_New0");
12141 DeclareFunctionUtil("eSystem_Renew");
12142 DeclareFunctionUtil("eSystem_Renew0");
12143 DeclareFunctionUtil("eClass_GetProperty");
12145 DeclareStruct("ecere::com::Class", false);
12146 DeclareStruct("ecere::com::Instance", false);
12147 DeclareStruct("ecere::com::Property", false);
12148 DeclareStruct("ecere::com::DataMember", false);
12149 DeclareStruct("ecere::com::Method", false);
12150 DeclareStruct("ecere::com::SerialBuffer", false);
12151 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12155 for(external = ast->first; external; external = external.next)
12157 afterExternal = curExternal = external;
12158 if(external.type == functionExternal)
12160 currentClass = external.function._class;
12161 ProcessFunction(external.function);
12163 // There shouldn't be any _class member access here anyways...
12164 else if(external.type == declarationExternal)
12166 currentClass = null;
12167 ProcessDeclaration(external.declaration);
12169 else if(external.type == classExternal)
12171 ClassDefinition _class = external._class;
12172 currentClass = external.symbol.registered;
12173 if(_class.definitions)
12175 ProcessClass(_class.definitions, _class.symbol);
12179 // Free class data...
12180 ast->Remove(external);
12184 else if(external.type == nameSpaceExternal)
12186 thisNameSpace = external.id.string;
12189 currentClass = null;
12190 thisNameSpace = null;
12192 delete temp.symbol;