4 #include <stdlib.h> // For strtoll
7 // UNTIL IMPLEMENTED IN GRAMMAR
8 #define ACCESS_CLASSDATA(_class, baseClass) \
9 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
11 #define YYLTYPE Location
15 extern int returnCode;
16 extern Expression parsedExpression;
18 public void SetYydebug(bool b) { yydebug = b; }
23 // TODO: Reset this to 0 on reinitialization
26 int expression_yyparse();
27 static Statement curCompound;
28 External curExternal, afterExternal;
29 static Type curSwitchType;
30 static Class currentClass;
32 public void SetThisClass(Class c) { thisClass = c; } public Class GetThisClass() { return thisClass; }
33 static char * thisNameSpace;
34 /*static */Class containerClass;
35 bool thisClassParams = true;
37 uint internalValueCounter;
40 Time findSymbolTotalTime;
43 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
44 /*static */public void PrintExpression(Expression exp, char * string)
52 OutputExpression(exp, f);
54 count = strlen(string);
55 count += f.Read(string + count, 1, 1023);
61 Type ProcessTemplateParameterType(TemplateParameter param)
63 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
65 // TOFIX: Will need to free this Type
68 if(param.dataTypeString)
69 param.baseType = ProcessTypeString(param.dataTypeString, false);
71 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
73 return param.baseType;
78 bool NeedCast(Type type1, Type type2)
80 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
82 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
87 if(type1.kind == type2.kind)
98 if(type1.passAsTemplate && !type2.passAsTemplate)
100 return type1.isSigned != type2.isSigned;
102 return type1._class != type2._class;
104 return NeedCast(type1.type, type2.type);
106 return true; //false; ????
112 static void ReplaceClassMembers(Expression exp, Class _class)
114 if(exp.type == identifierExp && exp.identifier)
116 Identifier id = exp.identifier;
118 Symbol symbol = null;
119 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
121 // First, check if the identifier is declared inside the function
122 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
124 symbol = (Symbol)ctx.symbols.FindString(id.string);
129 // If it is not, check if it is a member of the _class
130 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
132 Property prop = eClass_FindProperty(_class, id.string, privateModule);
133 Method method = null;
134 DataMember member = null;
135 ClassProperty classProp = null;
138 method = eClass_FindMethod(_class, id.string, privateModule);
141 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
142 if(!prop && !method && !member)
144 classProp = eClass_FindClassProperty(_class, id.string);
146 if(prop || method || member || classProp)
148 // Replace by this.[member]
149 exp.type = memberExp;
150 exp.member.member = id;
151 exp.member.memberType = unresolvedMember;
152 exp.member.exp = QMkExpId("this");
153 //exp.member.exp.loc = exp.loc;
154 exp.addedThis = true;
156 else if(_class && _class.templateParams.first)
159 for(sClass = _class; sClass; sClass = sClass.base)
161 if(sClass.templateParams.first)
163 ClassTemplateParameter param;
164 for(param = sClass.templateParams.first; param; param = param.next)
166 if(param.type == expression && !strcmp(param.name, id.string))
168 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
173 OldList * specs = MkList();
175 FreeIdentifier(exp.member.member);
177 ProcessExpressionType(argExp);
179 decl = SpecDeclFromString(param.dataTypeString, specs, null);
181 exp.expType = ProcessType(specs, decl);
183 // *[expType] *[argExp]
184 exp.type = bracketsExp;
185 exp.list = MkListOne(MkExpOp(null, '*',
186 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
197 ////////////////////////////////////////////////////////////////////////
198 // PRINTING ////////////////////////////////////////////////////////////
199 ////////////////////////////////////////////////////////////////////////
201 public char * PrintInt(int64 result)
204 if(result > MAXINT64)
205 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
207 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
208 return CopyString(temp);
211 public char * PrintUInt(uint64 result)
214 if(result > MAXDWORD)
215 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
216 else if(result > MAXINT)
217 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
219 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
220 return CopyString(temp);
223 public char * PrintInt64(int64 result)
226 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
227 return CopyString(temp);
230 public char * PrintUInt64(uint64 result)
233 if(result > MAXINT64)
234 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
236 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
237 return CopyString(temp);
240 public char * PrintHexUInt(uint64 result)
243 if(result > MAXDWORD)
244 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
246 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
247 return CopyString(temp);
250 public char * PrintHexUInt64(uint64 result)
253 if(result > MAXDWORD)
254 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
256 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
257 return CopyString(temp);
260 public char * PrintShort(short result)
263 sprintf(temp, "%d", (unsigned short)result);
264 return CopyString(temp);
267 public char * PrintUShort(unsigned short result)
271 sprintf(temp, "0x%X", (int)result);
273 sprintf(temp, "%d", (int)result);
274 return CopyString(temp);
277 public char * PrintChar(char result)
280 if(result > 0 && isprint(result))
281 sprintf(temp, "'%c'", result);
283 sprintf(temp, "%d", (int)result);
285 //sprintf(temp, "%#X", result);
286 sprintf(temp, "0x%X", (unsigned char)result);
287 return CopyString(temp);
290 public char * PrintUChar(unsigned char result)
293 sprintf(temp, "0x%X", result);
294 return CopyString(temp);
297 public char * PrintFloat(float result)
300 sprintf(temp, "%.16ff", result);
301 return CopyString(temp);
304 public char * PrintDouble(double result)
307 sprintf(temp, "%.16f", result);
308 return CopyString(temp);
311 ////////////////////////////////////////////////////////////////////////
312 ////////////////////////////////////////////////////////////////////////
314 //public Operand GetOperand(Expression exp);
316 #define GETVALUE(name, t) \
317 public bool Get##name(Expression exp, t * value2) \
319 Operand op2 = GetOperand(exp); \
320 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
321 else if(op2.kind == intType) *value2 = (t) op2.ui; \
322 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
323 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
324 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
325 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
326 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
327 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
328 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
329 else if(op2.kind == shortType) *value2 = (t) op2.us; \
330 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
331 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
332 else if(op2.kind == floatType) *value2 = (t) op2.f; \
333 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
334 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
340 // To help the deubugger currently not preprocessing...
343 GETVALUE(Int, HELP(int));
344 GETVALUE(UInt, HELP(unsigned int));
345 GETVALUE(Int64, HELP(int64));
346 GETVALUE(UInt64, HELP(uint64));
347 GETVALUE(IntPtr, HELP(intptr));
348 GETVALUE(UIntPtr, HELP(uintptr));
349 GETVALUE(IntSize, HELP(intsize));
350 GETVALUE(UIntSize, HELP(uintsize));
351 GETVALUE(Short, HELP(short));
352 GETVALUE(UShort, HELP(unsigned short));
353 GETVALUE(Char, HELP(char));
354 GETVALUE(UChar, HELP(unsigned char));
355 GETVALUE(Float, HELP(float));
356 GETVALUE(Double, HELP(double));
358 void ComputeExpression(Expression exp);
360 void ComputeClassMembers(Class _class, bool isMember)
362 DataMember member = isMember ? (DataMember) _class : null;
363 Context context = isMember ? null : SetupTemplatesContext(_class);
364 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
365 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
368 int unionMemberOffset = 0;
372 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
373 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
378 member.memberOffset = 0;
379 if(targetBits < sizeof(void *) * 8)
380 member.structAlignment = 0;
382 else if(targetBits < sizeof(void *) * 8)
383 _class.structAlignment = 0;
385 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
386 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
387 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
389 if(!member && _class.destructionWatchOffset)
390 _class.memberOffset += sizeof(OldList);
392 // To avoid reentrancy...
393 //_class.structSize = -1;
396 DataMember dataMember;
397 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
399 if(!dataMember.isProperty)
401 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
403 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
404 /*if(!dataMember.dataType)
405 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
413 DataMember dataMember;
414 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
416 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
418 if(!isMember && _class.type == bitClass && dataMember.dataType)
420 BitMember bitMember = (BitMember) dataMember;
424 ComputeTypeSize(dataMember.dataType);
426 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
427 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
429 _class.memberOffset = bitMember.pos + bitMember.size;
430 for(d = 0; d<bitMember.size; d++)
436 bitMember.mask = mask << bitMember.pos;
438 else if(dataMember.type == normalMember && dataMember.dataType)
443 // Prevent infinite recursion
444 if(dataMember.dataType.kind != classType ||
445 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
446 _class.type != structClass)))
447 ComputeTypeSize(dataMember.dataType);
449 if(dataMember.dataType.bitFieldCount)
451 bitFields += dataMember.dataType.bitFieldCount;
458 int size = (bitFields + 7) / 8;
462 // TESTING THIS PADDING CODE
465 member.structAlignment = Max(member.structAlignment, alignment);
467 if(member.memberOffset % alignment)
468 member.memberOffset += alignment - (member.memberOffset % alignment);
471 dataMember.offset = member.memberOffset;
472 if(member.type == unionMember)
473 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
476 member.memberOffset += size;
481 // TESTING THIS PADDING CODE
484 _class.structAlignment = Max(_class.structAlignment, alignment);
486 if(_class.memberOffset % alignment)
487 _class.memberOffset += alignment - (_class.memberOffset % alignment);
490 dataMember.offset = _class.memberOffset;
491 _class.memberOffset += size;
495 size = dataMember.dataType.size;
496 alignment = dataMember.dataType.alignment;
501 // TESTING THIS PADDING CODE
504 member.structAlignment = Max(member.structAlignment, alignment);
506 if(member.memberOffset % alignment)
507 member.memberOffset += alignment - (member.memberOffset % alignment);
510 dataMember.offset = member.memberOffset;
511 if(member.type == unionMember)
512 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
515 member.memberOffset += size;
520 // TESTING THIS PADDING CODE
523 _class.structAlignment = Max(_class.structAlignment, alignment);
525 if(_class.memberOffset % alignment)
526 _class.memberOffset += alignment - (_class.memberOffset % alignment);
529 dataMember.offset = _class.memberOffset;
530 _class.memberOffset += size;
537 ComputeClassMembers((Class)dataMember, true);
538 alignment = dataMember.structAlignment;
544 if(member.memberOffset % alignment)
545 member.memberOffset += alignment - (member.memberOffset % alignment);
547 member.structAlignment = Max(member.structAlignment, alignment);
549 dataMember.offset = member.memberOffset;
550 if(member.type == unionMember)
551 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
553 member.memberOffset += dataMember.memberOffset;
559 if(_class.memberOffset % alignment)
560 _class.memberOffset += alignment - (_class.memberOffset % alignment);
561 _class.structAlignment = Max(_class.structAlignment, alignment);
563 dataMember.offset = _class.memberOffset;
564 _class.memberOffset += dataMember.memberOffset;
572 int size = (bitFields + 7) / 8;
576 // TESTING THIS PADDING CODE
579 member.structAlignment = Max(member.structAlignment, alignment);
581 if(member.memberOffset % alignment)
582 member.memberOffset += alignment - (member.memberOffset % alignment);
585 if(member.type == unionMember)
586 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
589 member.memberOffset += size;
594 // TESTING THIS PADDING CODE
597 _class.structAlignment = Max(_class.structAlignment, alignment);
599 if(_class.memberOffset % alignment)
600 _class.memberOffset += alignment - (_class.memberOffset % alignment);
602 _class.memberOffset += size;
607 if(member && member.type == unionMember)
609 member.memberOffset = unionMemberOffset;
614 /*if(_class.type == structClass)
615 _class.size = _class.memberOffset;
619 if(_class.type != bitClass)
622 if(_class.structAlignment)
624 if(_class.memberOffset % _class.structAlignment)
625 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
627 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
631 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
633 if(prop.isProperty && prop.isWatchable)
635 prop.watcherOffset = _class.structSize;
636 _class.structSize += sizeof(OldList);
644 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
646 Class deriv = derivative.data;
648 if(deriv.computeSize)
650 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
651 deriv.offset = /*_class.offset + */_class.structSize;
652 deriv.memberOffset = 0;
653 // ----------------------
655 deriv.structSize = deriv.offset;
657 ComputeClassMembers(deriv, false);
665 FinishTemplatesContext(context);
668 public void ComputeModuleClasses(Module module)
673 for(subModule = module.modules.first; subModule; subModule = subModule.next)
674 ComputeModuleClasses(subModule.data);
675 for(_class = module.classes.first; _class; _class = _class.next)
676 ComputeClassMembers(_class, false);
680 public int ComputeTypeSize(Type type)
682 uint size = type ? type.size : 0;
683 if(!size && type && !type.computing)
685 type.computing = true;
688 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
689 case charType: type.alignment = size = sizeof(char); break;
690 case intType: type.alignment = size = sizeof(int); break;
691 case int64Type: type.alignment = size = sizeof(int64); break;
692 case intPtrType: type.alignment = size = targetBits / 8; break;
693 case intSizeType: type.alignment = size = targetBits / 8; break;
694 case longType: type.alignment = size = sizeof(long); break;
695 case shortType: type.alignment = size = sizeof(short); break;
696 case floatType: type.alignment = size = sizeof(float); break;
697 case doubleType: type.alignment = size = sizeof(double); break;
700 Class _class = type._class ? type._class.registered : null;
702 if(_class && _class.type == structClass)
704 // Ensure all members are properly registered
705 ComputeClassMembers(_class, false);
706 type.alignment = _class.structAlignment;
707 size = _class.structSize;
708 if(type.alignment && size % type.alignment)
709 size += type.alignment - (size % type.alignment);
712 else if(_class && (_class.type == unitClass ||
713 _class.type == enumClass ||
714 _class.type == bitClass))
717 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
718 size = type.alignment = ComputeTypeSize(_class.dataType);
721 size = type.alignment = targetBits / 8; // sizeof(Instance *);
724 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
726 if(type.arraySizeExp)
728 ProcessExpressionType(type.arraySizeExp);
729 ComputeExpression(type.arraySizeExp);
730 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType && type.arraySizeExp.expType.kind != enumType &&
731 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
733 Location oldLoc = yylloc;
734 // bool isConstant = type.arraySizeExp.isConstant;
735 char expression[10240];
736 expression[0] = '\0';
737 type.arraySizeExp.expType = null;
738 yylloc = type.arraySizeExp.loc;
740 PrintExpression(type.arraySizeExp, expression);
741 Compiler_Error($"Array size not constant int (%s)\n", expression);
744 GetInt(type.arraySizeExp, &type.arraySize);
746 else if(type.enumClass)
748 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
750 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
757 // Unimplemented auto size
761 size = ComputeTypeSize(type.type) * type.arraySize;
763 type.alignment = type.type.alignment;
769 for(member = type.members.first; member; member = member.next)
771 uint addSize = ComputeTypeSize(member);
773 member.offset = size;
774 if(member.alignment && size % member.alignment)
775 member.offset += member.alignment - (size % member.alignment);
776 size = member.offset;
778 type.alignment = Max(type.alignment, member.alignment);
781 if(type.alignment && size % type.alignment)
782 size += type.alignment - (size % type.alignment);
788 for(member = type.members.first; member; member = member.next)
790 uint addSize = ComputeTypeSize(member);
792 member.offset = size;
793 if(member.alignment && size % member.alignment)
794 member.offset += member.alignment - (size % member.alignment);
795 size = member.offset;
797 type.alignment = Max(type.alignment, member.alignment);
798 size = Max(size, addSize);
800 if(type.alignment && size % type.alignment)
801 size += type.alignment - (size % type.alignment);
806 TemplateParameter param = type.templateParameter;
807 Type baseType = ProcessTemplateParameterType(param);
810 size = ComputeTypeSize(baseType);
811 type.alignment = baseType.alignment;
814 type.alignment = size = sizeof(uint64);
819 type.alignment = size = sizeof(enum { test });
824 type.alignment = size = targetBits / 8; //sizeof(void *);
829 type.computing = false;
835 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
837 // This function is in need of a major review when implementing private members etc.
838 DataMember topMember = isMember ? (DataMember) _class : null;
843 Context context = isMember ? null : SetupTemplatesContext(_class);
845 *addedPadding = false;
847 if(!isMember && _class.base)
849 maxSize = _class.structSize;
850 //if(_class.base.type != systemClass) // Commented out with new Instance _class
852 // DANGER: Testing this noHeadClass here...
853 if(_class.type == structClass || _class.type == noHeadClass)
854 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
857 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
858 if(maxSize > baseSize)
866 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
868 if(!member.isProperty)
874 if(member.dataTypeString)
876 OldList * specs = MkList(), * decls = MkList();
879 decl = SpecDeclFromString(member.dataTypeString, specs,
880 MkDeclaratorIdentifier(MkIdentifier(member.name)));
881 ListAdd(decls, MkStructDeclarator(decl, null));
882 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
885 member.dataType = ProcessType(specs, decl);
887 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
890 Type type = ProcessType(specs, decl);
891 DeclareType(member.dataType, false, false);
895 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
896 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
897 DeclareStruct(member.dataType._class.string, false);
900 ComputeTypeSize(member.dataType);
901 size = member.dataType.size;
902 alignment = member.dataType.alignment;
906 if(totalSize % alignment)
907 totalSize += alignment - (totalSize % alignment);
916 OldList * specs = MkList(), * list = MkList();
919 AddMembers(list, (Class)member, true, &size, topClass, null);
921 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
922 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
923 alignment = member.structAlignment;
927 if(totalSize % alignment)
928 totalSize += alignment - (totalSize % alignment);
938 if(topMember && topMember.type == unionMember)
939 *retSize = Max(*retSize, totalSize);
941 *retSize += totalSize;
943 else if(totalSize < maxSize && _class.type != systemClass)
946 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
947 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
948 if(totalSize + autoPadding < maxSize)
951 sprintf(sizeString, "%d", maxSize - totalSize);
952 ListAdd(declarations,
953 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
954 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
956 *addedPadding = true;
960 FinishTemplatesContext(context);
961 return topMember ? topMember.memberID : _class.memberID;
964 static int DeclareMembers(Class _class, bool isMember)
966 DataMember topMember = isMember ? (DataMember) _class : null;
969 Context context = isMember ? null : SetupTemplatesContext(_class);
971 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
972 DeclareMembers(_class.base, false);
974 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
976 if(!member.isProperty)
983 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
984 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
985 DeclareStruct(member.dataType._class.string, false);
987 if(!member.dataType && member.dataTypeString)
988 member.dataType = ProcessTypeString(member.dataTypeString, false);
990 DeclareType(member.dataType, false, false);
996 DeclareMembers((Class)member, true);
1003 FinishTemplatesContext(context);
1005 return topMember ? topMember.memberID : _class.memberID;
1008 void DeclareStruct(char * name, bool skipNoHead)
1010 External external = null;
1011 Symbol classSym = FindClass(name);
1013 if(!inCompiler || !classSym) return;
1015 // We don't need any declaration for bit classes...
1016 if(classSym.registered &&
1017 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1020 /*if(classSym.registered.templateClass)
1021 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1024 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1026 // Add typedef struct
1028 OldList * specifiers, * declarators;
1029 OldList * declarations = null;
1030 char structName[1024];
1031 external = (classSym.registered && classSym.registered.type == structClass) ?
1032 classSym.pointerExternal : classSym.structExternal;
1034 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1035 // Moved this one up because DeclareClass done later will need it
1037 classSym.declaring++;
1039 if(strchr(classSym.string, '<'))
1041 if(classSym.registered.templateClass)
1043 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1044 classSym.declaring--;
1050 DeclareMembers(classSym.registered, false);
1053 FullClassNameCat(structName, name, false);
1056 external = MkExternalDeclaration(null);*/
1060 bool addedPadding = false;
1061 classSym.declaredStructSym = true;
1063 declarations = MkList();
1065 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1067 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1068 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1070 if(!declarations->count || (declarations->count == 1 && addedPadding))
1072 FreeList(declarations, FreeClassDef);
1073 declarations = null;
1076 if(skipNoHead || declarations)
1078 if(external && external.declaration)
1080 ((Specifier)external.declaration.specifiers->first).definitions = declarations;
1082 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1085 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1088 if(classSym.structExternal)
1089 ast->Move(classSym.structExternal, curExternal.prev);
1090 ast->Move(classSym.pointerExternal, curExternal.prev);
1092 classSym.id = curExternal.symbol.idCode;
1093 classSym.idCode = curExternal.symbol.idCode;
1094 // external = classSym.pointerExternal;
1095 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1101 external = MkExternalDeclaration(null);
1103 specifiers = MkList();
1104 declarators = MkList();
1105 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1108 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1109 ListAdd(declarators, MkInitDeclarator(d, null));
1111 external.declaration = decl = MkDeclaration(specifiers, declarators);
1112 if(decl.symbol && !decl.symbol.pointerExternal)
1113 decl.symbol.pointerExternal = external;
1115 // For simple classes, keep the declaration as the external to move around
1116 if(classSym.registered && classSym.registered.type == structClass)
1118 char className[1024];
1119 strcpy(className, "__ecereClass_");
1120 FullClassNameCat(className, classSym.string, true);
1121 MangleClassName(className);
1124 DeclareClass(classSym, className);
1126 external.symbol = classSym;
1127 classSym.pointerExternal = external;
1128 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1129 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1133 char className[1024];
1134 strcpy(className, "__ecereClass_");
1135 FullClassNameCat(className, classSym.string, true);
1136 MangleClassName(className);
1138 // TOFIX: TESTING THIS...
1139 classSym.structExternal = external;
1140 DeclareClass(classSym, className);
1141 external.symbol = classSym;
1145 ast->Insert(curExternal ? curExternal.prev : null, external);
1149 classSym.declaring--;
1151 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1153 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1154 // Moved this one up because DeclareClass done later will need it
1157 classSym.declaring++;
1161 if(classSym.registered)
1162 DeclareMembers(classSym.registered, false);
1165 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1168 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1171 if(classSym.structExternal)
1172 ast->Move(classSym.structExternal, curExternal.prev);
1173 ast->Move(classSym.pointerExternal, curExternal.prev);
1175 classSym.id = curExternal.symbol.idCode;
1176 classSym.idCode = curExternal.symbol.idCode;
1177 // external = classSym.pointerExternal;
1178 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1181 classSym.declaring--;
1186 void DeclareProperty(Property prop, char * setName, char * getName)
1188 Symbol symbol = prop.symbol;
1189 char propName[1024];
1191 strcpy(setName, "__ecereProp_");
1192 FullClassNameCat(setName, prop._class.fullName, false);
1193 strcat(setName, "_Set_");
1194 // strcat(setName, prop.name);
1195 FullClassNameCat(setName, prop.name, true);
1197 strcpy(getName, "__ecereProp_");
1198 FullClassNameCat(getName, prop._class.fullName, false);
1199 strcat(getName, "_Get_");
1200 FullClassNameCat(getName, prop.name, true);
1201 // strcat(getName, prop.name);
1203 strcpy(propName, "__ecereProp_");
1204 FullClassNameCat(propName, prop._class.fullName, false);
1205 strcat(propName, "_");
1206 FullClassNameCat(propName, prop.name, true);
1207 // strcat(propName, prop.name);
1209 // To support "char *" property
1210 MangleClassName(getName);
1211 MangleClassName(setName);
1212 MangleClassName(propName);
1214 if(prop._class.type == structClass)
1215 DeclareStruct(prop._class.fullName, false);
1217 if(!symbol || curExternal.symbol.idCode < symbol.id)
1219 bool imported = false;
1220 bool dllImport = false;
1221 if(!symbol || symbol._import)
1226 if(!prop._class.symbol)
1227 prop._class.symbol = FindClass(prop._class.fullName);
1228 classSym = prop._class.symbol;
1229 if(classSym && !classSym._import)
1231 ModuleImport module;
1233 if(prop._class.module)
1234 module = FindModule(prop._class.module);
1236 module = mainModule;
1238 classSym._import = ClassImport
1240 name = CopyString(prop._class.fullName);
1241 isRemote = prop._class.isRemote;
1243 module.classes.Add(classSym._import);
1245 symbol = prop.symbol = Symbol { };
1246 symbol._import = (ClassImport)PropertyImport
1248 name = CopyString(prop.name);
1249 isVirtual = false; //prop.isVirtual;
1250 hasSet = prop.Set ? true : false;
1251 hasGet = prop.Get ? true : false;
1254 classSym._import.properties.Add(symbol._import);
1257 if(prop._class.module != privateModule && prop._class.module.importType != staticImport)
1263 Context context = SetupTemplatesContext(prop._class);
1264 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1265 FinishTemplatesContext(context);
1271 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1274 OldList * specifiers, * declarators;
1279 Declarator typeDecl;
1280 bool simple = false;
1282 specifiers = MkList();
1283 declarators = MkList();
1286 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1287 MkDeclaratorIdentifier(MkIdentifier("this"))));
1289 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1292 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1295 Context context = SetupTemplatesContext(prop._class);
1296 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1297 FinishTemplatesContext(context);
1300 // Make sure the simple _class's type is declared
1301 for(spec = specifiers->first; spec; spec = spec.next)
1303 if(spec.type == nameSpecifier /*SpecifierClass*/)
1305 if((!typeDecl || typeDecl.type == identifierDeclarator))
1307 Symbol classSym = spec.symbol; // FindClass(spec.name);
1308 symbol._class = classSym.registered;
1309 if(classSym.registered && classSym.registered.type == structClass)
1311 DeclareStruct(spec.name, false);
1319 d = PlugDeclarator(typeDecl, d);
1322 ListAdd(params, MkTypeName(specifiers,
1323 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1324 specifiers = MkList();
1327 d = MkDeclaratorFunction(d, params);
1331 specifiers->Insert(null, MkSpecifier(EXTERN));
1332 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1333 specifiers->Insert(null, MkSpecifier(STATIC));
1335 ListAdd(specifiers, MkSpecifier(VOID));
1337 ListAdd(declarators, MkInitDeclarator(d, null));
1339 decl = MkDeclaration(specifiers, declarators);
1341 external = MkExternalDeclaration(decl);
1342 ast->Insert(curExternal.prev, external);
1343 external.symbol = symbol;
1344 symbol.externalGet = external;
1346 ReplaceThisClassSpecifiers(specifiers, prop._class);
1349 FreeDeclarator(typeDecl);
1353 // Move declaration higher...
1354 ast->Move(symbol.externalGet, curExternal.prev);
1361 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1364 OldList * specifiers, * declarators;
1369 Declarator typeDecl;
1371 declarators = MkList();
1374 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1375 if(!prop.conversion || prop._class.type == structClass)
1377 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1378 MkDeclaratorIdentifier(MkIdentifier("this"))));
1381 specifiers = MkList();
1384 Context context = SetupTemplatesContext(prop._class);
1385 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1386 MkDeclaratorIdentifier(MkIdentifier("value")));
1387 FinishTemplatesContext(context);
1389 ListAdd(params, MkTypeName(specifiers, d));
1391 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1394 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1395 d = MkDeclaratorFunction(d, params);
1397 // Make sure the simple _class's type is declared
1398 for(spec = specifiers->first; spec; spec = spec.next)
1400 if(spec.type == nameSpecifier /*SpecifierClass*/)
1402 if((!typeDecl || typeDecl.type == identifierDeclarator))
1404 Symbol classSym = spec.symbol; // FindClass(spec.name);
1405 symbol._class = classSym.registered;
1406 if(classSym.registered && classSym.registered.type == structClass)
1407 DeclareStruct(spec.name, false);
1412 ListAdd(declarators, MkInitDeclarator(d, null));
1414 specifiers = MkList();
1417 specifiers->Insert(null, MkSpecifier(EXTERN));
1418 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1419 specifiers->Insert(null, MkSpecifier(STATIC));
1421 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1422 if(!prop.conversion || prop._class.type == structClass)
1423 ListAdd(specifiers, MkSpecifier(VOID));
1425 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1427 decl = MkDeclaration(specifiers, declarators);
1429 external = MkExternalDeclaration(decl);
1430 ast->Insert(curExternal.prev, external);
1431 external.symbol = symbol;
1432 symbol.externalSet = external;
1434 ReplaceThisClassSpecifiers(specifiers, prop._class);
1438 // Move declaration higher...
1439 ast->Move(symbol.externalSet, curExternal.prev);
1443 // Property (for Watchers)
1444 if(!symbol.externalPtr)
1448 OldList * specifiers = MkList();
1451 specifiers->Insert(null, MkSpecifier(EXTERN));
1453 specifiers->Insert(null, MkSpecifier(STATIC));
1455 ListAdd(specifiers, MkSpecifierName("Property"));
1458 OldList * list = MkList();
1459 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1460 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1464 strcpy(propName, "__ecerePropM_");
1465 FullClassNameCat(propName, prop._class.fullName, false);
1466 strcat(propName, "_");
1467 // strcat(propName, prop.name);
1468 FullClassNameCat(propName, prop.name, true);
1470 MangleClassName(propName);
1472 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1473 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1475 decl = MkDeclaration(specifiers, list);
1478 external = MkExternalDeclaration(decl);
1479 ast->Insert(curExternal.prev, external);
1480 external.symbol = symbol;
1481 symbol.externalPtr = external;
1485 // Move declaration higher...
1486 ast->Move(symbol.externalPtr, curExternal.prev);
1489 symbol.id = curExternal.symbol.idCode;
1493 // ***************** EXPRESSION PROCESSING ***************************
1494 public Type Dereference(Type source)
1499 if(source.kind == pointerType || source.kind == arrayType)
1502 source.type.refCount++;
1504 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1512 // Support dereferencing of no head classes for now...
1513 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1519 Compiler_Error($"cannot dereference type\n");
1524 static Type Reference(Type source)
1540 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1542 Identifier ident = member.identifiers ? member.identifiers->first : null;
1544 DataMember dataMember = null;
1545 Method method = null;
1546 bool freeType = false;
1548 yylloc = member.loc;
1554 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1558 dataMember = *curMember;
1564 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1565 DataMember _subMemberStack[256];
1566 int _subMemberStackPos = 0;
1568 // FILL MEMBER STACK
1570 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1573 dataMember = thisMember;
1574 if(curMember && thisMember.memberAccess == publicAccess)
1576 *curMember = thisMember;
1577 *curClass = thisMember._class;
1578 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1579 *subMemberStackPos = _subMemberStackPos;
1586 method = eClass_FindMethod(_class, ident.string, privateModule);
1587 if(method && method.type == virtualMethod)
1599 if(!dataMember.dataType && dataMember.dataTypeString)
1601 //Context context = SetupTemplatesContext(dataMember._class);
1602 Context context = SetupTemplatesContext(_class);
1603 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1604 FinishTemplatesContext(context);
1606 type = dataMember.dataType;
1610 // This is for destination type...
1611 if(!method.dataType)
1612 ProcessMethodType(method);
1613 //DeclareMethod(method);
1614 // method.dataType = ((Symbol)method.symbol)->type;
1615 type = method.dataType;
1618 if(ident && ident.next)
1620 for(ident = ident.next; ident && type; ident = ident.next)
1622 if(type.kind == classType)
1624 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1626 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1628 type = dataMember.dataType;
1630 else if(type.kind == structType || type.kind == unionType)
1633 for(memberType = type.members.first; memberType; memberType = memberType.next)
1635 if(!strcmp(memberType.name, ident.string))
1645 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1646 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1649 ClassTemplateParameter curParam = null;
1651 for(sClass = _class; sClass; sClass = sClass.base)
1654 if(sClass.templateClass) sClass = sClass.templateClass;
1655 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1657 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1659 for(sClass = sClass.base; sClass; sClass = sClass.base)
1661 if(sClass.templateClass) sClass = sClass.templateClass;
1662 id += sClass.templateParams.count;
1673 ClassTemplateArgument arg = _class.templateArgs[id];
1674 if(arg.dataTypeString)
1677 type = ProcessTypeString(arg.dataTypeString, false);
1679 if(type && _class.templateClass)
1680 type.passAsTemplate = true;
1686 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1687 exp.destType.refCount++;
1693 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1695 Class expClass = type._class.registered;
1696 Class cClass = null;
1701 char templateString[1024];
1702 ClassTemplateParameter param;
1703 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1704 for(cClass = expClass; cClass; cClass = cClass.base)
1707 if(cClass.templateClass) cClass = cClass.templateClass;
1708 for(param = cClass.templateParams.first; param; param = param.next)
1712 ClassTemplateArgument arg;
1713 for(sClass = cClass.base; sClass; sClass = sClass.base)
1715 if(sClass.templateClass) sClass = sClass.templateClass;
1716 id += sClass.templateParams.count;
1718 arg = expClass.templateArgs[id];
1720 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1722 ClassTemplateParameter cParam;
1723 //int p = numParams - sClass.templateParams.count;
1726 if(sClass.templateClass) sClass = sClass.templateClass;
1728 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1730 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1731 p += nextClass.templateParams.count;
1734 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1736 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1738 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1740 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1741 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1753 strcat(argument, arg.name.string);
1754 strcat(argument, " = ");
1760 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1761 char expString[1024];
1762 OldList * specs = MkList();
1763 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1765 char * string = PrintHexUInt64(arg.expression.ui64);
1766 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1769 ProcessExpressionType(exp);
1770 ComputeExpression(exp);
1771 expString[0] = '\0';
1772 PrintExpression(exp, expString);
1773 strcat(argument, expString);
1775 FreeExpression(exp);
1780 strcat(argument, arg.member.name);
1783 case TemplateParameterType::type:
1785 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1786 strcat(argument, arg.dataTypeString);
1792 if(paramCount) strcat(templateString, ", ");
1793 if(lastParam != p - 1)
1795 strcat(templateString, param.name);
1796 strcat(templateString, " = ");
1798 strcat(templateString, argument);
1807 int len = strlen(templateString);
1808 if(templateString[len-1] == '<')
1812 if(templateString[len-1] == '>')
1813 templateString[len++] = ' ';
1814 templateString[len++] = '>';
1816 templateString[len++] = '\0';
1819 Context context = SetupTemplatesContext(_class);
1820 if(freeType) FreeType(type);
1821 type = ProcessTypeString(templateString, false);
1823 FinishTemplatesContext(context);
1827 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1829 ProcessExpressionType(member.initializer.exp);
1830 if(!member.initializer.exp.expType)
1834 char expString[10240];
1835 expString[0] = '\0';
1836 PrintExpression(member.initializer.exp, expString);
1837 ChangeCh(expString, '\n', ' ');
1838 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1841 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1842 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1844 Compiler_Error($"incompatible instance method %s\n", ident.string);
1847 else if(member.initializer)
1850 FreeType(member.exp.destType);
1851 member.exp.destType = type;
1852 if(member.exp.destType)
1853 member.exp.destType.refCount++;
1854 ProcessExpressionType(member.exp);
1857 ProcessInitializer(member.initializer, type);
1859 if(freeType) FreeType(type);
1863 if(_class && _class.type == unitClass)
1865 if(member.initializer)
1868 FreeType(member.exp.destType);
1869 member.exp.destType = MkClassType(_class.fullName);
1870 ProcessExpressionType(member.initializer, type);
1872 Type type = MkClassType(_class.fullName);
1873 ProcessInitializer(member.initializer, type);
1879 if(member.initializer)
1881 //ProcessExpressionType(member.exp);
1882 ProcessInitializer(member.initializer, null);
1888 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1892 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1894 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1898 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1903 void ProcessInstantiationType(Instantiation inst)
1908 MembersInit members;
1909 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1912 /*if(!inst._class.symbol)
1913 inst._class.symbol = FindClass(inst._class.name);*/
1914 classSym = inst._class.symbol;
1915 _class = classSym ? classSym.registered : null;
1917 // DANGER: Patch for mutex not declaring its struct when not needed
1918 if(!_class || _class.type != noHeadClass)
1919 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1921 afterExternal = afterExternal ? afterExternal : curExternal;
1924 ProcessExpressionType(inst.exp);
1926 inst.isConstant = true;
1929 DataMember curMember = null;
1930 Class curClass = null;
1931 DataMember subMemberStack[256];
1932 int subMemberStackPos = 0;
1934 for(members = inst.members->first; members; members = members.next)
1936 switch(members.type)
1938 case methodMembersInit:
1941 static uint instMethodID = 0;
1942 External external = curExternal;
1943 Context context = curContext;
1944 Declarator declarator = members.function.declarator;
1945 Identifier nameID = GetDeclId(declarator);
1946 char * unmangled = nameID ? nameID.string : null;
1948 External createdExternal = null;
1953 //members.function.dontMangle = true;
1954 strcpy(name, "__ecereInstMeth_");
1955 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
1957 strcat(name, nameID.string);
1959 sprintf(number, "_%08d", instMethodID++);
1960 strcat(name, number);
1961 nameID.string = CopyString(name);
1964 // Do modifications here...
1967 Symbol symbol = declarator.symbol;
1968 Method method = eClass_FindMethod(_class, unmangled, privateModule);
1970 if(method && method.type == virtualMethod)
1972 symbol.method = method;
1973 ProcessMethodType(method);
1975 if(!symbol.type.thisClass)
1977 if(method.dataType.thisClass && currentClass &&
1978 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
1980 if(!currentClass.symbol)
1981 currentClass.symbol = FindClass(currentClass.fullName);
1982 symbol.type.thisClass = currentClass.symbol;
1987 _class.symbol = FindClass(_class.fullName);
1988 symbol.type.thisClass = _class.symbol;
1991 // TESTING THIS HERE:
1992 DeclareType(symbol.type, true, true);
1997 Compiler_Error($"couldn't find virtual method %s in class %s\n",
1998 unmangled, classSym.string);
2002 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2003 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2007 FreeSpecifier(nameID._class);
2008 nameID._class = null;
2014 Type type = declarator.symbol.type;
2015 External oldExternal = curExternal;
2017 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2018 // *** It was commented out for problems such as
2020 class VirtualDesktop : Window
2022 clientSize = Size { };
2033 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2035 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2038 if(strcmp(declarator.symbol.string, name))
2040 printf("TOCHECK: Look out for this\n");
2041 delete declarator.symbol.string;
2042 declarator.symbol.string = CopyString(name);
2045 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2047 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2048 excludedSymbols->Remove(declarator.symbol);
2049 globalContext.symbols.Add((BTNode)declarator.symbol);
2050 if(strstr(declarator.symbol.string), "::")
2051 globalContext.hasNameSpace = true;
2056 //curExternal = curExternal.prev;
2057 //afterExternal = afterExternal->next;
2059 //ProcessFunction(afterExternal->function);
2061 //curExternal = afterExternal;
2063 External externalDecl;
2064 externalDecl = MkExternalDeclaration(null);
2065 ast->Insert(oldExternal.prev, externalDecl);
2067 // Which function does this process?
2068 if(createdExternal.function)
2070 ProcessFunction(createdExternal.function);
2072 //curExternal = oldExternal;
2075 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2077 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2078 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2080 //externalDecl = MkExternalDeclaration(decl);
2082 //***** ast->Insert(external.prev, externalDecl);
2083 //ast->Insert(curExternal.prev, externalDecl);
2084 externalDecl.declaration = decl;
2085 if(decl.symbol && !decl.symbol.pointerExternal)
2086 decl.symbol.pointerExternal = externalDecl;
2088 // Trying this out...
2089 declarator.symbol.pointerExternal = externalDecl;
2096 curExternal = declarator.symbol.pointerExternal;
2097 ProcessFunction((FunctionDefinition)members.function);
2099 curExternal = external;
2100 curContext = context;
2104 FreeClassFunction(members.function);
2106 // In this pass, turn this into a MemberInitData
2107 exp = QMkExpId(name);
2108 members.type = dataMembersInit;
2109 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2115 case dataMembersInit:
2117 if(members.dataMembers && classSym)
2120 Location oldyyloc = yylloc;
2121 for(member = members.dataMembers->first; member; member = member.next)
2123 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2124 if(member.initializer && !member.initializer.isConstant)
2125 inst.isConstant = false;
2137 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2139 // OPTIMIZATIONS: TESTING THIS...
2142 if(type.kind == functionType)
2147 for(param = type.params.first; param; param = param.next)
2148 DeclareType(param, declarePointers, true);
2150 DeclareType(type.returnType, declarePointers, true);
2152 else if(type.kind == pointerType && declarePointers)
2153 DeclareType(type.type, declarePointers, false);
2154 else if(type.kind == classType)
2156 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2157 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2159 else if(type.kind == structType || type.kind == unionType)
2162 for(member = type.members.first; member; member = member.next)
2163 DeclareType(member, false, false);
2165 else if(type.kind == arrayType)
2166 DeclareType(type.arrayType, declarePointers, false);
2170 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2172 ClassTemplateArgument * arg = null;
2174 ClassTemplateParameter curParam = null;
2176 for(sClass = _class; sClass; sClass = sClass.base)
2179 if(sClass.templateClass) sClass = sClass.templateClass;
2180 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2182 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2184 for(sClass = sClass.base; sClass; sClass = sClass.base)
2186 if(sClass.templateClass) sClass = sClass.templateClass;
2187 id += sClass.templateParams.count;
2197 arg = &_class.templateArgs[id];
2198 if(arg && param.type == type)
2199 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2204 public Context SetupTemplatesContext(Class _class)
2206 Context context = PushContext();
2207 context.templateTypesOnly = true;
2208 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2210 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2211 for(; param; param = param.next)
2213 if(param.type == type && param.identifier)
2215 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2216 curContext.templateTypes.Add((BTNode)type);
2223 for(sClass = _class; sClass; sClass = sClass.base)
2225 ClassTemplateParameter p;
2226 for(p = sClass.templateParams.first; p; p = p.next)
2228 //OldList * specs = MkList();
2229 //Declarator decl = null;
2230 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2233 TemplateParameter param = p.param;
2237 // ADD DATA TYPE HERE...
2238 p.param = param = TemplateParameter
2240 identifier = MkIdentifier(p.name), type = p.type,
2241 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2244 type = TemplatedType { key = (uintptr)p.name, param = param };
2245 curContext.templateTypes.Add((BTNode)type);
2253 public void FinishTemplatesContext(Context context)
2255 PopContext(context);
2256 FreeContext(context);
2260 public void ProcessMethodType(Method method)
2262 if(!method.dataType)
2264 Context context = SetupTemplatesContext(method._class);
2266 method.dataType = ProcessTypeString(method.dataTypeString, false);
2268 FinishTemplatesContext(context);
2270 if(method.type != virtualMethod && method.dataType)
2272 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2274 if(!method._class.symbol)
2275 method._class.symbol = FindClass(method._class.fullName);
2276 method.dataType.thisClass = method._class.symbol;
2280 // Why was this commented out? Working fine without now...
2283 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2284 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2291 char * par = strstr(type, "(");
2292 char * classOp = null;
2297 for(c = par-type-1; c >= 0; c++)
2299 if(type[c] == ':' && type[c+1] == ':')
2301 classOp = type + c - 1;
2302 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2309 else if(!isspace(type[c]))
2316 int typeLen = strlen(type);
2317 memcpy(temp, classOp, classOpLen);
2318 temp[classOpLen] = '\0';
2320 _class = eSystem_FindClass(module, temp);
2323 method.dataTypeString = new char[typeLen - classOpLen + 1];
2324 memcpy(method.dataTypeString, type, classOp - type);
2325 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2328 method.dataTypeString = type;
2334 public void ProcessPropertyType(Property prop)
2338 Context context = SetupTemplatesContext(prop._class);
2339 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2340 FinishTemplatesContext(context);
2344 public void DeclareMethod(Method method, char * name)
2346 Symbol symbol = method.symbol;
2347 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2349 bool imported = false;
2350 bool dllImport = false;
2352 if(!method.dataType)
2353 method.dataType = ProcessTypeString(method.dataTypeString, false);
2355 if(!symbol || symbol._import || method.type == virtualMethod)
2357 if(!symbol || method.type == virtualMethod)
2360 if(!method._class.symbol)
2361 method._class.symbol = FindClass(method._class.fullName);
2362 classSym = method._class.symbol;
2363 if(!classSym._import)
2365 ModuleImport module;
2367 if(method._class.module && method._class.module.name)
2368 module = FindModule(method._class.module);
2370 module = mainModule;
2371 classSym._import = ClassImport
2373 name = CopyString(method._class.fullName);
2374 isRemote = method._class.isRemote;
2376 module.classes.Add(classSym._import);
2380 symbol = method.symbol = Symbol { };
2384 symbol._import = (ClassImport)MethodImport
2386 name = CopyString(method.name);
2387 isVirtual = method.type == virtualMethod;
2389 classSym._import.methods.Add(symbol._import);
2393 // Set the symbol type
2397 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2399 else if(type.thisClass == (void *)-1)
2401 type.thisClass = null;
2404 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2405 symbol.type = method.dataType;
2406 if(symbol.type) symbol.type.refCount++;
2409 if(!method.thisClass || strcmp(method.thisClass, "void"))
2410 symbol.type.params.Insert(null,
2411 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2414 if(!method.dataType.dllExport)
2417 if(method._class.module != privateModule && method._class.module.importType != staticImport)
2423 if(!method.dataType)
2424 method.dataType = ((Symbol)method.symbol).type;
2425 //ProcessMethodType(method);
2428 if(method.type != virtualMethod && method.dataType)
2429 DeclareType(method.dataType, true, true);
2431 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2433 // We need a declaration here :)
2435 OldList * specifiers, * declarators;
2437 Declarator funcDecl;
2440 specifiers = MkList();
2441 declarators = MkList();
2445 ListAdd(specifiers, MkSpecifier(EXTERN));
2446 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2447 ListAdd(specifiers, MkSpecifier(STATIC));
2449 if(method.type == virtualMethod)
2451 ListAdd(specifiers, MkSpecifier(INT));
2452 d = MkDeclaratorIdentifier(MkIdentifier(name));
2456 d = MkDeclaratorIdentifier(MkIdentifier(name));
2459 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2461 Context context = SetupTemplatesContext(method._class);
2462 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2463 FinishTemplatesContext(context);
2465 funcDecl = GetFuncDecl(d);
2469 Specifier spec, next;
2470 for(spec = specifiers->first; spec; spec = next)
2473 if(spec.type == extendedSpecifier)
2475 specifiers->Remove(spec);
2476 FreeSpecifier(spec);
2481 // Add this parameter if not a static method
2482 if(method.dataType && !method.dataType.staticMethod)
2484 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2486 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2487 TypeName thisParam = MkTypeName(MkListOne(
2488 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2489 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2490 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2491 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2493 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2495 TypeName param = funcDecl.function.parameters->first;
2496 funcDecl.function.parameters->Remove(param);
2497 FreeTypeName(param);
2500 if(!funcDecl.function.parameters)
2501 funcDecl.function.parameters = MkList();
2502 funcDecl.function.parameters->Insert(null, thisParam);
2505 // Make sure we don't have empty parameter declarations for static methods...
2507 else if(!funcDecl.function.parameters)
2509 funcDecl.function.parameters = MkList();
2510 funcDecl.function.parameters->Insert(null,
2511 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2515 ProcessDeclarator(d);
2517 ListAdd(declarators, MkInitDeclarator(d, null));
2519 decl = MkDeclaration(specifiers, declarators);
2521 ReplaceThisClassSpecifiers(specifiers, method._class);
2523 // Keep a different symbol for the function definition than the declaration...
2524 if(symbol.pointerExternal)
2526 Symbol functionSymbol { };
2530 *functionSymbol = *symbol;
2531 functionSymbol.string = CopyString(symbol.string);
2532 if(functionSymbol.type)
2533 functionSymbol.type.refCount++;
2536 excludedSymbols->Add(functionSymbol);
2537 symbol.pointerExternal.symbol = functionSymbol;
2539 external = MkExternalDeclaration(decl);
2541 ast->Insert(curExternal ? curExternal.prev : null, external);
2542 external.symbol = symbol;
2543 symbol.pointerExternal = external;
2547 // Move declaration higher...
2548 ast->Move(symbol.pointerExternal, curExternal.prev);
2551 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2555 char * ReplaceThisClass(Class _class)
2557 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2561 ClassTemplateParameter param;
2564 char className[1024];
2565 strcpy(className, _class.fullName);
2566 for(param = _class.templateParams.first; param; param = param.next)
2568 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2570 if(first) strcat(className, "<");
2571 if(!first) strcat(className, ", ");
2572 if(lastParam + 1 != p)
2574 strcat(className, param.name);
2575 strcat(className, " = ");
2577 strcat(className, param.name);
2585 int len = strlen(className);
2586 if(className[len-1] == '>') className[len++] = ' ';
2587 className[len++] = '>';
2588 className[len++] = '\0';
2590 return CopyString(className);
2593 return CopyString(_class.fullName);
2596 Type ReplaceThisClassType(Class _class)
2598 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2602 ClassTemplateParameter param;
2604 char className[1024];
2605 strcpy(className, _class.fullName);
2607 for(param = _class.templateParams.first; param; param = param.next)
2609 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2611 if(first) strcat(className, "<");
2612 if(!first) strcat(className, ", ");
2613 if(lastParam + 1 != p)
2615 strcat(className, param.name);
2616 strcat(className, " = ");
2618 strcat(className, param.name);
2626 int len = strlen(className);
2627 if(className[len-1] == '>') className[len++] = ' ';
2628 className[len++] = '>';
2629 className[len++] = '\0';
2631 return MkClassType(className);
2632 //return ProcessTypeString(className, false);
2636 return MkClassType(_class.fullName);
2637 //return ProcessTypeString(_class.fullName, false);
2641 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2643 if(specs != null && _class)
2646 for(spec = specs.first; spec; spec = spec.next)
2648 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2650 spec.type = nameSpecifier;
2651 spec.name = ReplaceThisClass(_class);
2652 spec.symbol = FindClass(spec.name); //_class.symbol;
2658 // Returns imported or not
2659 bool DeclareFunction(GlobalFunction function, char * name)
2661 Symbol symbol = function.symbol;
2662 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2664 bool imported = false;
2665 bool dllImport = false;
2667 if(!function.dataType)
2669 function.dataType = ProcessTypeString(function.dataTypeString, false);
2670 if(!function.dataType.thisClass)
2671 function.dataType.staticMethod = true;
2678 ModuleImport module = FindModule(function.module);
2679 // WARNING: This is not added anywhere...
2680 symbol = function.symbol = Symbol { };
2684 if(!function.dataType.dllExport)
2686 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2687 module.functions.Add(symbol._import);
2690 // Set the symbol type
2692 symbol.type = ProcessTypeString(function.dataTypeString, false);
2693 if(!symbol.type.thisClass)
2694 symbol.type.staticMethod = true;
2697 imported = symbol._import ? true : false;
2698 if(imported && function.module != privateModule && function.module.importType != staticImport)
2702 DeclareType(function.dataType, true, true);
2706 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2708 // We need a declaration here :)
2710 OldList * specifiers, * declarators;
2712 Declarator funcDecl;
2715 specifiers = MkList();
2716 declarators = MkList();
2719 ListAdd(specifiers, MkSpecifier(EXTERN));
2722 ListAdd(specifiers, MkSpecifier(STATIC));
2725 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2728 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2730 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2731 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2732 if(function.module.importType == staticImport)
2735 for(spec = specifiers->first; spec; spec = spec.next)
2736 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2738 specifiers->Remove(spec);
2739 FreeSpecifier(spec);
2744 funcDecl = GetFuncDecl(d);
2746 // Make sure we don't have empty parameter declarations for static methods...
2747 if(funcDecl && !funcDecl.function.parameters)
2749 funcDecl.function.parameters = MkList();
2750 funcDecl.function.parameters->Insert(null,
2751 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2754 ListAdd(declarators, MkInitDeclarator(d, null));
2757 Context oldCtx = curContext;
2758 curContext = globalContext;
2759 decl = MkDeclaration(specifiers, declarators);
2760 curContext = oldCtx;
2763 // Keep a different symbol for the function definition than the declaration...
2764 if(symbol.pointerExternal)
2766 Symbol functionSymbol { };
2769 *functionSymbol = *symbol;
2770 functionSymbol.string = CopyString(symbol.string);
2771 if(functionSymbol.type)
2772 functionSymbol.type.refCount++;
2775 excludedSymbols->Add(functionSymbol);
2777 symbol.pointerExternal.symbol = functionSymbol;
2779 external = MkExternalDeclaration(decl);
2781 ast->Insert(curExternal.prev, external);
2782 external.symbol = symbol;
2783 symbol.pointerExternal = external;
2787 // Move declaration higher...
2788 ast->Move(symbol.pointerExternal, curExternal.prev);
2792 symbol.id = curExternal.symbol.idCode;
2795 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2798 void DeclareGlobalData(GlobalData data)
2800 Symbol symbol = data.symbol;
2801 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2806 symbol = data.symbol = Symbol { };
2809 data.dataType = ProcessTypeString(data.dataTypeString, false);
2810 DeclareType(data.dataType, true, true);
2813 if(!symbol.pointerExternal)
2815 // We need a declaration here :)
2817 OldList * specifiers, * declarators;
2821 specifiers = MkList();
2822 declarators = MkList();
2824 ListAdd(specifiers, MkSpecifier(EXTERN));
2825 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2826 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2828 ListAdd(declarators, MkInitDeclarator(d, null));
2830 decl = MkDeclaration(specifiers, declarators);
2831 external = MkExternalDeclaration(decl);
2833 ast->Insert(curExternal.prev, external);
2834 external.symbol = symbol;
2835 symbol.pointerExternal = external;
2839 // Move declaration higher...
2840 ast->Move(symbol.pointerExternal, curExternal.prev);
2844 symbol.id = curExternal.symbol.idCode;
2849 class Conversion : struct
2851 Conversion prev, next;
2857 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2861 // Property convert;
2863 if(source.kind == templateType && dest.kind != templateType)
2865 Type type = ProcessTemplateParameterType(source.templateParameter);
2866 if(type) source = type;
2869 if(dest.kind == templateType && source.kind != templateType)
2871 Type type = ProcessTemplateParameterType(dest.templateParameter);
2872 if(type) dest = type;
2875 if(dest.classObjectType == typedObject)
2877 if(source.classObjectType != anyObject)
2881 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2882 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2890 if(source.classObjectType == anyObject)
2892 if(dest.classObjectType == anyObject && source.classObjectType != typedObject)
2896 if((dest.kind == structType && source.kind == structType) ||
2897 (dest.kind == unionType && source.kind == unionType))
2899 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2900 (source.members.first && source.members.first == dest.members.first))
2904 if(dest.kind == ellipsisType && source.kind != voidType)
2907 if(dest.kind == pointerType && dest.type.kind == voidType &&
2908 ((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))
2909 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2911 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2913 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2915 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2916 ((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))
2917 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2919 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2921 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2924 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2926 if(source._class.registered && source._class.registered.type == unitClass)
2928 if(conversions != null)
2930 if(source._class.registered == dest._class.registered)
2935 Class sourceBase, destBase;
2936 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2937 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2938 if(sourceBase == destBase)
2942 // Don't match enum inheriting from other enum if resolving enumeration values
2943 // TESTING: !dest.classObjectType
2944 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2946 (!source._class.registered || source._class.registered.type != enumClass) ||
2947 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2951 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2953 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2954 ((source._class && source._class.registered && source._class.registered.type != enumClass) || source.kind == classType)) // Added this here for a base enum to be acceptable for a derived enum (#139)
2956 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2964 // JUST ADDED THIS...
2965 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
2970 // Just added this for Straight conversion of ColorAlpha => Color
2971 if(source.kind == classType)
2974 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
2977 for(convert = _class.conversions.first; convert; convert = convert.next)
2979 if(convert.memberAccess == publicAccess || _class.module == privateModule)
2981 Conversion after = (conversions != null) ? conversions.last : null;
2983 if(!convert.dataType)
2984 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
2985 if(MatchTypes(convert.dataType, dest, conversions, null, null, false, true, false, true))
2987 if(!conversions && !convert.Get)
2989 else if(conversions != null)
2991 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
2992 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
2993 (dest.kind != classType || dest._class.registered != _class.base))
2997 Conversion conv { convert = convert, isGet = true };
2998 // conversions.Add(conv);
2999 conversions.Insert(after, conv);
3011 if(dest.kind == classType)
3014 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3017 for(convert = _class.conversions.first; convert; convert = convert.next)
3019 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3021 // Conversion after = (conversions != null) ? conversions.last : null;
3023 if(!convert.dataType)
3024 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3025 // Just added this equality check to prevent recursion.... Make it safer?
3026 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3027 if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
3029 if(!conversions && !convert.Set)
3031 else if(conversions != null)
3033 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3034 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3035 (source.kind != classType || source._class.registered != _class.base))
3039 // *** Testing this! ***
3040 Conversion conv { convert = convert };
3041 conversions.Add(conv);
3042 //conversions.Insert(after, conv);
3050 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3052 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3053 (source.kind != classType || source._class.registered.type != structClass))
3057 // TESTING THIS... IS THIS OK??
3058 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3060 if(!dest._class.registered.dataType)
3061 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3062 // Only support this for classes...
3063 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3064 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3066 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3075 if(source.kind == classType)
3078 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3081 for(convert = _class.conversions.first; convert; convert = convert.next)
3083 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3085 Conversion after = (conversions != null) ? conversions.last : null;
3087 if(!convert.dataType)
3088 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3089 if(convert.dataType != source && MatchTypes(convert.dataType, dest, conversions, null, null, true, true, false, true))
3091 if(!conversions && !convert.Get)
3093 else if(conversions != null)
3095 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3096 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3097 (dest.kind != classType || dest._class.registered != _class.base))
3101 Conversion conv { convert = convert, isGet = true };
3103 // conversions.Add(conv);
3104 conversions.Insert(after, conv);
3113 // TESTING THIS... IS THIS OK??
3114 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3116 if(!source._class.registered.dataType)
3117 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3118 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, true, false, false))
3126 if(source.kind == classType || source.kind == subClassType)
3128 else if(dest.kind == source.kind &&
3129 (dest.kind != structType && dest.kind != unionType &&
3130 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3132 // RECENTLY ADDED THESE
3133 else if(dest.kind == doubleType && source.kind == floatType)
3135 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3137 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3139 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3141 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3143 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3145 else if(source.kind == enumType &&
3146 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3148 else if(dest.kind == enumType &&
3149 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3151 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3152 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3154 Type paramSource, paramDest;
3156 if(dest.kind == methodType)
3157 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3158 if(source.kind == methodType)
3159 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3161 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3162 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3163 if(dest.kind == methodType)
3164 dest = dest.method.dataType;
3165 if(source.kind == methodType)
3166 source = source.method.dataType;
3168 paramSource = source.params.first;
3169 if(paramSource && paramSource.kind == voidType) paramSource = null;
3170 paramDest = dest.params.first;
3171 if(paramDest && paramDest.kind == voidType) paramDest = null;
3174 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3175 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3177 // Source thisClass must be derived from destination thisClass
3178 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3179 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3181 if(paramDest && paramDest.kind == classType)
3182 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3184 Compiler_Error($"method class should not take an object\n");
3187 paramDest = paramDest.next;
3189 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3191 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3195 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3197 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3203 // THIS WAS BACKWARDS:
3204 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3205 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3208 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3210 Compiler_Error($"overriding class expected to be derived from method class\n");
3214 paramSource = paramSource.next;
3220 // Source thisClass must be derived from destination thisClass
3221 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3223 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3229 // THIS WAS BACKWARDS TOO??
3230 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3231 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3234 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3236 //Compiler_Error($"overriding class expected to be derived from method class\n");
3244 // Source return type must be derived from destination return type
3245 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3247 Compiler_Warning($"incompatible return type for function\n");
3253 for(; paramDest; paramDest = paramDest.next)
3257 //Compiler_Warning($"not enough parameters\n");
3258 Compiler_Error($"not enough parameters\n");
3262 Type paramDestType = paramDest;
3263 Type paramSourceType = paramSource;
3264 Type type = paramDestType;
3266 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3267 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3268 paramSource.kind != templateType)
3271 ClassTemplateParameter curParam = null;
3273 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3276 if(sClass.templateClass) sClass = sClass.templateClass;
3277 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3279 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3281 for(sClass = sClass.base; sClass; sClass = sClass.base)
3283 if(sClass.templateClass) sClass = sClass.templateClass;
3284 id += sClass.templateParams.count;
3295 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3296 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3300 // paramDest must be derived from paramSource
3301 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3302 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3306 PrintType(paramDest, type, false, true);
3307 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3309 if(paramDestType != paramDest)
3310 FreeType(paramDestType);
3313 if(paramDestType != paramDest)
3314 FreeType(paramDestType);
3317 paramSource = paramSource.next;
3321 Compiler_Error($"too many parameters\n");
3326 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3330 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3331 (source.kind == arrayType || source.kind == pointerType))
3333 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3340 static void FreeConvert(Conversion convert)
3342 if(convert.resultType)
3343 FreeType(convert.resultType);
3346 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3347 char * string, OldList conversions)
3351 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3353 Class _class = link.data;
3354 if(_class.type == enumClass)
3356 OldList converts { };
3358 type.kind = classType;
3361 _class.symbol = FindClass(_class.fullName);
3362 type._class = _class.symbol;
3364 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3367 Class enumClass = eSystem_FindClass(privateModule, "enum");
3371 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3373 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3374 for(value = e.values.first; value; value = value.next)
3376 if(!strcmp(value.name, string))
3381 FreeExpContents(sourceExp);
3382 FreeType(sourceExp.expType);
3384 sourceExp.isConstant = true;
3385 sourceExp.expType = MkClassType(baseClass.fullName);
3389 sourceExp.type = constantExp;
3390 if(!strcmp(baseClass.dataTypeString, "int"))
3391 sprintf(constant, "%d",(int)value.data);
3393 sprintf(constant, "0x%X",(int)value.data);
3394 sourceExp.constant = CopyString(constant);
3395 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3398 while(converts.first)
3400 Conversion convert = converts.first;
3401 converts.Remove(convert);
3402 conversions.Add(convert);
3411 converts.Free(FreeConvert);
3415 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3416 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3421 public bool ModuleVisibility(Module searchIn, Module searchFor)
3423 SubModule subModule;
3425 if(searchFor == searchIn)
3428 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3430 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3432 if(ModuleVisibility(subModule.module, searchFor))
3439 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3443 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3445 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3447 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3450 for(module = mainModule.application.allModules.first; module; module = module.next)
3452 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3458 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3460 Type source = sourceExp.expType;
3461 Type realDest = dest;
3462 Type backupSourceExpType = null;
3464 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3467 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3469 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3471 Class sourceBase, destBase;
3472 for(sourceBase = source._class.registered;
3473 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3474 sourceBase = sourceBase.base);
3475 for(destBase = dest._class.registered;
3476 destBase && destBase.base && destBase.base.type != systemClass;
3477 destBase = destBase.base);
3478 //if(source._class.registered == dest._class.registered)
3479 if(sourceBase == destBase)
3488 int64 value = MAXINT;
3493 if(sourceExp.type == constantExp)
3496 value = strtoll(sourceExp.constant, null, 0);
3498 value = strtoull(sourceExp.constant, null, 0);
3500 else if(sourceExp.type == opExp && sourceExp.op.op == '-' && !sourceExp.op.exp1 && sourceExp.op.exp2 && sourceExp.op.exp2.type == constantExp)
3503 value = -strtoll(sourceExp.op.exp2.constant, null, 0);
3505 value = -strtoull(sourceExp.op.exp2.constant, null, 0);
3508 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3509 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3512 source = Type { kind = intType, isSigned = false, refCount = 1 };
3515 if(dest.kind == classType)
3517 Class _class = dest._class ? dest._class.registered : null;
3519 if(_class && _class.type == unitClass)
3521 if(source.kind != classType)
3524 Type tempDest, tempSource;
3526 for(; _class.base.type != systemClass; _class = _class.base);
3528 tempDest = tempType;
3530 tempType.kind = classType;
3532 _class.symbol = FindClass(_class.fullName);
3534 tempType._class = _class.symbol;
3535 tempType.truth = dest.truth;
3537 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3539 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3540 backupSourceExpType = sourceExp.expType;
3541 sourceExp.expType = dest; dest.refCount++;
3542 //sourceExp.expType = MkClassType(_class.fullName);
3550 // Why wasn't there something like this?
3551 if(_class && _class.type == bitClass && source.kind != classType)
3553 if(!dest._class.registered.dataType)
3554 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3555 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3558 FreeType(sourceExp.expType);
3559 source = sourceExp.expType = MkClassType(dest._class.string);
3562 //source.kind = classType;
3563 //source._class = dest._class;
3567 // Adding two enumerations
3569 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3571 if(!source._class.registered.dataType)
3572 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3573 if(!dest._class.registered.dataType)
3574 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3576 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3579 source = sourceExp.expType = MkClassType(dest._class.string);
3582 //source.kind = classType;
3583 //source._class = dest._class;
3587 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3589 OldList * specs = MkList();
3593 ReadString(string, sourceExp.string);
3594 decl = SpecDeclFromString(string, specs, null);
3596 FreeExpContents(sourceExp);
3597 FreeType(sourceExp.expType);
3599 sourceExp.type = classExp;
3600 sourceExp._classExp.specifiers = specs;
3601 sourceExp._classExp.decl = decl;
3602 sourceExp.expType = dest;
3607 if(backupSourceExpType) FreeType(backupSourceExpType);
3611 else if(source.kind == classType)
3613 Class _class = source._class ? source._class.registered : null;
3615 if(_class && (_class.type == unitClass || !strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3618 if(dest.kind != classType)
3620 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3621 if(!source._class.registered.dataType)
3622 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3625 dest = MkClassType(source._class.string);
3626 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3627 // dest = MkClassType(source._class.string);
3631 if(dest.kind != classType)
3634 Type tempDest, tempSource;
3636 if(!source._class.registered.dataType)
3637 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3639 for(; _class.base.type != systemClass; _class = _class.base);
3641 tempSource = tempType;
3642 tempType.kind = classType;
3643 tempType._class = FindClass(_class.fullName);
3644 tempType.truth = source.truth;
3645 tempType.classObjectType = source.classObjectType;
3648 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3650 // PUT THIS BACK TESTING UNITS?
3651 if(conversions.last)
3653 ((Conversion)(conversions.last)).resultType = dest;
3657 FreeType(sourceExp.expType);
3658 sourceExp.expType = MkClassType(_class.fullName);
3659 sourceExp.expType.truth = source.truth;
3660 sourceExp.expType.classObjectType = source.classObjectType;
3662 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3664 if(!sourceExp.destType)
3666 FreeType(sourceExp.destType);
3667 sourceExp.destType = sourceExp.expType;
3668 if(sourceExp.expType)
3669 sourceExp.expType.refCount++;
3672 //source = _class.dataType;
3675 // TOCHECK: TESTING THIS NEW CODE
3676 if(!_class.dataType)
3677 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3679 dest = MkClassType(source._class.string);
3680 dest.truth = source.truth;
3681 dest.classObjectType = source.classObjectType;
3684 source = _class.dataType;
3694 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3704 if(source.kind == classType)
3706 Class _class = source._class.registered;
3707 if(_class.type == unitClass)
3709 if(!_class.dataType)
3710 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3711 source = _class.dataType;
3715 if(dest.kind == classType)
3717 Class _class = dest._class ? dest._class.registered : null;
3718 if(_class && !dest.truth && (_class.type == unitClass || !strcmp(_class.fullName, "bool") ||
3719 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3721 if(_class.type == normalClass || _class.type == noHeadClass)
3723 Expression newExp { };
3724 *newExp = *sourceExp;
3725 if(sourceExp.destType) sourceExp.destType.refCount++;
3726 if(sourceExp.expType) sourceExp.expType.refCount++;
3727 sourceExp.type = castExp;
3728 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3729 sourceExp.cast.exp = newExp;
3730 FreeType(sourceExp.expType);
3731 sourceExp.expType = null;
3732 ProcessExpressionType(sourceExp);
3734 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3737 FreeType(sourceExp.expType);
3738 sourceExp.expType = dest;
3742 if(inCompiler) FreeType(dest);
3744 if(backupSourceExpType) FreeType(backupSourceExpType);
3748 if(!_class.dataType)
3749 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3751 dest = _class.dataType;
3755 // Accept lower precision types for units, since we want to keep the unit type
3756 if(dest.kind == doubleType &&
3757 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3758 source.kind == charType || source.kind == _BoolType))
3760 specs = MkListOne(MkSpecifier(DOUBLE));
3762 else if(dest.kind == floatType &&
3763 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3764 source.kind == _BoolType || source.kind == doubleType))
3766 specs = MkListOne(MkSpecifier(FLOAT));
3768 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3769 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3772 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3773 ListAdd(specs, MkSpecifier(INT64));
3775 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3776 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3779 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3780 ListAdd(specs, MkSpecifier(INT));
3782 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3783 source.kind == floatType || source.kind == doubleType))
3786 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3787 ListAdd(specs, MkSpecifier(SHORT));
3789 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3790 source.kind == floatType || source.kind == doubleType))
3793 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3794 ListAdd(specs, MkSpecifier(CHAR));
3800 if(backupSourceExpType)
3802 // Failed to convert: revert previous exp type
3803 if(sourceExp.expType) FreeType(sourceExp.expType);
3804 sourceExp.expType = backupSourceExpType;
3809 else if(dest.kind == doubleType &&
3810 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3811 source.kind == _BoolType || source.kind == charType))
3813 specs = MkListOne(MkSpecifier(DOUBLE));
3815 else if(dest.kind == floatType &&
3816 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3818 specs = MkListOne(MkSpecifier(FLOAT));
3820 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3821 (value == 1 || value == 0))
3824 ListAdd(specs, MkSpecifier(BOOL));
3826 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3827 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3830 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3831 ListAdd(specs, MkSpecifier(CHAR));
3833 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3834 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3837 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3838 ListAdd(specs, MkSpecifier(SHORT));
3840 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3843 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3844 ListAdd(specs, MkSpecifier(INT));
3846 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3849 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3850 ListAdd(specs, MkSpecifier(INT64));
3852 else if(dest.kind == enumType &&
3853 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3855 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3861 if(backupSourceExpType)
3863 // Failed to convert: revert previous exp type
3864 if(sourceExp.expType) FreeType(sourceExp.expType);
3865 sourceExp.expType = backupSourceExpType;
3872 Expression newExp { };
3873 *newExp = *sourceExp;
3876 if(sourceExp.destType) sourceExp.destType.refCount++;
3877 if(sourceExp.expType) sourceExp.expType.refCount++;
3879 sourceExp.type = castExp;
3880 if(realDest.kind == classType)
3882 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3883 FreeList(specs, FreeSpecifier);
3886 sourceExp.cast.typeName = MkTypeName(specs, null);
3887 if(newExp.type == opExp)
3889 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3892 sourceExp.cast.exp = newExp;
3894 FreeType(sourceExp.expType);
3895 sourceExp.expType = null;
3896 ProcessExpressionType(sourceExp);
3899 FreeList(specs, FreeSpecifier);
3903 if(backupSourceExpType) FreeType(backupSourceExpType);
3909 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
3910 if(sourceExp.type == identifierExp)
3912 Identifier id = sourceExp.identifier;
3913 if(dest.kind == classType)
3915 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3917 Class _class = dest._class.registered;
3918 Class enumClass = eSystem_FindClass(privateModule, "enum");
3921 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
3924 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
3925 for(value = e.values.first; value; value = value.next)
3927 if(!strcmp(value.name, id.string))
3932 FreeExpContents(sourceExp);
3933 FreeType(sourceExp.expType);
3935 sourceExp.isConstant = true;
3936 sourceExp.expType = MkClassType(_class.fullName);
3940 sourceExp.type = constantExp;
3941 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
3942 sprintf(constant, "%d", (int) value.data);
3944 sprintf(constant, "0x%X", (int) value.data);
3945 sourceExp.constant = CopyString(constant);
3946 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
3955 // Loop through all enum classes
3956 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
3963 #define TERTIARY(o, name, m, t, p) \
3964 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
3966 exp.type = constantExp; \
3967 exp.string = p(op1.m ? op2.m : op3.m); \
3969 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3973 #define BINARY(o, name, m, t, p) \
3974 static bool name(Expression exp, Operand op1, Operand op2) \
3977 exp.type = constantExp; \
3978 exp.string = p(op1.m o value2); \
3980 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3984 #define BINARY_DIVIDE(o, name, m, t, p) \
3985 static bool name(Expression exp, Operand op1, Operand op2) \
3988 exp.type = constantExp; \
3989 exp.string = p(value2 ? (op1.m o value2) : 0); \
3991 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
3995 #define UNARY(o, name, m, t, p) \
3996 static bool name(Expression exp, Operand op1) \
3998 exp.type = constantExp; \
3999 exp.string = p((t)(o op1.m)); \
4001 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4005 #define OPERATOR_ALL(macro, o, name) \
4006 macro(o, Int##name, i, int, PrintInt) \
4007 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4008 macro(o, Int64##name, i, int, PrintInt64) \
4009 macro(o, UInt64##name, ui, unsigned int, PrintUInt64) \
4010 macro(o, Short##name, s, short, PrintShort) \
4011 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4012 macro(o, Char##name, c, char, PrintChar) \
4013 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4014 macro(o, Float##name, f, float, PrintFloat) \
4015 macro(o, Double##name, d, double, PrintDouble)
4017 #define OPERATOR_INTTYPES(macro, o, name) \
4018 macro(o, Int##name, i, int, PrintInt) \
4019 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4020 macro(o, Int64##name, i, int, PrintInt64) \
4021 macro(o, UInt64##name, ui, unsigned int, PrintUInt64) \
4022 macro(o, Short##name, s, short, PrintShort) \
4023 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4024 macro(o, Char##name, c, char, PrintChar) \
4025 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4028 // binary arithmetic
4029 OPERATOR_ALL(BINARY, +, Add)
4030 OPERATOR_ALL(BINARY, -, Sub)
4031 OPERATOR_ALL(BINARY, *, Mul)
4032 OPERATOR_ALL(BINARY_DIVIDE, /, Div)
4033 OPERATOR_INTTYPES(BINARY_DIVIDE, %, Mod)
4036 OPERATOR_ALL(UNARY, -, Neg)
4038 // unary arithmetic increment and decrement
4039 OPERATOR_ALL(UNARY, ++, Inc)
4040 OPERATOR_ALL(UNARY, --, Dec)
4042 // binary arithmetic assignment
4043 OPERATOR_ALL(BINARY, =, Asign)
4044 OPERATOR_ALL(BINARY, +=, AddAsign)
4045 OPERATOR_ALL(BINARY, -=, SubAsign)
4046 OPERATOR_ALL(BINARY, *=, MulAsign)
4047 OPERATOR_ALL(BINARY_DIVIDE, /=, DivAsign)
4048 OPERATOR_INTTYPES(BINARY_DIVIDE, %=, ModAsign)
4051 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4052 OPERATOR_INTTYPES(BINARY, |, BitOr)
4053 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4054 OPERATOR_INTTYPES(BINARY, <<, LShift)
4055 OPERATOR_INTTYPES(BINARY, >>, RShift)
4058 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4060 // binary bitwise assignment
4061 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4062 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4063 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4064 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4065 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4067 // unary logical negation
4068 OPERATOR_INTTYPES(UNARY, !, Not)
4070 // binary logical equality
4071 OPERATOR_ALL(BINARY, ==, Equ)
4072 OPERATOR_ALL(BINARY, !=, Nqu)
4075 OPERATOR_ALL(BINARY, &&, And)
4076 OPERATOR_ALL(BINARY, ||, Or)
4078 // binary logical relational
4079 OPERATOR_ALL(BINARY, >, Grt)
4080 OPERATOR_ALL(BINARY, <, Sma)
4081 OPERATOR_ALL(BINARY, >=, GrtEqu)
4082 OPERATOR_ALL(BINARY, <=, SmaEqu)
4084 // tertiary condition operator
4085 OPERATOR_ALL(TERTIARY, ?, Cond)
4087 //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
4088 #define OPERATOR_TABLE_ALL(name, type) \
4089 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4091 type##Inc, type##Dec, \
4092 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4093 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4095 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4097 type##Equ, type##Nqu, \
4098 type##And, type##Or, \
4099 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4102 #define OPERATOR_TABLE_INTTYPES(name, type) \
4103 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4105 type##Inc, type##Dec, \
4106 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4107 null, null, null, null, null, \
4109 null, null, null, null, null, \
4111 type##Equ, type##Nqu, \
4112 type##And, type##Or, \
4113 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4116 OPERATOR_TABLE_ALL(int, Int)
4117 OPERATOR_TABLE_ALL(uint, UInt)
4118 OPERATOR_TABLE_ALL(int64, Int64)
4119 OPERATOR_TABLE_ALL(uint64, UInt64)
4120 OPERATOR_TABLE_ALL(short, Short)
4121 OPERATOR_TABLE_ALL(ushort, UShort)
4122 OPERATOR_TABLE_INTTYPES(float, Float)
4123 OPERATOR_TABLE_INTTYPES(double, Double)
4124 OPERATOR_TABLE_ALL(char, Char)
4125 OPERATOR_TABLE_ALL(uchar, UChar)
4127 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4128 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4129 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4130 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4131 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4132 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4133 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4134 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4136 public void ReadString(char * output, char * string)
4138 int len = strlen(string);
4140 bool quoted = false, escaped = false;
4141 for(c = 0; c<len; c++)
4143 char ch = string[c];
4148 case 'n': output[d] = '\n'; break;
4149 case 't': output[d] = '\t'; break;
4150 case 'a': output[d] = '\a'; break;
4151 case 'b': output[d] = '\b'; break;
4152 case 'f': output[d] = '\f'; break;
4153 case 'r': output[d] = '\r'; break;
4154 case 'v': output[d] = '\v'; break;
4155 case '\\': output[d] = '\\'; break;
4156 case '\"': output[d] = '\"'; break;
4157 default: output[d++] = '\\'; output[d] = ch;
4158 //default: output[d] = ch;
4179 public Operand GetOperand(Expression exp)
4182 Type type = exp.expType;
4185 while(type.kind == classType &&
4186 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4188 if(!type._class.registered.dataType)
4189 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4190 type = type._class.registered.dataType;
4193 op.kind = type.kind;
4194 op.type = exp.expType;
4195 if(exp.isConstant && exp.type == constantExp)
4202 if(exp.constant[0] == '\'')
4203 op.c = exp.constant[1];
4204 else if(type.isSigned)
4206 op.c = (char)strtol(exp.constant, null, 0);
4211 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4219 op.s = (short)strtol(exp.constant, null, 0);
4224 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4232 op.i = (int)strtol(exp.constant, null, 0);
4237 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4245 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4250 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4253 op.kind = int64Type;
4258 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4263 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4266 op.kind = int64Type;
4271 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4276 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4279 op.kind = int64Type;
4282 op.f = (float)strtod(exp.constant, null);
4286 op.d = (double)strtod(exp.constant, null);
4289 //case classType: For when we have operator overloading...
4290 // Pointer additions
4291 //case functionType:
4295 op.ui64 = _strtoui64(exp.constant, null, 0);
4296 op.kind = pointerType;
4306 static void UnusedFunction()
4309 a.OnGetString(0,0,0);
4312 extern int __ecereVMethodID_class_OnGetString;
4315 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4317 DataMember dataMember;
4318 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4320 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4321 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4325 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4327 void * ptr = inst.data + dataMember.offset + offset;
4328 char * result = null;
4329 exp.loc = member.loc = inst.loc;
4330 ((Identifier)member.identifiers->first).loc = inst.loc;
4332 if(!dataMember.dataType)
4333 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4334 type = dataMember.dataType;
4335 if(type.kind == classType)
4337 Class _class = type._class.registered;
4338 if(_class.type == enumClass)
4340 Class enumClass = eSystem_FindClass(privateModule, "enum");
4343 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4345 for(item = e.values.first; item; item = item.next)
4347 if((int)item.data == *(int *)ptr)
4355 exp.identifier = MkIdentifier(result);
4356 exp.type = identifierExp;
4357 exp.destType = MkClassType(_class.fullName);
4358 ProcessExpressionType(exp);
4362 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4364 if(!_class.dataType)
4365 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4366 type = _class.dataType;
4375 FreeExpContents(exp);
4377 exp.constant = PrintFloat(*(float*)ptr);
4378 exp.type = constantExp;
4383 FreeExpContents(exp);
4385 exp.constant = PrintDouble(*(double*)ptr);
4386 exp.type = constantExp;
4391 FreeExpContents(exp);
4393 exp.constant = PrintInt(*(int*)ptr);
4394 exp.type = constantExp;
4399 FreeExpContents(exp);
4401 exp.constant = PrintInt64(*(int64*)ptr);
4402 exp.type = constantExp;
4407 FreeExpContents(exp);
4408 // TODO: This should probably use proper type
4409 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4410 exp.type = constantExp;
4415 FreeExpContents(exp);
4416 // TODO: This should probably use proper type
4417 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4418 exp.type = constantExp;
4422 Compiler_Error($"Unhandled type populating instance\n");
4425 ListAdd(memberList, member);
4428 if(parentDataMember.type == unionMember)
4433 void PopulateInstance(Instantiation inst)
4435 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4436 Class _class = classSym.registered;
4437 DataMember dataMember;
4438 OldList * memberList = MkList();
4439 // Added this check and ->Add to prevent memory leaks on bad code
4441 inst.members = MkListOne(MkMembersInitList(memberList));
4443 inst.members->Add(MkMembersInitList(memberList));
4444 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4446 if(!dataMember.isProperty)
4448 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4449 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4453 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4455 void * ptr = inst.data + dataMember.offset;
4456 char * result = null;
4458 exp.loc = member.loc = inst.loc;
4459 ((Identifier)member.identifiers->first).loc = inst.loc;
4461 if(!dataMember.dataType)
4462 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4463 type = dataMember.dataType;
4464 if(type.kind == classType)
4466 Class _class = type._class.registered;
4467 if(_class.type == enumClass)
4469 Class enumClass = eSystem_FindClass(privateModule, "enum");
4472 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4474 for(item = e.values.first; item; item = item.next)
4476 if((int)item.data == *(int *)ptr)
4485 exp.identifier = MkIdentifier(result);
4486 exp.type = identifierExp;
4487 exp.destType = MkClassType(_class.fullName);
4488 ProcessExpressionType(exp);
4491 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4493 if(!_class.dataType)
4494 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4495 type = _class.dataType;
4504 exp.constant = PrintFloat(*(float*)ptr);
4505 exp.type = constantExp;
4510 exp.constant = PrintDouble(*(double*)ptr);
4511 exp.type = constantExp;
4516 exp.constant = PrintInt(*(int*)ptr);
4517 exp.type = constantExp;
4522 exp.constant = PrintInt64(*(int64*)ptr);
4523 exp.type = constantExp;
4528 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4529 exp.type = constantExp;
4533 Compiler_Error($"Unhandled type populating instance\n");
4536 ListAdd(memberList, member);
4542 void ComputeInstantiation(Expression exp)
4544 Instantiation inst = exp.instance;
4545 MembersInit members;
4546 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4547 Class _class = classSym ? classSym.registered : null;
4548 DataMember curMember = null;
4549 Class curClass = null;
4550 DataMember subMemberStack[256];
4551 int subMemberStackPos = 0;
4554 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4556 // Don't recompute the instantiation...
4557 // Non Simple classes will have become constants by now
4561 if(_class.type == normalClass || _class.type == noHeadClass)
4563 inst.data = (byte *)eInstance_New(_class);
4564 if(_class.type == normalClass)
4565 ((Instance)inst.data)._refCount++;
4568 inst.data = new0 byte[_class.structSize];
4573 for(members = inst.members->first; members; members = members.next)
4575 switch(members.type)
4577 case dataMembersInit:
4579 if(members.dataMembers)
4582 for(member = members.dataMembers->first; member; member = member.next)
4584 Identifier ident = member.identifiers ? member.identifiers->first : null;
4587 Property prop = null;
4588 DataMember dataMember = null;
4589 Method method = null;
4590 uint dataMemberOffset;
4594 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4597 if(curMember.isProperty)
4598 prop = (Property)curMember;
4601 dataMember = curMember;
4603 // CHANGED THIS HERE
4604 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4606 // 2013/17/29 -- It seems that this was missing here!
4607 if(_class.type == normalClass)
4608 dataMemberOffset += _class.base.structSize;
4609 // dataMemberOffset = dataMember.offset;
4616 prop = eClass_FindProperty(_class, ident.string, privateModule);
4620 if(prop.memberAccess == publicAccess)
4622 curMember = (DataMember)prop;
4623 curClass = prop._class;
4628 DataMember _subMemberStack[256];
4629 int _subMemberStackPos = 0;
4631 // FILL MEMBER STACK
4632 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4637 if(dataMember.memberAccess == publicAccess)
4639 curMember = dataMember;
4640 curClass = dataMember._class;
4641 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4642 subMemberStackPos = _subMemberStackPos;
4648 if(found && member.initializer && member.initializer.type == expInitializer)
4650 Expression value = member.initializer.exp;
4652 bool deepMember = false;
4655 type = prop.dataType;
4659 if(!dataMember.dataType)
4660 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4662 type = dataMember.dataType;
4665 if(ident && ident.next)
4669 // for(; ident && type; ident = ident.next)
4670 for(ident = ident.next; ident && type; ident = ident.next)
4672 if(type.kind == classType)
4674 prop = eClass_FindProperty(type._class.registered,
4675 ident.string, privateModule);
4677 type = prop.dataType;
4680 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4681 ident.string, &dataMemberOffset, privateModule, null, null);
4683 type = dataMember.dataType;
4686 else if(type.kind == structType || type.kind == unionType)
4689 for(memberType = type.members.first; memberType; memberType = memberType.next)
4691 if(!strcmp(memberType.name, ident.string))
4702 FreeType(value.destType);
4703 value.destType = type;
4704 if(type) type.refCount++;
4705 ComputeExpression(value);
4707 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4709 if(type.kind == classType)
4711 Class _class = type._class.registered;
4712 if(_class.type == bitClass || _class.type == unitClass ||
4713 _class.type == enumClass)
4715 if(!_class.dataType)
4716 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4717 type = _class.dataType;
4723 void * ptr = inst.data + dataMemberOffset;
4725 if(value.type == constantExp)
4731 GetInt(value, (int*)ptr);
4736 GetInt64(value, (int64*)ptr);
4741 GetIntPtr(value, (intptr*)ptr);
4746 GetIntSize(value, (intsize*)ptr);
4751 GetFloat(value, (float*)ptr);
4756 GetDouble(value, (double *)ptr);
4761 else if(value.type == instanceExp)
4763 if(type.kind == classType)
4765 Class _class = type._class.registered;
4766 if(_class.type == structClass)
4768 ComputeTypeSize(type);
4769 if(value.instance.data)
4770 memcpy(ptr, value.instance.data, type.size);
4777 if(value.type == instanceExp && value.instance.data)
4779 if(type.kind == classType)
4781 Class _class = type._class.registered;
4782 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
4784 void (*Set)(void *, void *) = (void *)prop.Set;
4785 Set(inst.data, value.instance.data);
4786 PopulateInstance(inst);
4790 else if(value.type == constantExp)
4796 void (*Set)(void *, double) = (void *)prop.Set;
4797 Set(inst.data, strtod(value.constant, null) );
4802 void (*Set)(void *, float) = (void *)prop.Set;
4803 Set(inst.data, (float)(strtod(value.constant, null)));
4808 void (*Set)(void *, int) = (void *)prop.Set;
4809 Set(inst.data, (int)strtol(value.constant, null, 0));
4814 void (*Set)(void *, int64) = (void *)prop.Set;
4815 Set(inst.data, _strtoi64(value.constant, null, 0));
4820 void (*Set)(void *, intptr) = (void *)prop.Set;
4821 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
4826 void (*Set)(void *, intsize) = (void *)prop.Set;
4827 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
4832 else if(value.type == stringExp)
4835 ReadString(temp, value.string);
4836 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
4840 else if(!deepMember && type && _class.type == unitClass)
4844 // Only support converting units to units for now...
4845 if(value.type == constantExp)
4847 if(type.kind == classType)
4849 Class _class = type._class.registered;
4850 if(_class.type == unitClass)
4852 if(!_class.dataType)
4853 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4854 type = _class.dataType;
4857 // TODO: Assuming same base type for units...
4863 float (*Set)(float) = (void *)prop.Set;
4864 GetFloat(member.initializer.exp, &fValue);
4865 exp.constant = PrintFloat(Set(fValue));
4866 exp.type = constantExp;
4872 double (*Set)(double) = (void *)prop.Set;
4873 GetDouble(member.initializer.exp, &dValue);
4874 exp.constant = PrintDouble(Set(dValue));
4875 exp.type = constantExp;
4882 else if(!deepMember && type && _class.type == bitClass)
4886 if(value.type == instanceExp && value.instance.data)
4888 unsigned int (*Set)(void *) = (void *)prop.Set;
4889 bits = Set(value.instance.data);
4891 else if(value.type == constantExp)
4897 BitMember bitMember = (BitMember) dataMember;
4900 GetInt(value, &part);
4901 bits = (bits & ~bitMember.mask);
4902 if(!bitMember.dataType)
4903 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
4905 type = bitMember.dataType;
4907 if(type.kind == classType && type._class && type._class.registered)
4909 if(!type._class.registered.dataType)
4910 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4911 type = type._class.registered.dataType;
4919 bits |= ((char)part << bitMember.pos);
4921 bits |= ((unsigned char)part << bitMember.pos);
4925 bits |= ((short)part << bitMember.pos);
4927 bits |= ((unsigned short)part << bitMember.pos);
4932 bits |= ((int)part << bitMember.pos);
4934 bits |= ((unsigned int)part << bitMember.pos);
4938 bits |= ((int64)part << bitMember.pos);
4940 bits |= ((uint64)part << bitMember.pos);
4945 bits |= ((intptr)part << bitMember.pos);
4949 bits |= ((uintptr)part << bitMember.pos);
4955 bits |= ((ssize_t)(intsize)part << bitMember.pos);
4959 bits |= ((size_t) (uintsize)part << bitMember.pos);
4968 if(_class && _class.type == unitClass)
4970 ComputeExpression(member.initializer.exp);
4971 exp.constant = member.initializer.exp.constant;
4972 exp.type = constantExp;
4974 member.initializer.exp.constant = null;
4984 if(_class && _class.type == bitClass)
4986 exp.constant = PrintHexUInt(bits);
4987 exp.type = constantExp;
4989 if(exp.type != instanceExp)
4995 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
4997 if(exp.op.op == SIZEOF)
4999 FreeExpContents(exp);
5000 exp.type = constantExp;
5001 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5012 // Provide default unary +
5013 Expression exp2 = exp.op.exp2;
5015 FreeExpContents(exp);
5016 FreeType(exp.expType);
5017 FreeType(exp.destType);
5023 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5025 // unary arithmetic increment and decrement
5026 //OPERATOR_ALL(UNARY, ++, Inc)
5027 //OPERATOR_ALL(UNARY, --, Dec)
5030 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5032 // unary logical negation
5034 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5042 // binary arithmetic
5044 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5047 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5050 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5053 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5056 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5058 // binary arithmetic assignment
5059 //OPERATOR_ALL(BINARY, =, Asign)
5060 //OPERATOR_ALL(BINARY, +=, AddAsign)
5061 //OPERATOR_ALL(BINARY, -=, SubAsign)
5062 //OPERATOR_ALL(BINARY, *=, MulAsign)
5063 //OPERATOR_ALL(BINARY, /=, DivAsign)
5064 //OPERATOR_ALL(BINARY, %=, ModAsign)
5069 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5073 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5076 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5079 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5082 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5084 // binary bitwise assignment
5085 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5086 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5087 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5088 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5089 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5090 // binary logical equality
5092 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5095 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5099 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5102 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5104 // binary logical relational
5106 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5109 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5112 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5115 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5122 void ComputeExpression(Expression exp)
5124 char expString[10240];
5125 expString[0] = '\0';
5127 PrintExpression(exp, expString);
5134 ComputeInstantiation(exp);
5143 Expression exp1, exp2 = null;
5147 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5149 ComputeExpression(exp.op.exp2);
5152 ComputeExpression(exp.op.exp1);
5155 op1 = GetOperand(exp1);
5156 if(op1.type) op1.type.refCount++;
5159 op2 = GetOperand(exp2);
5160 if(op2.type) op2.type.refCount++;
5166 op1 = GetOperand(exp1);
5167 if(op1.type) op1.type.refCount++;
5170 CallOperator(exp, exp1, exp2, op1, op2);
5177 if(exp.op.exp1 && exp.op.exp2)
5182 FreeExpContents(exp);
5183 op1.ops.BitAnd(exp, op1, op2);
5192 FreeExpContents(exp);
5193 op1.ops.Mul(exp, op1, op2);
5202 FreeExpContents(exp);
5203 op1.ops.Add(exp, op1, op2);
5208 // Provide default unary +
5209 Expression exp2 = exp.op.exp2;
5211 FreeExpContents(exp);
5212 FreeType(exp.expType);
5213 FreeType(exp.destType);
5224 FreeExpContents(exp);
5225 op1.ops.Sub(exp, op1, op2);
5232 FreeExpContents(exp);
5233 op1.ops.Neg(exp, op1);
5240 FreeExpContents(exp);
5241 op1.ops.BitNot(exp, op1);
5247 FreeExpContents(exp);
5248 op1.ops.Not(exp, op1);
5251 // Binary only operators
5255 FreeExpContents(exp);
5256 op1.ops.Div(exp, op1, op2);
5262 FreeExpContents(exp);
5263 op1.ops.Mod(exp, op1, op2);
5275 FreeExpContents(exp);
5276 op1.ops.Sma(exp, op1, op2);
5285 FreeExpContents(exp);
5286 op1.ops.Grt(exp, op1, op2);
5295 FreeExpContents(exp);
5296 op1.ops.SmaEqu(exp, op1, op2);
5305 FreeExpContents(exp);
5306 op1.ops.GrtEqu(exp, op1, op2);
5315 FreeExpContents(exp);
5316 op1.ops.Equ(exp, op1, op2);
5325 FreeExpContents(exp);
5326 op1.ops.Nqu(exp, op1, op2);
5333 FreeExpContents(exp);
5334 op1.ops.BitOr(exp, op1, op2);
5340 FreeExpContents(exp);
5341 op1.ops.BitXor(exp, op1, op2);
5349 FreeExpContents(exp);
5350 exp.type = constantExp;
5351 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5355 if(op1.type) FreeType(op1.type);
5356 if(op2.type) FreeType(op2.type);
5360 case extensionExpressionExp:
5363 for(e = exp.list->first; e; e = n)
5368 OldList * list = exp.list;
5369 ComputeExpression(e);
5370 //FreeExpContents(exp);
5371 FreeType(exp.expType);
5372 FreeType(exp.destType);
5389 exp.isConstant = true;
5391 ComputeExpression(exp.index.exp);
5392 if(!exp.index.exp.isConstant)
5393 exp.isConstant = false;
5395 for(e = exp.index.index->first; e; e = e.next)
5397 ComputeExpression(e);
5400 // Check if this type is int
5403 exp.isConstant = false;
5405 exp.expType = Dereference(exp.index.exp.expType);
5411 Expression memberExp = exp.member.exp;
5412 Identifier memberID = exp.member.member;
5415 ComputeExpression(exp.member.exp);
5416 type = exp.member.exp.expType;
5419 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);
5420 Property prop = null;
5421 DataMember member = null;
5422 Class convertTo = null;
5423 if(type.kind == subClassType && exp.member.exp.type == classExp)
5424 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5431 PrintTypeNoConst(type, string, false, true);
5432 classSym = FindClass(string);
5433 _class = classSym ? classSym.registered : null;
5436 if(exp.member.member)
5438 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5440 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5442 if(!prop && !member && _class && exp.member.member)
5444 Symbol classSym = FindClass(exp.member.member.string);
5446 _class = classSym ? classSym.registered : null;
5447 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5454 Type type = prop.dataType;
5455 // TODO: Assuming same base type for units...
5456 if(_class.type == unitClass)
5458 if(type.kind == classType)
5460 Class _class = type._class.registered;
5461 if(_class.type == unitClass)
5463 if(!_class.dataType)
5464 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5465 type = _class.dataType;
5473 float (*Get)(float) = (void *)prop.Get;
5474 GetFloat(exp.member.exp, &value);
5475 exp.constant = PrintFloat(Get ? Get(value) : value);
5476 exp.type = constantExp;
5482 double (*Get)(double);
5483 GetDouble(exp.member.exp, &value);
5486 Get = (void *)prop.Set;
5488 Get = (void *)prop.Get;
5489 exp.constant = PrintDouble(Get ? Get(value) : value);
5490 exp.type = constantExp;
5499 Expression value = exp.member.exp;
5502 ProcessPropertyType(prop);
5504 type = prop.dataType;
5507 // printf("Investigate this\n");
5509 else if(_class.type == structClass)
5515 Class propertyClass = type._class.registered;
5516 if(propertyClass.type == structClass && value.type == instanceExp)
5518 void (*Set)(void *, void *) = (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;
5524 Set(exp.instance.data, value.instance.data);
5525 PopulateInstance(exp.instance);
5532 void (*Set)(void *, int) = (void *)prop.Set;
5534 exp.instance = Instantiation { };
5535 exp.instance.data = new0 byte[_class.structSize];
5536 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5537 exp.instance.loc = exp.loc;
5538 exp.type = instanceExp;
5540 GetInt(value, &intValue);
5542 Set(exp.instance.data, intValue);
5543 PopulateInstance(exp.instance);
5549 void (*Set)(void *, int64) = (void *)prop.Set;
5551 exp.instance = Instantiation { };
5552 exp.instance.data = new0 byte[_class.structSize];
5553 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5554 exp.instance.loc = exp.loc;
5555 exp.type = instanceExp;
5557 GetInt64(value, &intValue);
5559 Set(exp.instance.data, intValue);
5560 PopulateInstance(exp.instance);
5567 void (*Set)(void *, intptr) = (void *)prop.Set;
5569 exp.instance = Instantiation { };
5570 exp.instance.data = new0 byte[_class.structSize];
5571 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5572 exp.instance.loc = exp.loc;
5573 exp.type = instanceExp;
5575 GetIntPtr(value, &intValue);
5577 Set(exp.instance.data, intValue);
5578 PopulateInstance(exp.instance);
5585 void (*Set)(void *, intsize) = (void *)prop.Set;
5587 exp.instance = Instantiation { };
5588 exp.instance.data = new0 byte[_class.structSize];
5589 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5590 exp.instance.loc = exp.loc;
5591 exp.type = instanceExp;
5593 GetIntSize(value, &intValue);
5595 Set(exp.instance.data, intValue);
5596 PopulateInstance(exp.instance);
5602 void (*Set)(void *, double) = (void *)prop.Set;
5604 exp.instance = Instantiation { };
5605 exp.instance.data = new0 byte[_class.structSize];
5606 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5607 exp.instance.loc = exp.loc;
5608 exp.type = instanceExp;
5610 GetDouble(value, &doubleValue);
5612 Set(exp.instance.data, doubleValue);
5613 PopulateInstance(exp.instance);
5618 else if(_class.type == bitClass)
5624 Class propertyClass = type._class.registered;
5625 if(propertyClass.type == structClass && value.instance.data)
5627 unsigned int (*Set)(void *) = (void *)prop.Set;
5628 unsigned int bits = Set(value.instance.data);
5629 exp.constant = PrintHexUInt(bits);
5630 exp.type = constantExp;
5633 else if(_class.type == bitClass)
5636 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5639 GetUInt(exp.member.exp, &value);
5641 exp.constant = PrintHexUInt(bits);
5642 exp.type = constantExp;
5650 if(_class.type == bitClass)
5653 GetUInt(exp.member.exp, &value);
5659 Class _class = type._class.registered;
5660 if(_class.type == structClass)
5662 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5664 exp.instance = Instantiation { };
5665 exp.instance.data = new0 byte[_class.structSize];
5666 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5667 exp.instance.loc = exp.loc;
5668 //exp.instance.fullSet = true;
5669 exp.type = instanceExp;
5670 Get(value, exp.instance.data);
5671 PopulateInstance(exp.instance);
5673 else if(_class.type == bitClass)
5675 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5676 uint64 bits = Get(value);
5677 exp.constant = PrintHexUInt64(bits);
5678 exp.type = constantExp;
5684 else if(_class.type == structClass)
5686 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5691 Class _class = type._class.registered;
5692 if(_class.type == structClass && value)
5694 void (*Get)(void *, void *) = (void *)prop.Get;
5696 exp.instance = Instantiation { };
5697 exp.instance.data = new0 byte[_class.structSize];
5698 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5699 exp.instance.loc = exp.loc;
5700 //exp.instance.fullSet = true;
5701 exp.type = instanceExp;
5702 Get(value, exp.instance.data);
5703 PopulateInstance(exp.instance);
5711 char * value = exp.member.exp.instance.data;
5716 Class _class = type._class.registered;
5717 if(_class.type == normalClass)
5719 void *(*Get)(void *) = (void *)prop.Get;
5721 exp.instance = Instantiation { };
5722 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5723 exp.type = instanceExp;
5724 exp.instance.data = Get(value, exp.instance.data);
5736 exp.isConstant = false;
5744 if(exp.type != ExpressionType::memberExp)
5746 FreeExpression(memberExp);
5747 FreeIdentifier(memberID);
5753 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5754 FreeExpContents(exp);
5755 exp.constant = PrintUInt(ComputeTypeSize(type));
5756 exp.type = constantExp;
5762 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5763 if(classSym && classSym.registered)
5765 if(classSym.registered.fixed)
5767 FreeSpecifier(exp._class);
5768 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5769 exp.type = constantExp;
5773 char className[1024];
5774 strcpy(className, "__ecereClass_");
5775 FullClassNameCat(className, classSym.string, true);
5776 MangleClassName(className);
5778 DeclareClass(classSym, className);
5780 FreeExpContents(exp);
5781 exp.type = pointerExp;
5782 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5783 exp.member.member = MkIdentifier("structSize");
5793 if(exp.type == castExp)
5796 ComputeExpression(exp.cast.exp);
5799 if(e && exp.expType)
5802 type = exp.destType;
5805 if(type.kind == classType)
5807 Class _class = type._class.registered;
5808 if(_class && (_class.type == unitClass || _class.type == bitClass))
5810 if(!_class.dataType)
5811 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5812 type = _class.dataType;
5824 FreeExpContents(exp);
5825 exp.constant = PrintChar(value);
5826 exp.type = constantExp;
5830 unsigned char value;
5831 GetUChar(e, &value);
5832 FreeExpContents(exp);
5833 exp.constant = PrintUChar(value);
5834 exp.type = constantExp;
5841 GetShort(e, &value);
5842 FreeExpContents(exp);
5843 exp.constant = PrintShort(value);
5844 exp.type = constantExp;
5848 unsigned short value;
5849 GetUShort(e, &value);
5850 FreeExpContents(exp);
5851 exp.constant = PrintUShort(value);
5852 exp.type = constantExp;
5860 FreeExpContents(exp);
5861 exp.constant = PrintInt(value);
5862 exp.type = constantExp;
5868 FreeExpContents(exp);
5869 exp.constant = PrintUInt(value);
5870 exp.type = constantExp;
5877 GetInt64(e, &value);
5878 FreeExpContents(exp);
5879 exp.constant = PrintInt64(value);
5880 exp.type = constantExp;
5885 GetUInt64(e, &value);
5886 FreeExpContents(exp);
5887 exp.constant = PrintUInt64(value);
5888 exp.type = constantExp;
5895 GetIntPtr(e, &value);
5896 FreeExpContents(exp);
5897 exp.constant = PrintInt64((int64)value);
5898 exp.type = constantExp;
5903 GetUIntPtr(e, &value);
5904 FreeExpContents(exp);
5905 exp.constant = PrintUInt64((uint64)value);
5906 exp.type = constantExp;
5913 GetIntSize(e, &value);
5914 FreeExpContents(exp);
5915 exp.constant = PrintInt64((int64)value);
5916 exp.type = constantExp;
5921 GetUIntSize(e, &value);
5922 FreeExpContents(exp);
5923 exp.constant = PrintUInt64((uint64)value);
5924 exp.type = constantExp;
5930 GetFloat(e, &value);
5931 FreeExpContents(exp);
5932 exp.constant = PrintFloat(value);
5933 exp.type = constantExp;
5939 GetDouble(e, &value);
5940 FreeExpContents(exp);
5941 exp.constant = PrintDouble(value);
5942 exp.type = constantExp;
5956 // Caring only about last expression for now...
5957 ComputeExpression(exp.cond.exp->last);
5958 if(exp.cond.elseExp)
5959 ComputeExpression(exp.cond.elseExp);
5961 ComputeExpression(exp.cond.cond);
5963 op1 = GetOperand(exp.cond.cond);
5964 if(op1.type) op1.type.refCount++;
5965 op2 = GetOperand(exp.cond.exp->last);
5966 if(op2.type) op2.type.refCount++;
5967 op3 = GetOperand(exp.cond.elseExp);
5968 if(op3.type) op3.type.refCount++;
5970 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
5971 if(op1.type) FreeType(op1.type);
5972 if(op2.type) FreeType(op2.type);
5973 if(op3.type) FreeType(op3.type);
5979 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
5984 OldList converts { };
5987 if(destType.kind == voidType)
5990 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
5994 // for(convert = converts.last; convert; convert = convert.prev)
5995 for(convert = converts.first; convert; convert = convert.next)
5997 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6000 Expression newExp { };
6001 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6003 // TODO: Check this...
6005 newExp.destType = null;
6010 exp.type = memberExp;
6011 exp.addedThis = true;
6012 exp.member.exp = newExp;
6013 FreeType(exp.member.exp.expType);
6015 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6016 exp.member.exp.expType.classObjectType = objectType;
6017 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6018 exp.member.memberType = propertyMember;
6019 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6020 // TESTING THIS... for (int)degrees
6021 exp.needCast = true;
6022 if(exp.expType) exp.expType.refCount++;
6023 ApplyAnyObjectLogic(exp.member.exp);
6028 /*if(exp.isConstant)
6030 // Color { ColorRGB = [exp] };
6031 exp.type = instanceExp;
6032 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6033 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6034 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6038 // If not constant, don't turn it yet into an instantiation
6039 // (Go through the deep members system first)
6040 exp.type = memberExp;
6041 exp.addedThis = true;
6042 exp.member.exp = newExp;
6044 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6045 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6046 newExp.expType._class.registered.type == noHeadClass)
6048 newExp.byReference = true;
6051 FreeType(exp.member.exp.expType);
6052 /*exp.member.exp.expType = convert.convert.dataType;
6053 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6054 exp.member.exp.expType = null;
6055 if(convert.convert.dataType)
6057 exp.member.exp.expType = { };
6058 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6059 exp.member.exp.expType.refCount = 1;
6060 exp.member.exp.expType.classObjectType = objectType;
6061 ApplyAnyObjectLogic(exp.member.exp);
6064 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6065 exp.member.memberType = reverseConversionMember;
6066 exp.expType = convert.resultType ? convert.resultType :
6067 MkClassType(convert.convert._class.fullName);
6068 exp.needCast = true;
6069 if(convert.resultType) convert.resultType.refCount++;
6075 FreeType(exp.expType);
6078 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6079 exp.needCast = true;
6080 if(exp.expType) exp.expType.refCount++;
6084 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6085 exp.needCast = true;
6086 if(convert.resultType)
6087 convert.resultType.refCount++;
6091 if(exp.isConstant && inCompiler)
6092 ComputeExpression(exp);
6094 converts.Free(FreeConvert);
6097 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6099 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6101 if(!result && exp.expType && exp.destType)
6103 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6104 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6105 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6106 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6110 // if(result) CheckTemplateTypes(exp);
6114 void CheckTemplateTypes(Expression exp)
6116 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6118 Expression newExp { };
6122 if(exp.destType) exp.destType.refCount++;
6123 if(exp.expType) exp.expType.refCount++;
6127 switch(exp.expType.kind)
6130 if(exp.destType.classObjectType)
6132 // We need to pass the address, just pass it along (Undo what was done above)
6133 if(exp.destType) exp.destType.refCount--;
6134 if(exp.expType) exp.expType.refCount--;
6139 // If we're looking for value:
6140 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6142 OldList * unionDefs = MkList();
6143 OldList * statements = MkList();
6144 context = PushContext();
6145 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6146 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6147 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6148 exp.type = extensionCompoundExp;
6149 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6150 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6151 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6152 exp.compound.compound.context = context;
6153 PopContext(context);
6158 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6159 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6163 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6165 Expression newExp { };
6169 if(exp.destType) exp.destType.refCount++;
6170 if(exp.expType) exp.expType.refCount++;
6174 switch(exp.expType.kind)
6177 if(exp.destType.classObjectType)
6179 // We need to pass the address, just pass it along (Undo what was done above)
6180 if(exp.destType) exp.destType.refCount--;
6181 if(exp.expType) exp.expType.refCount--;
6186 // If we're looking for value:
6187 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6189 OldList * unionDefs = MkList();
6190 OldList * statements = MkList();
6191 context = PushContext();
6192 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6193 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6194 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6195 exp.type = extensionCompoundExp;
6196 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6197 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6198 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6199 exp.compound.compound.context = context;
6200 PopContext(context);
6205 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6207 exp.type = bracketsExp;
6208 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6209 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6210 ProcessExpressionType(exp.list->first);
6215 exp.type = bracketsExp;
6216 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6217 newExp.needCast = true;
6218 ProcessExpressionType(exp.list->first);
6224 if(exp.expType.kind == templateType)
6226 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6229 FreeType(exp.destType);
6230 FreeType(exp.expType);
6235 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6240 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6241 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6245 char typeString[1024];
6247 OldList * specs = MkList();
6248 typeString[0] = '\0';
6249 PrintType(exp.expType, typeString, false, false);
6250 decl = SpecDeclFromString(typeString, specs, null);
6253 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6254 exp.cast.typeName = MkTypeName(specs, decl);
6255 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6256 exp.cast.exp.needCast = true;
6263 // TODO: The Symbol tree should be reorganized by namespaces
6265 // - Tree of all symbols within (stored without namespace)
6266 // - Tree of sub-namespaces
6268 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6270 int nsLen = strlen(nameSpace);
6272 // Start at the name space prefix
6273 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6275 char * s = symbol.string;
6276 if(!strncmp(s, nameSpace, nsLen))
6278 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6281 for(c = strlen(s)-1; c >= 0; c--)
6286 if(!strcmp(namePart, name))
6288 // TODO: Error on ambiguity
6298 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6301 char nameSpace[1024];
6303 bool gotColon = false;
6305 nameSpace[0] = '\0';
6306 for(c = strlen(name)-1; c >= 0; c--)
6313 namePart = name+c+1;
6314 while(c >= 0 && name[c] == ':') c--;
6317 // Try an exact match first
6318 Symbol symbol = (Symbol)tree.FindString(name);
6322 // Namespace specified
6323 memcpy(nameSpace, name, c + 1);
6326 return ScanWithNameSpace(tree, nameSpace, namePart);
6330 // Looking for a global symbol, e.g. ::Sleep()
6331 Symbol symbol = (Symbol)tree.FindString(namePart);
6336 // Name only (no namespace specified)
6337 Symbol symbol = (Symbol)tree.FindString(namePart);
6340 return ScanWithNameSpace(tree, "", namePart);
6345 static void ProcessDeclaration(Declaration decl);
6347 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6350 //Time startTime = GetTime();
6352 // Optimize this later? Do this before/less?
6354 Symbol symbol = null;
6355 // First, check if the identifier is declared inside the function
6356 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6358 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6360 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6366 strcpy(curName, thisNameSpace);
6367 strcat(curName, "::");
6368 strcat(curName, name);
6369 // Try to resolve in current namespace first
6370 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6373 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6376 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6378 if(symbol || ctx == endContext) break;
6380 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6382 if(symbol.pointerExternal.type == functionExternal)
6384 FunctionDefinition function = symbol.pointerExternal.function;
6386 // Modified this recently...
6387 Context tmpContext = curContext;
6389 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6390 curContext = tmpContext;
6392 symbol.pointerExternal.symbol = symbol;
6395 DeclareType(symbol.type, true, true);
6397 ast->Insert(curExternal.prev, symbol.pointerExternal);
6399 symbol.id = curExternal.symbol.idCode;
6402 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6404 ast->Move(symbol.pointerExternal, curExternal.prev);
6405 symbol.id = curExternal.symbol.idCode;
6409 //findSymbolTotalTime += GetTime() - startTime;
6414 static void GetTypeSpecs(Type type, OldList * specs)
6416 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6421 if(type._class.registered)
6423 if(!type._class.registered.dataType)
6424 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6425 GetTypeSpecs(type._class.registered.dataType, specs);
6429 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6430 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6431 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6432 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6433 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6434 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6435 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6436 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6439 ListAdd(specs, MkSpecifier(INT)); break;
6443 static void PrintArraySize(Type arrayType, char * string)
6448 if(arrayType.enumClass)
6449 strcat(size, arrayType.enumClass.string);
6450 else if(arrayType.arraySizeExp)
6451 PrintExpression(arrayType.arraySizeExp, size);
6453 strcat(string, size);
6456 // WARNING : This function expects a null terminated string since it recursively concatenate...
6457 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6461 if(printConst && type.constant)
6462 strcat(string, "const ");
6467 Symbol c = type._class;
6468 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6469 // look into merging with thisclass ?
6470 if(type.classObjectType == typedObject)
6471 strcat(string, "typed_object");
6472 else if(type.classObjectType == anyObject)
6473 strcat(string, "any_object");
6477 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6479 if(type.byReference)
6480 strcat(string, " &");
6483 case voidType: strcat(string, "void"); break;
6484 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6485 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6486 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6487 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6488 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6489 case _BoolType: strcat(string, "_Bool"); break;
6490 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6491 case floatType: strcat(string, "float"); break;
6492 case doubleType: strcat(string, "double"); break;
6496 strcat(string, "struct ");
6497 strcat(string, type.enumName);
6499 else if(type.typeName)
6500 strcat(string, type.typeName);
6504 strcat(string, "struct { ");
6505 for(member = type.members.first; member; member = member.next)
6507 PrintType(member, string, true, fullName);
6508 strcat(string,"; ");
6516 strcat(string, "union ");
6517 strcat(string, type.enumName);
6519 else if(type.typeName)
6520 strcat(string, type.typeName);
6523 strcat(string, "union ");
6524 strcat(string,"(unnamed)");
6530 strcat(string, "enum ");
6531 strcat(string, type.enumName);
6533 else if(type.typeName)
6534 strcat(string, type.typeName);
6536 strcat(string, "int"); // "enum");
6539 strcat(string, "...");
6542 strcat(string, "subclass(");
6543 strcat(string, type._class ? type._class.string : "int");
6544 strcat(string, ")");
6547 strcat(string, type.templateParameter.identifier.string);
6550 strcat(string, "thisclass");
6553 strcat(string, "__builtin_va_list");
6559 static void PrintName(Type type, char * string, bool fullName)
6561 if(type.name && type.name[0])
6564 strcat(string, type.name);
6567 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6568 if(name) name += 2; else name = type.name;
6569 strcat(string, name);
6574 static void PrintAttribs(Type type, char * string)
6578 if(type.dllExport) strcat(string, "dllexport ");
6579 if(type.attrStdcall) strcat(string, "stdcall ");
6583 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
6585 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6587 Type attrType = null;
6588 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
6589 PrintAttribs(type, string);
6590 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
6591 strcat(string, " const");
6592 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
6593 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6594 strcat(string, " (");
6595 if(type.kind == pointerType)
6597 if(type.type.kind == functionType || type.type.kind == methodType)
6598 PrintAttribs(type.type, string);
6600 if(type.kind == pointerType)
6602 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
6603 strcat(string, "*");
6605 strcat(string, " *");
6607 if(printConst && type.constant && type.kind == pointerType)
6608 strcat(string, " const");
6611 PrintTypeSpecs(type, string, fullName, printConst);
6614 static void PostPrintType(Type type, char * string, bool fullName)
6616 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6617 strcat(string, ")");
6618 if(type.kind == arrayType)
6619 PrintArraySize(type, string);
6620 else if(type.kind == functionType)
6623 strcat(string, "(");
6624 for(param = type.params.first; param; param = param.next)
6626 PrintType(param, string, true, fullName);
6627 if(param.next) strcat(string, ", ");
6629 strcat(string, ")");
6631 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6632 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
6636 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6638 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
6640 PrePrintType(type, string, fullName, null, printConst);
6642 if(type.thisClass || (printName && type.name && type.name[0]))
6643 strcat(string, " ");
6644 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
6646 Symbol _class = type.thisClass;
6647 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
6649 if(type.classObjectType == classPointer)
6650 strcat(string, "class");
6652 strcat(string, type.byReference ? "typed_object&" : "typed_object");
6654 else if(_class && _class.string)
6656 String s = _class.string;
6661 char * name = RSearchString(s, "::", strlen(s), true, false);
6662 if(name) name += 2; else name = s;
6663 strcat(string, name);
6666 strcat(string, "::");
6669 if(printName && type.name)
6670 PrintName(type, string, fullName);
6671 PostPrintType(type, string, fullName);
6672 if(type.bitFieldCount)
6675 sprintf(count, ":%d", type.bitFieldCount);
6676 strcat(string, count);
6680 void PrintType(Type type, char * string, bool printName, bool fullName)
6682 _PrintType(type, string, printName, fullName, true);
6685 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
6687 _PrintType(type, string, printName, fullName, false);
6690 static Type FindMember(Type type, char * string)
6693 for(memberType = type.members.first; memberType; memberType = memberType.next)
6695 if(!memberType.name)
6697 Type subType = FindMember(memberType, string);
6701 else if(!strcmp(memberType.name, string))
6707 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6710 for(memberType = type.members.first; memberType; memberType = memberType.next)
6712 if(!memberType.name)
6714 Type subType = FindMember(memberType, string);
6717 *offset += memberType.offset;
6721 else if(!strcmp(memberType.name, string))
6723 *offset += memberType.offset;
6730 Expression ParseExpressionString(char * expression)
6732 fileInput = TempFile { };
6733 fileInput.Write(expression, 1, strlen(expression));
6734 fileInput.Seek(0, start);
6737 parsedExpression = null;
6739 expression_yyparse();
6742 return parsedExpression;
6745 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6747 Identifier id = exp.identifier;
6748 Method method = null;
6749 Property prop = null;
6750 DataMember member = null;
6751 ClassProperty classProp = null;
6753 if(_class && _class.type == enumClass)
6755 NamedLink value = null;
6756 Class enumClass = eSystem_FindClass(privateModule, "enum");
6760 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6762 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6763 for(value = e.values.first; value; value = value.next)
6765 if(!strcmp(value.name, id.string))
6772 FreeExpContents(exp);
6774 exp.type = constantExp;
6775 exp.isConstant = true;
6776 if(!strcmp(baseClass.dataTypeString, "int"))
6777 sprintf(constant, "%d",(int)value.data);
6779 sprintf(constant, "0x%X",(int)value.data);
6780 exp.constant = CopyString(constant);
6781 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6782 exp.expType = MkClassType(baseClass.fullName);
6790 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6792 ProcessMethodType(method);
6799 // TOCHECK: Put it back to what it was...
6800 // methodClass = _class;
6801 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6806 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
6809 ProcessPropertyType(prop);
6810 exp.expType = prop.dataType;
6811 if(prop.dataType) prop.dataType.refCount++;
6814 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
6816 if(!member.dataType)
6817 member.dataType = ProcessTypeString(member.dataTypeString, false);
6818 exp.expType = member.dataType;
6819 if(member.dataType) member.dataType.refCount++;
6822 else if((classProp = eClass_FindClassProperty(_class, id.string)))
6824 if(!classProp.dataType)
6825 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
6827 if(classProp.constant)
6829 FreeExpContents(exp);
6831 exp.isConstant = true;
6832 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
6834 //char constant[256];
6835 exp.type = stringExp;
6836 exp.constant = QMkString((char *)classProp.Get(_class));
6841 exp.type = constantExp;
6842 sprintf(constant, "%d", (int)classProp.Get(_class));
6843 exp.constant = CopyString(constant);
6851 exp.expType = classProp.dataType;
6852 if(classProp.dataType) classProp.dataType.refCount++;
6858 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
6860 BinaryTree * tree = &nameSpace.functions;
6861 GlobalData data = (GlobalData)tree->FindString(name);
6865 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
6867 data = ScanGlobalData(child, name);
6875 static GlobalData FindGlobalData(char * name)
6878 NameSpace * nameSpace;
6879 nameSpace = globalData;
6880 for(c = 0; name[c]; c++)
6882 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
6884 NameSpace * newSpace;
6885 char * spaceName = new char[c - start + 1];
6886 strncpy(spaceName, name + start, c - start);
6887 spaceName[c-start] = '\0';
6888 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
6892 nameSpace = newSpace;
6893 if(name[c] == ':') c++;
6899 return ScanGlobalData(nameSpace, name + start);
6904 static int definedExpStackPos;
6905 static void * definedExpStack[512];
6907 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
6908 void ReplaceExpContents(Expression checkedExp, Expression newExp)
6910 Expression prev = checkedExp.prev, next = checkedExp.next;
6912 FreeExpContents(checkedExp);
6913 FreeType(checkedExp.expType);
6914 FreeType(checkedExp.destType);
6916 *checkedExp = *newExp;
6920 checkedExp.prev = prev;
6921 checkedExp.next = next;
6924 void ApplyAnyObjectLogic(Expression e)
6926 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
6928 char debugExpString[4096];
6929 debugExpString[0] = '\0';
6930 PrintExpression(e, debugExpString);
6933 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
6935 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
6936 //ellipsisDestType = destType;
6939 Type type = e.expType;
6940 Class _class = null;
6941 //Type destType = e.destType;
6943 if(type.kind == classType && type._class && type._class.registered)
6945 _class = type._class.registered;
6947 else if(type.kind == subClassType)
6949 _class = FindClass("ecere::com::Class").registered;
6953 char string[1024] = "";
6956 PrintTypeNoConst(type, string, false, true);
6957 classSym = FindClass(string);
6958 if(classSym) _class = classSym.registered;
6961 if((_class && (_class.type == enumClass || _class.type == unitClass || _class.type == bitClass || _class.type == systemClass) && strcmp(_class.fullName, "class") && strcmp(_class.fullName, "uintptr") && strcmp(_class.fullName, "intptr")) || // Patched so that class isn't considered SYSTEM...
6962 (!e.expType.classObjectType && (((type.kind != pointerType && type.kind != intPtrType && type.kind != subClassType && (type.kind != classType || !type._class || !type._class.registered || type._class.registered.type == structClass))) ||
6963 destType.byReference)))
6965 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
6967 Expression checkedExp = e, newExp;
6969 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6971 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6973 if(checkedExp.type == extensionCompoundExp)
6975 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6978 checkedExp = checkedExp.list->last;
6980 else if(checkedExp.type == castExp)
6981 checkedExp = checkedExp.cast.exp;
6984 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
6986 newExp = checkedExp.op.exp2;
6987 checkedExp.op.exp2 = null;
6988 FreeExpContents(checkedExp);
6990 if(e.expType && e.expType.passAsTemplate)
6993 ComputeTypeSize(e.expType);
6994 sprintf(size, "%d", e.expType.size);
6995 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
6996 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
6997 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7000 ReplaceExpContents(checkedExp, newExp);
7001 e.byReference = true;
7003 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7005 Expression checkedExp, newExp;
7008 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7010 e.type == identifierExp ||
7011 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7012 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7013 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7016 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7018 Context context = PushContext();
7020 OldList * specs = MkList();
7021 char typeString[1024];
7022 Expression newExp { };
7024 typeString[0] = '\0';
7027 //if(e.destType) e.destType.refCount++;
7028 // if(exp.expType) exp.expType.refCount++;
7031 newExp.expType = null;
7033 PrintTypeNoConst(e.expType, typeString, false, true);
7034 decl = SpecDeclFromString(typeString, specs, null);
7035 newExp.destType = ProcessType(specs, decl);
7037 curContext = context;
7039 // We need a current compound for this
7043 OldList * stmts = MkList();
7044 e.type = extensionCompoundExp;
7045 sprintf(name, "__internalValue%03X", internalValueCounter++);
7046 if(!curCompound.compound.declarations)
7047 curCompound.compound.declarations = MkList();
7048 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7049 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7050 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7051 e.compound = MkCompoundStmt(null, stmts);
7054 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7057 e.compound = MkCompoundStmt(
7058 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7059 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7061 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7065 Type type = e.destType;
7067 CopyTypeInto(e.destType, type);
7068 e.destType.refCount = 1;
7069 e.destType.classObjectType = none;
7073 e.compound.compound.context = context;
7074 PopContext(context);
7075 curContext = context.parent;
7079 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7081 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7083 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7085 if(checkedExp.type == extensionCompoundExp)
7087 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7090 checkedExp = checkedExp.list->last;
7092 else if(checkedExp.type == castExp)
7093 checkedExp = checkedExp.cast.exp;
7096 Expression operand { };
7097 operand = *checkedExp;
7098 checkedExp.destType = null;
7099 checkedExp.expType = null;
7101 checkedExp.type = opExp;
7102 checkedExp.op.op = '&';
7103 checkedExp.op.exp1 = null;
7104 checkedExp.op.exp2 = operand;
7106 //newExp = MkExpOp(null, '&', checkedExp);
7108 //ReplaceExpContents(checkedExp, newExp);
7115 // If expression type is a simple class, make it an address
7116 // FixReference(e, true);
7119 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7120 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7121 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7123 if(e.expType.classObjectType && destType && destType.classObjectType) //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class"))
7125 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7129 Expression thisExp { };
7132 thisExp.prev = null;
7133 thisExp.next = null;
7136 e.type = bracketsExp;
7137 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7138 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7139 ((Expression)e.list->first).byReference = true;
7141 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7143 e.expType = thisExp.expType;
7144 e.expType.refCount++;
7149 CopyTypeInto(e.expType, thisExp.expType);
7150 e.expType.byReference = false;
7151 e.expType.refCount = 1;
7153 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7154 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7156 e.expType.classObjectType = none;
7161 // TOFIX: Try this for a nice IDE crash!
7163 // The other way around
7166 if(destType && e.expType &&
7167 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7168 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7169 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7171 if(destType.kind == ellipsisType)
7173 Compiler_Error($"Unspecified type\n");
7175 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7177 bool byReference = e.expType.byReference;
7178 Expression thisExp { };
7180 OldList * specs = MkList();
7181 char typeString[1024]; // Watch buffer overruns
7183 ClassObjectType backupClassObjectType;
7184 bool backupByReference;
7186 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7191 backupClassObjectType = type.classObjectType;
7192 backupByReference = type.byReference;
7194 type.classObjectType = none;
7195 type.byReference = false;
7197 typeString[0] = '\0';
7198 PrintType(type, typeString, false, true);
7199 decl = SpecDeclFromString(typeString, specs, null);
7201 type.classObjectType = backupClassObjectType;
7202 type.byReference = backupByReference;
7205 thisExp.prev = null;
7206 thisExp.next = null;
7209 if( ( type.kind == classType && type._class && type._class.registered &&
7210 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7211 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7212 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7213 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7218 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7221 CopyTypeInto(e.expType, type);
7222 e.expType.byReference = false;
7223 e.expType.refCount = 1;
7228 e.cast.typeName = MkTypeName(specs, decl);
7229 e.cast.exp = thisExp;
7230 e.byReference = true;
7234 e.destType = destType;
7235 destType.refCount++;
7240 void ProcessExpressionType(Expression exp)
7242 bool unresolved = false;
7243 Location oldyylloc = yylloc;
7244 bool notByReference = false;
7246 char debugExpString[4096];
7247 debugExpString[0] = '\0';
7248 PrintExpression(exp, debugExpString);
7250 if(!exp || exp.expType)
7253 //eSystem_Logf("%s\n", expString);
7255 // Testing this here
7261 Identifier id = exp.identifier;
7264 // DOING THIS LATER NOW...
7265 if(id._class && id._class.name)
7267 id.classSym = id._class.symbol; // FindClass(id._class.name);
7268 /* TODO: Name Space Fix ups
7270 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7274 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7276 exp.expType = ProcessTypeString("Module", true);
7279 else */if(strstr(id.string, "__ecereClass") == id.string)
7281 exp.expType = ProcessTypeString("ecere::com::Class", true);
7284 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7286 // Added this here as well
7287 ReplaceClassMembers(exp, thisClass);
7288 if(exp.type != identifierExp)
7290 ProcessExpressionType(exp);
7294 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7299 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7300 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7301 if(!symbol/* && exp.destType*/)
7303 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7309 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7310 if(exp.type != identifierExp)
7312 ProcessExpressionType(exp);
7316 // Static methods called from inside the _class
7317 else if(currentClass && !id._class)
7319 if(ResolveIdWithClass(exp, currentClass, true))
7322 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7326 // If we manage to resolve this symbol
7329 Type type = symbol.type;
7330 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7332 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7334 Context context = SetupTemplatesContext(_class);
7335 type = ReplaceThisClassType(_class);
7336 FinishTemplatesContext(context);
7337 if(type) type.refCount = 0; // We'll be incrementing it right below...
7340 FreeSpecifier(id._class);
7343 id.string = CopyString(symbol.string);
7349 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7350 // Add missing cases here... enum Classes...
7351 exp.isConstant = true;
7353 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7354 if(symbol.isParam || !strcmp(id.string, "this"))
7356 if(_class && _class.type == structClass && !type.declaredWithStruct)
7357 exp.byReference = true;
7359 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7360 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7361 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7362 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7364 Identifier id = exp.identifier;
7365 exp.type = bracketsExp;
7366 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7370 if(symbol.isIterator)
7372 if(symbol.isIterator == 3)
7374 exp.type = bracketsExp;
7375 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7376 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7378 ProcessExpressionType(exp);
7380 else if(symbol.isIterator != 4)
7382 exp.type = memberExp;
7383 exp.member.exp = MkExpIdentifier(exp.identifier);
7384 exp.member.exp.expType = exp.expType;
7385 /*if(symbol.isIterator == 6)
7386 exp.member.member = MkIdentifier("key");
7388 exp.member.member = MkIdentifier("data");
7390 ProcessExpressionType(exp);
7397 DefinedExpression definedExp = null;
7398 if(thisNameSpace && !(id._class && !id._class.name))
7401 strcpy(name, thisNameSpace);
7403 strcat(name, id.string);
7404 definedExp = eSystem_FindDefine(privateModule, name);
7407 definedExp = eSystem_FindDefine(privateModule, id.string);
7411 for(c = 0; c<definedExpStackPos; c++)
7412 if(definedExpStack[c] == definedExp)
7414 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7416 Location backupYylloc = yylloc;
7417 definedExpStack[definedExpStackPos++] = definedExp;
7418 fileInput = TempFile { };
7419 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7420 fileInput.Seek(0, start);
7423 parsedExpression = null;
7425 expression_yyparse();
7428 yylloc = backupYylloc;
7430 if(parsedExpression)
7433 exp.type = bracketsExp;
7434 exp.list = MkListOne(parsedExpression);
7435 parsedExpression.loc = yylloc;
7436 ProcessExpressionType(exp);
7437 definedExpStackPos--;
7440 definedExpStackPos--;
7446 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7452 GlobalData data = null;
7453 if(thisNameSpace && !(id._class && !id._class.name))
7456 strcpy(name, thisNameSpace);
7458 strcat(name, id.string);
7459 data = FindGlobalData(name);
7462 data = FindGlobalData(id.string);
7465 DeclareGlobalData(data);
7466 exp.expType = data.dataType;
7467 if(data.dataType) data.dataType.refCount++;
7470 id.string = CopyString(data.fullName);
7471 FreeSpecifier(id._class);
7478 GlobalFunction function = null;
7479 if(thisNameSpace && !(id._class && !id._class.name))
7482 strcpy(name, thisNameSpace);
7484 strcat(name, id.string);
7485 function = eSystem_FindFunction(privateModule, name);
7488 function = eSystem_FindFunction(privateModule, id.string);
7493 id.string = CopyString(function.name);
7496 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7497 strcpy(name, "__ecereFunction_");
7498 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7499 if(DeclareFunction(function, name))
7502 id.string = CopyString(name);
7504 exp.expType = function.dataType;
7505 if(function.dataType) function.dataType.refCount++;
7507 FreeSpecifier(id._class);
7524 if(!exp.instance._class)
7526 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7528 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7532 //classSym = FindClass(exp.instance._class.fullName);
7533 //_class = classSym ? classSym.registered : null;
7535 ProcessInstantiationType(exp.instance);
7536 exp.isConstant = exp.instance.isConstant;
7539 if(_class.type == unitClass && _class.base.type != systemClass)
7542 Type destType = exp.destType;
7544 exp.destType = MkClassType(_class.base.fullName);
7545 exp.expType = MkClassType(_class.fullName);
7546 CheckExpressionType(exp, exp.destType, true);
7548 exp.destType = destType;
7550 exp.expType = MkClassType(_class.fullName);
7553 if(exp.instance._class)
7555 exp.expType = MkClassType(exp.instance._class.name);
7556 /*if(exp.expType._class && exp.expType._class.registered &&
7557 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7558 exp.expType.byReference = true;*/
7566 char * constant = exp.constant;
7574 if(constant[0] == '\'')
7576 if((int)((byte *)constant)[1] > 127)
7579 unichar ch = UTF8GetChar(constant + 1, &nb);
7580 if(nb < 2) ch = constant[1];
7582 exp.constant = PrintUInt(ch);
7583 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7584 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7585 type._class = FindClass("unichar");
7587 type.isSigned = false;
7591 type.kind = charType;
7592 type.isSigned = true;
7597 char * dot = strchr(constant, '.');
7598 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
7602 exponent = strchr(constant, 'p');
7603 if(!exponent) exponent = strchr(constant, 'P');
7607 exponent = strchr(constant, 'e');
7608 if(!exponent) exponent = strchr(constant, 'E');
7613 if(strchr(constant, 'f') || strchr(constant, 'F'))
7614 type.kind = floatType;
7616 type.kind = doubleType;
7617 type.isSigned = true;
7621 bool isSigned = constant[0] == '-';
7622 int64 i64 = strtoll(constant, null, 0);
7623 uint64 ui64 = strtoull(constant, null, 0);
7624 bool is64Bit = false;
7637 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
7641 else if(constant[0] != '0' || !constant[1])
7644 type.kind = is64Bit ? int64Type : intType;
7645 type.isSigned = isSigned;
7648 exp.isConstant = true;
7649 if(exp.destType && exp.destType.kind == doubleType)
7650 type.kind = doubleType;
7651 else if(exp.destType && exp.destType.kind == floatType)
7652 type.kind = floatType;
7653 else if(exp.destType && exp.destType.kind == int64Type)
7654 type.kind = int64Type;
7660 exp.isConstant = true; // Why wasn't this constant?
7677 ProcessExpressionType(exp._new.size);
7682 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7684 DeclareType(exp.expType.type, false, false);
7688 ProcessExpressionType(exp._renew.size);
7689 ProcessExpressionType(exp._renew.exp);
7694 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7696 DeclareType(exp.expType.type, false, false);
7700 bool assign = false, boolResult = false, boolOps = false;
7701 Type type1 = null, type2 = null;
7702 bool useDestType = false, useSideType = false;
7703 Location oldyylloc = yylloc;
7704 bool useSideUnit = false;
7706 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7715 // Assignment Operators
7729 // boolean Operators
7731 // Expect boolean operators
7733 //boolResult = true;
7737 // Expect boolean operands
7748 // Gives boolean result
7756 // Just added these... testing
7761 // DANGER: Verify units
7766 if(exp.op.op != '*' || exp.op.exp1)
7773 /*// Implement speed etc.
7779 if(exp.op.op == '&')
7781 // Added this here earlier for Iterator address as key
7782 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7784 Identifier id = exp.op.exp2.identifier;
7785 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7786 if(symbol && symbol.isIterator == 2)
7788 exp.type = memberExp;
7789 exp.member.exp = exp.op.exp2;
7790 exp.member.member = MkIdentifier("key");
7792 exp.op.exp2.expType = symbol.type;
7793 symbol.type.refCount++;
7794 ProcessExpressionType(exp);
7798 // exp.op.exp2.usage.usageRef = true;
7802 //dummy.kind = TypeDummy;
7806 if(exp.destType && exp.destType.kind == classType &&
7807 exp.destType._class && exp.destType._class.registered && useDestType &&
7809 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
7810 exp.destType._class.registered.type == enumClass ||
7811 exp.destType._class.registered.type == bitClass
7814 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
7816 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7817 exp.op.exp1.destType = exp.destType;
7819 exp.destType.refCount++;
7823 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7824 exp.op.exp1.destType = dummy;
7828 // TESTING THIS HERE...
7829 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
7830 ProcessExpressionType(exp.op.exp1);
7831 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
7833 if(exp.op.exp1.destType == dummy)
7836 exp.op.exp1.destType = null;
7838 type1 = exp.op.exp1.expType;
7843 char expString[10240];
7844 expString[0] = '\0';
7845 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
7849 exp.op.exp2.destType = exp.op.exp1.expType;
7850 if(exp.op.exp1.expType)
7851 exp.op.exp1.expType.refCount++;
7855 exp.op.exp2.destType = exp.destType;
7857 exp.destType.refCount++;
7860 if(type1) type1.refCount++;
7861 exp.expType = type1;
7866 PrintExpression(exp.op.exp2, expString);
7868 if(type1 && type1.kind == pointerType)
7870 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 ||
7871 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
7872 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
7873 else if(exp.op.op == '=')
7875 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7876 exp.op.exp2.destType = type1;
7883 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
7884 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/* ||
7885 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
7888 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7889 exp.op.exp2.destType = type1;
7894 if(type1) type1.refCount++;
7895 exp.expType = type1;
7897 else if(exp.destType && exp.destType.kind == classType &&
7898 exp.destType._class && exp.destType._class.registered &&
7900 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
7901 (exp.destType._class.registered.type == enumClass && useDestType))
7904 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7905 exp.op.exp2.destType = exp.destType;
7907 exp.destType.refCount++;
7911 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7912 exp.op.exp2.destType = dummy;
7916 // TESTING THIS HERE... (DANGEROUS)
7917 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
7918 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
7920 FreeType(exp.op.exp2.destType);
7921 exp.op.exp2.destType = type1;
7924 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
7925 ProcessExpressionType(exp.op.exp2);
7926 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
7928 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
7930 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)
7932 if(exp.op.op != '=' && type1.type.kind == voidType)
7933 Compiler_Error($"void *: unknown size\n");
7935 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||
7936 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
7937 (exp.op.exp2.expType._class.registered.type == normalClass ||
7938 exp.op.exp2.expType._class.registered.type == structClass ||
7939 exp.op.exp2.expType._class.registered.type == noHeadClass)))
7941 if(exp.op.op == ADD_ASSIGN)
7942 Compiler_Error($"cannot add two pointers\n");
7944 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
7945 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
7947 if(exp.op.op == ADD_ASSIGN)
7948 Compiler_Error($"cannot add two pointers\n");
7952 char type1String[1024];
7953 char type2String[1024];
7954 type1String[0] = '\0';
7955 type2String[0] = '\0';
7957 PrintType(exp.op.exp2.expType, type1String, false, true);
7958 PrintType(type1, type2String, false, true);
7959 ChangeCh(expString, '\n', ' ');
7960 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
7964 if(exp.op.exp2.destType == dummy)
7967 exp.op.exp2.destType = null;
7970 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
7974 CopyTypeInto(type2, exp.op.exp2.expType);
7975 type2.isSigned = true;
7977 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
7979 type2 = { kind = intType };
7981 type2.isSigned = true;
7984 type2 = exp.op.exp2.expType;
7987 dummy.kind = voidType;
7989 if(exp.op.op == SIZEOF)
7996 exp.isConstant = true;
7998 // Get type of dereferenced pointer
7999 else if(exp.op.op == '*' && !exp.op.exp1)
8001 exp.expType = Dereference(type2);
8002 if(type2 && type2.kind == classType)
8003 notByReference = true;
8005 else if(exp.op.op == '&' && !exp.op.exp1)
8006 exp.expType = Reference(type2);
8013 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8014 exp.op.exp1.destType = MkClassType("bool");
8015 exp.op.exp1.destType.truth = true;
8016 if(!exp.op.exp1.expType)
8017 ProcessExpressionType(exp.op.exp1);
8019 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8020 FreeType(exp.op.exp1.expType);
8021 exp.op.exp1.expType = MkClassType("bool");
8022 exp.op.exp1.expType.truth = true;
8026 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8027 exp.op.exp2.destType = MkClassType("bool");
8028 exp.op.exp2.destType.truth = true;
8029 if(!exp.op.exp2.expType)
8030 ProcessExpressionType(exp.op.exp2);
8032 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8033 FreeType(exp.op.exp2.expType);
8034 exp.op.exp2.expType = MkClassType("bool");
8035 exp.op.exp2.expType.truth = true;
8038 else if(exp.op.exp1 && exp.op.exp2 &&
8041 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8042 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8043 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8044 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8046 if(type1 && type2 &&
8047 // If either both are class or both are not class
8048 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8050 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8051 exp.op.exp2.destType = type1;
8053 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8054 exp.op.exp1.destType = type2;
8056 // Warning here for adding Radians + Degrees with no destination type
8057 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8058 type1._class.registered && type1._class.registered.type == unitClass &&
8059 type2._class.registered && type2._class.registered.type == unitClass &&
8060 type1._class.registered != type2._class.registered)
8061 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8062 type1._class.string, type2._class.string, type1._class.string);
8064 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8066 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8069 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8071 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8072 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8075 ProcessExpressionType(exp.op.exp1);
8077 if(type2.kind != pointerType)
8079 ProcessExpressionType(classExp);
8081 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8082 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8083 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8085 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8088 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8089 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8090 MkPointer(null, null), null)))),
8091 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8093 if(!exp.op.exp2.expType)
8094 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8096 ProcessExpressionType(exp.op.exp2);
8101 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)))
8103 if(type1.kind != classType && type1.type.kind == voidType)
8104 Compiler_Error($"void *: unknown size\n");
8105 exp.expType = type1;
8106 if(type1) type1.refCount++;
8108 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)))
8110 if(type2.kind != classType && type2.type.kind == voidType)
8111 Compiler_Error($"void *: unknown size\n");
8112 exp.expType = type2;
8113 if(type2) type2.refCount++;
8115 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8116 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8118 Compiler_Warning($"different levels of indirection\n");
8122 bool success = false;
8123 if(type1.kind == pointerType && type2.kind == pointerType)
8125 if(exp.op.op == '+')
8126 Compiler_Error($"cannot add two pointers\n");
8127 else if(exp.op.op == '-')
8129 // Pointer Subtraction gives integer
8130 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8139 if(type1.type.kind == templateType)
8141 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8144 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8146 ProcessExpressionType(classExp);
8148 exp.type = bracketsExp;
8149 exp.list = MkListOne(MkExpOp(
8150 MkExpBrackets(MkListOne(MkExpOp(
8151 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8153 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8155 //MkExpMember(classExp, MkIdentifier("typeSize"))
8157 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8158 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8160 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8163 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8164 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8165 MkPointer(null, null), null)))),
8166 MkExpMember(classExp, MkIdentifier("typeSize")))))
8171 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8180 if(!success && exp.op.exp1.type == constantExp)
8182 // If first expression is constant, try to match that first
8183 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8185 if(exp.expType) FreeType(exp.expType);
8186 exp.expType = exp.op.exp1.destType;
8187 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8190 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8192 if(exp.expType) FreeType(exp.expType);
8193 exp.expType = exp.op.exp2.destType;
8194 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8200 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8202 if(exp.expType) FreeType(exp.expType);
8203 exp.expType = exp.op.exp2.destType;
8204 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8207 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8209 if(exp.expType) FreeType(exp.expType);
8210 exp.expType = exp.op.exp1.destType;
8211 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8217 char expString1[10240];
8218 char expString2[10240];
8221 expString1[0] = '\0';
8222 expString2[0] = '\0';
8227 PrintExpression(exp.op.exp1, expString1);
8228 ChangeCh(expString1, '\n', ' ');
8229 PrintExpression(exp.op.exp2, expString2);
8230 ChangeCh(expString2, '\n', ' ');
8231 PrintType(exp.op.exp1.expType, type1, false, true);
8232 PrintType(exp.op.exp2.expType, type2, false, true);
8235 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8239 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8240 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8242 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8243 // Convert e.g. / 4 into / 4.0
8244 exp.op.exp1.destType = type2._class.registered.dataType;
8245 if(type2._class.registered.dataType)
8246 type2._class.registered.dataType.refCount++;
8247 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8248 exp.expType = type2;
8249 if(type2) type2.refCount++;
8251 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8253 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8254 // Convert e.g. / 4 into / 4.0
8255 exp.op.exp2.destType = type1._class.registered.dataType;
8256 if(type1._class.registered.dataType)
8257 type1._class.registered.dataType.refCount++;
8258 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8259 exp.expType = type1;
8260 if(type1) type1.refCount++;
8266 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8268 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8270 if(!type1._class.registered.dataType)
8271 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8272 exp.op.exp2.destType = type1._class.registered.dataType;
8273 exp.op.exp2.destType.refCount++;
8275 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8276 type2 = exp.op.exp2.destType;
8278 exp.expType = type2;
8282 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8284 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8286 if(!type2._class.registered.dataType)
8287 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8288 exp.op.exp1.destType = type2._class.registered.dataType;
8289 exp.op.exp1.destType.refCount++;
8291 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8292 type1 = exp.op.exp1.destType;
8293 exp.expType = type1;
8297 // TESTING THIS NEW CODE
8298 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8300 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8302 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8304 if(exp.expType) FreeType(exp.expType);
8305 exp.expType = exp.op.exp1.expType;
8306 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8311 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8313 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8315 if(exp.expType) FreeType(exp.expType);
8316 exp.expType = exp.op.exp2.expType;
8317 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8325 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8326 exp.op.exp2.destType = type1;
8330 // Maybe this was meant to be an enum...
8331 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8333 Type oldType = exp.op.exp2.expType;
8334 exp.op.exp2.expType = null;
8335 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8338 exp.op.exp2.expType = oldType;
8343 // TESTING THIS HERE... LATEST ADDITION
8344 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8346 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8347 exp.op.exp2.destType = type2._class.registered.dataType;
8348 if(type2._class.registered.dataType)
8349 type2._class.registered.dataType.refCount++;
8350 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8352 //exp.expType = type2._class.registered.dataType; //type2;
8353 //if(type2) type2.refCount++;
8356 // TESTING THIS HERE... LATEST ADDITION
8357 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8359 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8360 exp.op.exp1.destType = type1._class.registered.dataType;
8361 if(type1._class.registered.dataType)
8362 type1._class.registered.dataType.refCount++;
8363 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8364 exp.expType = type1._class.registered.dataType; //type1;
8365 if(type1) type1.refCount++;
8369 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8371 if(exp.expType) FreeType(exp.expType);
8372 exp.expType = exp.op.exp2.destType;
8373 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8375 else if(type1 && type2)
8377 char expString1[10240];
8378 char expString2[10240];
8379 char type1String[1024];
8380 char type2String[1024];
8381 expString1[0] = '\0';
8382 expString2[0] = '\0';
8383 type1String[0] = '\0';
8384 type2String[0] = '\0';
8387 PrintExpression(exp.op.exp1, expString1);
8388 ChangeCh(expString1, '\n', ' ');
8389 PrintExpression(exp.op.exp2, expString2);
8390 ChangeCh(expString2, '\n', ' ');
8391 PrintType(exp.op.exp1.expType, type1String, false, true);
8392 PrintType(exp.op.exp2.expType, type2String, false, true);
8395 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8397 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8399 exp.expType = exp.op.exp1.expType;
8400 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8402 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8404 exp.expType = exp.op.exp2.expType;
8405 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8412 // Maybe this was meant to be an enum...
8413 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8415 Type oldType = exp.op.exp1.expType;
8416 exp.op.exp1.expType = null;
8417 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8420 exp.op.exp1.expType = oldType;
8423 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8424 exp.op.exp1.destType = type2;
8427 // TESTING THIS HERE... LATEST ADDITION
8428 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8430 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8431 exp.op.exp1.destType = type1._class.registered.dataType;
8432 if(type1._class.registered.dataType)
8433 type1._class.registered.dataType.refCount++;
8436 // TESTING THIS HERE... LATEST ADDITION
8437 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8439 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8440 exp.op.exp2.destType = type2._class.registered.dataType;
8441 if(type2._class.registered.dataType)
8442 type2._class.registered.dataType.refCount++;
8446 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8448 if(exp.expType) FreeType(exp.expType);
8449 exp.expType = exp.op.exp1.destType;
8450 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8454 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8456 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8458 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8459 // Convert e.g. / 4 into / 4.0
8460 exp.op.exp1.destType = type2._class.registered.dataType;
8461 if(type2._class.registered.dataType)
8462 type2._class.registered.dataType.refCount++;
8463 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8465 if(exp.op.op == '!')
8467 exp.expType = MkClassType("bool");
8468 exp.expType.truth = true;
8472 exp.expType = type2;
8473 if(type2) type2.refCount++;
8476 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8478 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8480 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8481 // Convert e.g. / 4 into / 4.0
8482 exp.op.exp2.destType = type1._class.registered.dataType;
8483 if(type1._class.registered.dataType)
8484 type1._class.registered.dataType.refCount++;
8485 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8487 exp.expType = type1;
8488 if(type1) type1.refCount++;
8493 if(exp.op.exp1 && !exp.op.exp1.expType)
8495 char expString[10000];
8496 expString[0] = '\0';
8499 PrintExpression(exp.op.exp1, expString);
8500 ChangeCh(expString, '\n', ' ');
8503 Compiler_Error($"couldn't determine type of %s\n", expString);
8505 if(exp.op.exp2 && !exp.op.exp2.expType)
8507 char expString[10240];
8508 expString[0] = '\0';
8511 PrintExpression(exp.op.exp2, expString);
8512 ChangeCh(expString, '\n', ' ');
8515 Compiler_Error($"couldn't determine type of %s\n", expString);
8520 FreeType(exp.expType);
8521 exp.expType = MkClassType("bool");
8522 exp.expType.truth = true;
8525 if(exp.op.op != SIZEOF)
8526 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8527 (!exp.op.exp2 || exp.op.exp2.isConstant);
8529 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8531 DeclareType(exp.op.exp2.expType, false, false);
8540 case extensionExpressionExp:
8543 exp.isConstant = true;
8544 for(e = exp.list->first; e; e = e.next)
8549 FreeType(e.destType);
8550 e.destType = exp.destType;
8551 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8553 ProcessExpressionType(e);
8555 exp.destType.count--;
8556 if(!exp.expType && !e.next)
8558 exp.expType = e.expType;
8559 if(e.expType) e.expType.refCount++;
8562 exp.isConstant = false;
8565 // In case a cast became a member...
8566 e = exp.list->first;
8567 if(!e.next && e.type == memberExp)
8569 // Preserve prev, next
8570 Expression next = exp.next, prev = exp.prev;
8573 FreeType(exp.expType);
8574 FreeType(exp.destType);
8584 ProcessExpressionType(exp);
8591 exp.isConstant = true;
8593 ProcessExpressionType(exp.index.exp);
8594 if(!exp.index.exp.isConstant)
8595 exp.isConstant = false;
8597 if(exp.index.exp.expType)
8599 Type source = exp.index.exp.expType;
8600 if(source.kind == classType && source._class && source._class.registered)
8602 Class _class = source._class.registered;
8603 Class c = _class.templateClass ? _class.templateClass : _class;
8604 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
8606 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8608 if(exp.index.index && exp.index.index->last)
8610 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8616 for(e = exp.index.index->first; e; e = e.next)
8618 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8620 if(e.destType) FreeType(e.destType);
8621 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8623 ProcessExpressionType(e);
8626 // Check if this type is int
8629 exp.isConstant = false;
8633 exp.expType = Dereference(exp.index.exp.expType);
8635 DeclareType(exp.expType, false, false);
8642 Type methodType = null;
8648 PrintExpression(exp.call.exp, name);
8649 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8651 //exp.call.exp.expType = null;
8652 PrintExpression(exp.call.exp, name);
8655 if(exp.call.exp.type == identifierExp)
8657 Expression idExp = exp.call.exp;
8658 Identifier id = idExp.identifier;
8659 if(!strcmp(id.string, "__builtin_frame_address"))
8661 exp.expType = ProcessTypeString("void *", true);
8662 if(exp.call.arguments && exp.call.arguments->first)
8663 ProcessExpressionType(exp.call.arguments->first);
8666 else if(!strcmp(id.string, "__ENDIAN_PAD"))
8668 exp.expType = ProcessTypeString("int", true);
8669 if(exp.call.arguments && exp.call.arguments->first)
8670 ProcessExpressionType(exp.call.arguments->first);
8673 else if(!strcmp(id.string, "Max") ||
8674 !strcmp(id.string, "Min") ||
8675 !strcmp(id.string, "Sgn") ||
8676 !strcmp(id.string, "Abs"))
8678 Expression a = null;
8679 Expression b = null;
8680 Expression tempExp1 = null, tempExp2 = null;
8681 if((!strcmp(id.string, "Max") ||
8682 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8684 a = exp.call.arguments->first;
8685 b = exp.call.arguments->last;
8689 else if(exp.call.arguments->count == 1)
8691 a = exp.call.arguments->first;
8697 exp.call.arguments->Clear();
8698 idExp.identifier = null;
8700 FreeExpContents(exp);
8702 ProcessExpressionType(a);
8704 ProcessExpressionType(b);
8706 exp.type = bracketsExp;
8707 exp.list = MkList();
8709 if(a.expType && (!b || b.expType))
8711 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8713 // Use the simpleStruct name/ids for now...
8716 OldList * specs = MkList();
8717 OldList * decls = MkList();
8719 char temp1[1024], temp2[1024];
8721 GetTypeSpecs(a.expType, specs);
8723 if(a && !a.isConstant && a.type != identifierExp)
8725 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8726 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8727 tempExp1 = QMkExpId(temp1);
8728 tempExp1.expType = a.expType;
8730 a.expType.refCount++;
8731 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8733 if(b && !b.isConstant && b.type != identifierExp)
8735 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8736 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8737 tempExp2 = QMkExpId(temp2);
8738 tempExp2.expType = b.expType;
8740 b.expType.refCount++;
8741 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8744 decl = MkDeclaration(specs, decls);
8745 if(!curCompound.compound.declarations)
8746 curCompound.compound.declarations = MkList();
8747 curCompound.compound.declarations->Insert(null, decl);
8752 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8754 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8756 MkExpCondition(MkExpBrackets(MkListOne(
8757 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8758 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8759 exp.expType = a.expType;
8761 a.expType.refCount++;
8763 else if(!strcmp(id.string, "Abs"))
8766 MkExpCondition(MkExpBrackets(MkListOne(
8767 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8768 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8769 exp.expType = a.expType;
8771 a.expType.refCount++;
8773 else if(!strcmp(id.string, "Sgn"))
8775 // ((!(a))?(0):(((a)<0)?(-1):(1)))
8777 MkExpCondition(MkExpBrackets(MkListOne(
8778 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
8779 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
8780 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8781 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
8782 exp.expType = ProcessTypeString("int", false);
8785 FreeExpression(tempExp1);
8786 if(tempExp2) FreeExpression(tempExp2);
8800 if(!exp.call.exp.destType)
8802 exp.call.exp.destType = dummy;
8805 ProcessExpressionType(exp.call.exp);
8806 if(exp.call.exp.destType == dummy)
8809 exp.call.exp.destType = null;
8814 // Check argument types against parameter types
8815 functionType = exp.call.exp.expType;
8817 if(functionType && functionType.kind == TypeKind::methodType)
8819 methodType = functionType;
8820 functionType = methodType.method.dataType;
8822 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
8823 // TOCHECK: Instead of doing this here could this be done per param?
8824 if(exp.call.exp.expType.usedClass)
8826 char typeString[1024];
8827 typeString[0] = '\0';
8829 Symbol back = functionType.thisClass;
8830 // Do not output class specifier here (thisclass was added to this)
8831 functionType.thisClass = null;
8832 PrintType(functionType, typeString, true, true);
8833 functionType.thisClass = back;
8835 if(strstr(typeString, "thisclass"))
8837 OldList * specs = MkList();
8840 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
8842 decl = SpecDeclFromString(typeString, specs, null);
8844 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
8845 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
8846 exp.call.exp.expType.usedClass))
8847 thisClassParams = false;
8849 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
8851 Class backupThisClass = thisClass;
8852 thisClass = exp.call.exp.expType.usedClass;
8853 ProcessDeclarator(decl);
8854 thisClass = backupThisClass;
8857 thisClassParams = true;
8859 functionType = ProcessType(specs, decl);
8860 functionType.refCount = 0;
8861 FinishTemplatesContext(context);
8864 FreeList(specs, FreeSpecifier);
8865 FreeDeclarator(decl);
8869 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
8871 Type type = functionType.type;
8872 if(!functionType.refCount)
8874 functionType.type = null;
8875 FreeType(functionType);
8877 //methodType = functionType;
8878 functionType = type;
8880 if(functionType && functionType.kind != TypeKind::functionType)
8882 Compiler_Error($"called object %s is not a function\n", name);
8884 else if(functionType)
8886 bool emptyParams = false, noParams = false;
8887 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
8888 Type type = functionType.params.first;
8889 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
8891 Location oldyylloc = yylloc;
8893 if(!type) emptyParams = true;
8896 if(functionType.extraParam && e && functionType.thisClass)
8898 e.destType = MkClassType(functionType.thisClass.string);
8902 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
8903 // Fixed #141 by adding '&& !functionType.extraParam'
8904 if(!functionType.staticMethod && !functionType.extraParam)
8906 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
8907 memberExp.member.exp.expType._class)
8909 type = MkClassType(memberExp.member.exp.expType._class.string);
8914 type = functionType.params.first;
8919 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
8921 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
8922 type.byReference = functionType.byReference;
8923 type.typedByReference = functionType.typedByReference;
8926 // Allow manually passing a class for typed object
8927 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
8931 type = functionType.params.first;
8939 if(type && type.kind == voidType)
8942 if(!type.refCount) FreeType(type);
8946 for( ; e; e = e.next)
8948 if(!type && !emptyParams)
8951 if(methodType && methodType.methodClass)
8952 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
8953 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
8954 noParams ? 0 : functionType.params.count);
8956 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
8957 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
8958 noParams ? 0 : functionType.params.count);
8962 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
8964 Type templatedType = null;
8965 Class _class = methodType.usedClass;
8966 ClassTemplateParameter curParam = null;
8968 if(_class && _class.templateArgs /*&& _class.templateClass*/)
8971 for(sClass = _class; sClass; sClass = sClass.base)
8973 if(sClass.templateClass) sClass = sClass.templateClass;
8975 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
8977 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
8980 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
8982 if(nextClass.templateClass) nextClass = nextClass.templateClass;
8983 id += nextClass.templateParams.count;
8992 if(curParam && _class.templateArgs[id].dataTypeString)
8994 ClassTemplateArgument arg = _class.templateArgs[id];
8996 Context context = SetupTemplatesContext(_class);
8999 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9000 templatedType = ProcessTypeString(arg.dataTypeString, false);
9001 FinishTemplatesContext(context);
9003 e.destType = templatedType;
9006 templatedType.passAsTemplate = true;
9007 // templatedType.refCount++;
9013 if(type) type.refCount++;
9018 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9020 e.destType = type.prev;
9021 e.destType.refCount++;
9026 if(type) type.refCount++;
9029 // Don't reach the end for the ellipsis
9030 if(type && type.kind != ellipsisType)
9032 Type next = type.next;
9033 if(!type.refCount) FreeType(type);
9038 if(type && type.kind != ellipsisType)
9040 if(methodType && methodType.methodClass)
9041 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9042 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9043 functionType.params.count + extra);
9045 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9046 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9047 functionType.params.count + extra);
9050 if(type && !type.refCount) FreeType(type);
9057 kind = TypeKind::functionType;
9060 if(exp.call.exp.type == identifierExp)
9062 char * string = exp.call.exp.identifier.string;
9066 Location oldyylloc = yylloc;
9068 yylloc = exp.call.exp.identifier.loc;
9069 if(strstr(string, "__builtin_") == string)
9073 functionType.returnType = exp.destType;
9074 exp.destType.refCount++;
9078 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9079 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9080 globalContext.symbols.Add((BTNode)symbol);
9081 if(strstr(symbol.string, "::"))
9082 globalContext.hasNameSpace = true;
9087 else if(exp.call.exp.type == memberExp)
9089 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9090 exp.call.exp.member.member.string);*/
9093 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9095 if(!functionType.returnType)
9097 functionType.returnType = Type
9104 if(functionType && functionType.kind == TypeKind::functionType)
9106 exp.expType = functionType.returnType;
9108 if(functionType.returnType)
9109 functionType.returnType.refCount++;
9111 if(!functionType.refCount)
9112 FreeType(functionType);
9115 if(exp.call.arguments)
9117 for(e = exp.call.arguments->first; e; e = e.next)
9119 Type destType = e.destType;
9120 ProcessExpressionType(e);
9128 Location oldyylloc = yylloc;
9130 Expression checkExp = exp.member.exp;
9133 if(checkExp.type == castExp)
9134 checkExp = checkExp.cast.exp;
9135 else if(checkExp.type == bracketsExp)
9136 checkExp = checkExp.list ? checkExp.list->first : null;
9141 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9142 exp.thisPtr = thisPtr;
9144 // DOING THIS LATER NOW...
9145 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9147 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9148 /* TODO: Name Space Fix ups
9149 if(!exp.member.member.classSym)
9150 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9154 ProcessExpressionType(exp.member.exp);
9155 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9156 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9158 exp.isConstant = false;
9161 exp.isConstant = exp.member.exp.isConstant;
9162 type = exp.member.exp.expType;
9166 if(type && (type.kind == templateType))
9168 Class _class = thisClass ? thisClass : currentClass;
9169 ClassTemplateParameter param = null;
9172 for(param = _class.templateParams.first; param; param = param.next)
9174 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9178 if(param && param.defaultArg.member)
9180 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9183 Expression expMember = exp.member.exp;
9185 OldList * specs = MkList();
9186 char thisClassTypeString[1024];
9188 FreeIdentifier(exp.member.member);
9190 ProcessExpressionType(argExp);
9193 char * colon = strstr(param.defaultArg.memberString, "::");
9196 char className[1024];
9199 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9200 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9203 strcpy(thisClassTypeString, _class.fullName);
9206 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9208 exp.expType = ProcessType(specs, decl);
9209 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9211 Class expClass = exp.expType._class.registered;
9212 Class cClass = null;
9217 char templateString[1024];
9218 ClassTemplateParameter param;
9219 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9220 for(cClass = expClass; cClass; cClass = cClass.base)
9223 for(param = cClass.templateParams.first; param; param = param.next)
9227 ClassTemplateArgument arg;
9228 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9229 arg = expClass.templateArgs[id];
9231 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9233 ClassTemplateParameter cParam;
9234 //int p = numParams - sClass.templateParams.count;
9237 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9239 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9241 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9243 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9245 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9246 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9258 strcat(argument, arg.name.string);
9259 strcat(argument, " = ");
9265 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9266 char expString[1024];
9267 OldList * specs = MkList();
9268 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9270 char * string = PrintHexUInt64(arg.expression.ui64);
9271 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9274 ProcessExpressionType(exp);
9275 ComputeExpression(exp);
9276 expString[0] = '\0';
9277 PrintExpression(exp, expString);
9278 strcat(argument, expString);
9280 FreeExpression(exp);
9285 strcat(argument, arg.member.name);
9288 case TemplateParameterType::type:
9290 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9292 if(!strcmp(arg.dataTypeString, "thisclass"))
9293 strcat(argument, thisClassTypeString);
9295 strcat(argument, arg.dataTypeString);
9302 if(paramCount) strcat(templateString, ", ");
9303 if(lastParam != p - 1)
9305 strcat(templateString, param.name);
9306 strcat(templateString, " = ");
9308 strcat(templateString, argument);
9317 int len = strlen(templateString);
9318 if(templateString[len-1] == '>') templateString[len++] = ' ';
9319 templateString[len++] = '>';
9320 templateString[len++] = '\0';
9323 Context context = SetupTemplatesContext(_class);
9324 FreeType(exp.expType);
9325 exp.expType = ProcessTypeString(templateString, false);
9326 FinishTemplatesContext(context);
9330 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9331 exp.type = bracketsExp;
9332 exp.list = MkListOne(MkExpOp(null, '*',
9337 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9338 MkExpBrackets(MkListOne(
9339 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9341 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9343 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9348 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9349 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9351 type = ProcessTemplateParameterType(type.templateParameter);
9354 // TODO: *** This seems to be where we should add method support for all basic types ***
9355 if(type && (type.kind == templateType));
9356 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9357 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
9358 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9359 (type.kind == pointerType && type.type.kind == charType)))
9361 Identifier id = exp.member.member;
9362 TypeKind typeKind = type.kind;
9363 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9364 if(typeKind == subClassType && exp.member.exp.type == classExp)
9366 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9367 typeKind = classType;
9372 if(typeKind == intType || typeKind == enumType)
9373 _class = eSystem_FindClass(privateModule, "int");
9376 if(type.kind == classType && type._class && type._class.registered)
9378 _class = type._class.registered;
9380 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
9382 _class = FindClass("char *").registered;
9384 else if(type.kind == pointerType)
9386 _class = eSystem_FindClass(privateModule, "uintptr");
9387 FreeType(exp.expType);
9388 exp.expType = ProcessTypeString("uintptr", false);
9389 exp.byReference = true;
9393 char string[1024] = "";
9395 PrintTypeNoConst(type, string, false, true);
9396 classSym = FindClass(string);
9397 if(classSym) _class = classSym.registered;
9405 (exp.member.exp.type == identifierExp &&
9406 !strcmp(exp.member.exp.identifier.string, "this"));*/
9407 Property prop = null;
9408 Method method = null;
9409 DataMember member = null;
9410 Property revConvert = null;
9411 ClassProperty classProp = null;
9413 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9414 exp.member.memberType = propertyMember;
9416 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9417 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9419 if(typeKind != subClassType)
9421 // Prioritize data members over properties for "this"
9422 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9424 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9425 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9427 prop = eClass_FindProperty(_class, id.string, privateModule);
9431 if(!member && !prop)
9432 prop = eClass_FindProperty(_class, id.string, privateModule);
9433 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9434 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9435 exp.member.thisPtr = true;
9437 // Prioritize properties over data members otherwise
9440 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9443 prop = eClass_FindProperty(_class, id.string, null);
9444 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9445 member = eClass_FindDataMember(_class, id.string, null, null, null);
9448 if(!prop && !member)
9450 method = eClass_FindMethod(_class, id.string, null);
9453 prop = eClass_FindProperty(_class, id.string, privateModule);
9454 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9455 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9461 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9468 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
9469 method = eClass_FindMethod(_class, id.string, privateModule);
9470 if(!prop && !member && !method)
9472 if(typeKind == subClassType)
9474 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9477 exp.member.memberType = classPropertyMember;
9478 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9482 // Assume this is a class_data member
9483 char structName[1024];
9484 Identifier id = exp.member.member;
9485 Expression classExp = exp.member.exp;
9488 FreeType(classExp.expType);
9489 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9491 strcpy(structName, "__ecereClassData_");
9492 FullClassNameCat(structName, type._class.string, false);
9493 exp.type = pointerExp;
9494 exp.member.member = id;
9496 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9497 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9498 MkExpBrackets(MkListOne(MkExpOp(
9499 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9500 MkExpMember(classExp, MkIdentifier("data"))), '+',
9501 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9506 ProcessExpressionType(exp);
9512 // Check for reverse conversion
9513 // (Convert in an instantiation later, so that we can use
9514 // deep properties system)
9515 Symbol classSym = FindClass(id.string);
9518 Class convertClass = classSym.registered;
9520 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9527 exp.member.memberType = propertyMember;
9529 ProcessPropertyType(prop);
9530 exp.expType = prop.dataType;
9531 if(prop.dataType) prop.dataType.refCount++;
9535 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9537 FreeExpContents(exp);
9538 exp.type = identifierExp;
9539 exp.identifier = MkIdentifier("class");
9540 ProcessExpressionType(exp);
9544 exp.member.memberType = dataMember;
9545 DeclareStruct(_class.fullName, false);
9546 if(!member.dataType)
9548 Context context = SetupTemplatesContext(_class);
9549 member.dataType = ProcessTypeString(member.dataTypeString, false);
9550 FinishTemplatesContext(context);
9552 exp.expType = member.dataType;
9553 if(member.dataType) member.dataType.refCount++;
9557 exp.member.memberType = reverseConversionMember;
9558 exp.expType = MkClassType(revConvert._class.fullName);
9566 exp.type = identifierExp;
9567 exp.identifier = exp.member.member;
9570 exp.member.memberType = methodMember;
9572 if(!method.dataType)
9573 ProcessMethodType(method);
9581 // Tricky spot here... To use instance versus class virtual table
9582 // Put it back to what it was... What did we break?
9584 // Had to put it back for overriding Main of Thread global instance
9586 //exp.expType.methodClass = _class;
9587 exp.expType.methodClass = (id && id._class) ? _class : null;
9589 // Need the actual class used for templated classes
9590 exp.expType.usedClass = _class;
9594 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9596 FreeExpContents(exp);
9597 exp.type = identifierExp;
9598 exp.identifier = MkIdentifier("class");
9599 ProcessExpressionType(exp);
9602 yylloc = exp.member.member.loc;
9603 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9605 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9608 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9613 while(tClass && !tClass.templateClass) tClass = tClass.base;
9615 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9618 ClassTemplateParameter curParam = null;
9621 for(sClass = tClass; sClass; sClass = sClass.base)
9624 if(sClass.templateClass) sClass = sClass.templateClass;
9625 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9627 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9629 for(sClass = sClass.base; sClass; sClass = sClass.base)
9630 id += sClass.templateParams.count;
9638 if(curParam && tClass.templateArgs[id].dataTypeString)
9640 ClassTemplateArgument arg = tClass.templateArgs[id];
9641 Context context = SetupTemplatesContext(tClass);
9643 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9644 FreeType(exp.expType);
9645 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9648 if(exp.expType.kind == thisClassType)
9650 FreeType(exp.expType);
9651 exp.expType = ReplaceThisClassType(_class);
9654 if(tClass.templateClass)
9655 exp.expType.passAsTemplate = true;
9656 //exp.expType.refCount++;
9659 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9660 //exp.destType.refCount++;
9662 if(exp.destType.kind == thisClassType)
9664 FreeType(exp.destType);
9665 exp.destType = ReplaceThisClassType(_class);
9669 FinishTemplatesContext(context);
9672 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9673 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9676 ClassTemplateParameter curParam = null;
9679 for(sClass = tClass; sClass; sClass = sClass.base)
9682 if(sClass.templateClass) sClass = sClass.templateClass;
9683 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9685 if(curParam.type == TemplateParameterType::type &&
9686 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9688 for(sClass = sClass.base; sClass; sClass = sClass.base)
9689 id += sClass.templateParams.count;
9699 ClassTemplateArgument arg = tClass.templateArgs[id];
9700 Context context = SetupTemplatesContext(tClass);
9703 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9705 basicType = ProcessTypeString(arg.dataTypeString, false);
9708 if(basicType.kind == thisClassType)
9710 FreeType(basicType);
9711 basicType = ReplaceThisClassType(_class);
9714 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9715 if(tClass.templateClass)
9716 basicType.passAsTemplate = true;
9719 FreeType(exp.expType);
9721 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9722 //exp.expType.refCount++;
9725 exp.destType = exp.expType;
9726 exp.destType.refCount++;
9730 Expression newExp { };
9731 OldList * specs = MkList();
9733 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9735 if(exp.destType) exp.destType.refCount++;
9736 if(exp.expType) exp.expType.refCount++;
9738 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9739 exp.cast.exp = newExp;
9740 //FreeType(exp.expType);
9741 //exp.expType = null;
9742 //ProcessExpressionType(sourceExp);
9745 FinishTemplatesContext(context);
9748 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9750 Class expClass = exp.expType._class.registered;
9753 Class cClass = null;
9758 char templateString[1024];
9759 ClassTemplateParameter param;
9760 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9761 while(cClass != expClass)
9764 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9767 for(param = cClass.templateParams.first; param; param = param.next)
9769 Class cClassCur = null;
9772 ClassTemplateParameter paramCur = null;
9773 ClassTemplateArgument arg;
9774 while(cClassCur != tClass && !paramCur)
9777 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
9778 cClassCur = sClassCur;
9780 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
9782 if(!strcmp(paramCur.name, param.name))
9790 if(paramCur && paramCur.type == TemplateParameterType::type)
9791 arg = tClass.templateArgs[cp];
9793 arg = expClass.templateArgs[p];
9800 strcat(argument, arg.name.string);
9801 strcat(argument, " = ");
9807 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9808 char expString[1024];
9809 OldList * specs = MkList();
9810 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9812 char * string = PrintHexUInt64(arg.expression.ui64);
9813 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9816 ProcessExpressionType(exp);
9817 ComputeExpression(exp);
9818 expString[0] = '\0';
9819 PrintExpression(exp, expString);
9820 strcat(argument, expString);
9822 FreeExpression(exp);
9827 strcat(argument, arg.member.name);
9830 case TemplateParameterType::type:
9832 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9833 strcat(argument, arg.dataTypeString);
9839 if(paramCount) strcat(templateString, ", ");
9840 if(lastParam != p - 1)
9842 strcat(templateString, param.name);
9843 strcat(templateString, " = ");
9845 strcat(templateString, argument);
9854 int len = strlen(templateString);
9855 if(templateString[len-1] == '>') templateString[len++] = ' ';
9856 templateString[len++] = '>';
9857 templateString[len++] = '\0';
9860 FreeType(exp.expType);
9862 Context context = SetupTemplatesContext(tClass);
9863 exp.expType = ProcessTypeString(templateString, false);
9864 FinishTemplatesContext(context);
9871 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
9873 else if(type && (type.kind == structType || type.kind == unionType))
9875 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
9878 exp.expType = memberType;
9880 memberType.refCount++;
9885 char expString[10240];
9886 expString[0] = '\0';
9887 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
9888 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
9891 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
9893 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9895 Identifier id = exp.member.member;
9896 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9899 FreeType(exp.expType);
9900 exp.expType = ReplaceThisClassType(_class);
9907 // Convert x->y into (*x).y
9910 Type destType = exp.destType;
9912 // DOING THIS LATER NOW...
9913 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9915 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9916 /* TODO: Name Space Fix ups
9917 if(!exp.member.member.classSym)
9918 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
9922 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
9923 exp.type = memberExp;
9926 ProcessExpressionType(exp);
9933 //ComputeExpression(exp);
9935 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
9936 if(classSym && classSym.registered)
9938 if(classSym.registered.type == noHeadClass)
9942 DeclareStruct(classSym.string, false);
9943 FreeSpecifier(exp._class);
9944 exp.type = typeSizeExp;
9945 FullClassNameCat(name, classSym.string, false);
9946 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
9950 if(classSym.registered.fixed)
9952 FreeSpecifier(exp._class);
9953 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
9954 exp.type = constantExp;
9958 char className[1024];
9959 strcpy(className, "__ecereClass_");
9960 FullClassNameCat(className, classSym.string, true);
9961 MangleClassName(className);
9963 DeclareClass(classSym, className);
9965 FreeExpContents(exp);
9966 exp.type = pointerExp;
9967 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
9968 exp.member.member = MkIdentifier("structSize");
9978 // exp.isConstant = true;
9983 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
9990 exp.isConstant = true;
9992 DeclareType(type, false, false);
9998 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10000 FreeType(exp.cast.exp.destType);
10001 exp.cast.exp.destType = type;
10003 ProcessExpressionType(exp.cast.exp);
10005 exp.expType = type;
10008 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10009 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10011 void * prev = exp.prev, * next = exp.next;
10012 Type expType = exp.cast.exp.destType;
10013 Expression castExp = exp.cast.exp;
10014 Type destType = exp.destType;
10016 if(expType) expType.refCount++;
10018 //FreeType(exp.destType);
10019 FreeType(exp.expType);
10020 FreeTypeName(exp.cast.typeName);
10023 FreeType(exp.expType);
10024 FreeType(exp.destType);
10026 exp.expType = expType;
10027 exp.destType = destType;
10037 exp.isConstant = exp.cast.exp.isConstant;
10042 case extensionInitializerExp:
10044 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10045 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10046 // ProcessInitializer(exp.initializer.initializer, type);
10047 exp.expType = type;
10052 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10053 ProcessExpressionType(exp.vaArg.exp);
10054 exp.expType = type;
10060 exp.isConstant = true;
10062 FreeType(exp.cond.cond.destType);
10063 exp.cond.cond.destType = MkClassType("bool");
10064 exp.cond.cond.destType.truth = true;
10065 ProcessExpressionType(exp.cond.cond);
10066 if(!exp.cond.cond.isConstant)
10067 exp.isConstant = false;
10068 for(e = exp.cond.exp->first; e; e = e.next)
10072 FreeType(e.destType);
10073 e.destType = exp.destType;
10074 if(e.destType) e.destType.refCount++;
10076 ProcessExpressionType(e);
10079 exp.expType = e.expType;
10080 if(e.expType) e.expType.refCount++;
10083 exp.isConstant = false;
10086 FreeType(exp.cond.elseExp.destType);
10087 // Added this check if we failed to find an expType
10088 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10091 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10093 if(exp.cond.elseExp.destType)
10094 exp.cond.elseExp.destType.refCount++;
10095 ProcessExpressionType(exp.cond.elseExp);
10097 // FIXED THIS: Was done before calling process on elseExp
10098 if(!exp.cond.elseExp.isConstant)
10099 exp.isConstant = false;
10102 case extensionCompoundExp:
10104 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10106 Statement last = exp.compound.compound.statements->last;
10107 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10109 ((Expression)last.expressions->last).destType = exp.destType;
10111 exp.destType.refCount++;
10113 ProcessStatement(exp.compound);
10114 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10116 exp.expType.refCount++;
10122 Specifier spec = exp._classExp.specifiers->first;
10123 if(spec && spec.type == nameSpecifier)
10125 exp.expType = MkClassType(spec.name);
10126 exp.expType.kind = subClassType;
10127 exp.byReference = true;
10131 exp.expType = MkClassType("ecere::com::Class");
10132 exp.byReference = true;
10138 Class _class = thisClass ? thisClass : currentClass;
10141 Identifier id = exp.classData.id;
10142 char structName[1024];
10143 Expression classExp;
10144 strcpy(structName, "__ecereClassData_");
10145 FullClassNameCat(structName, _class.fullName, false);
10146 exp.type = pointerExp;
10147 exp.member.member = id;
10148 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10149 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10151 classExp = MkExpIdentifier(MkIdentifier("class"));
10153 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10154 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10155 MkExpBrackets(MkListOne(MkExpOp(
10156 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10157 MkExpMember(classExp, MkIdentifier("data"))), '+',
10158 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10161 ProcessExpressionType(exp);
10169 char * typeString = null;
10170 char typeStringBuf[1024];
10171 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10172 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10174 Class templateClass = exp.destType._class.registered;
10175 typeString = templateClass.templateArgs[2].dataTypeString;
10179 // Guess type from expressions in the array
10181 for(e = exp.list->first; e; e = e.next)
10183 ProcessExpressionType(e);
10186 if(!type) { type = e.expType; type.refCount++; }
10189 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10190 if(!MatchTypeExpression(e, type, null, false))
10196 e = exp.list->first;
10197 ProcessExpressionType(e);
10200 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10201 if(!MatchTypeExpression(e, type, null, false))
10203 FreeType(e.expType);
10214 FreeType(e.expType);
10221 typeStringBuf[0] = '\0';
10222 PrintTypeNoConst(type, typeStringBuf, false, true);
10223 typeString = typeStringBuf;
10231 (Container)& (struct BuiltInContainer)
10233 ._vTbl = class(BuiltInContainer)._vTbl,
10234 ._class = class(BuiltInContainer),
10236 .data = (int[]){ 1, 7, 3, 4, 5 },
10238 .type = class(int),
10241 char templateString[1024];
10242 OldList * initializers = MkList();
10243 OldList * structInitializers = MkList();
10244 OldList * specs = MkList();
10246 Declarator decl = SpecDeclFromString(typeString, specs, null);
10247 sprintf(templateString, "Container<%s>", typeString);
10252 type = ProcessTypeString(typeString, false);
10253 while(e = exp.list->first)
10255 exp.list->Remove(e);
10258 ProcessExpressionType(e);
10259 ListAdd(initializers, MkInitializerAssignment(e));
10265 DeclareStruct("ecere::com::BuiltInContainer", false);
10267 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10268 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10269 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10270 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10271 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10272 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10273 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10274 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10275 MkInitializerList(initializers))));
10276 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10277 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10278 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10279 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10280 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10281 exp.expType = ProcessTypeString(templateString, false);
10282 exp.type = bracketsExp;
10283 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10285 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10286 MkInitializerList(structInitializers)))));
10287 ProcessExpressionType(expExt);
10291 exp.expType = ProcessTypeString("Container", false);
10292 Compiler_Error($"Couldn't determine type of array elements\n");
10298 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10300 FreeType(exp.expType);
10301 exp.expType = ReplaceThisClassType(thisClass);
10304 // Resolve structures here
10305 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10307 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10308 // TODO: Fix members reference...
10311 if(exp.expType.kind != enumType)
10314 String enumName = CopyString(exp.expType.enumName);
10316 // Fixed a memory leak on self-referencing C structs typedefs
10317 // by instantiating a new type rather than simply copying members
10318 // into exp.expType
10319 FreeType(exp.expType);
10320 exp.expType = Type { };
10321 exp.expType.kind = symbol.type.kind;
10322 exp.expType.refCount++;
10323 exp.expType.enumName = enumName;
10325 exp.expType.members = symbol.type.members;
10326 for(member = symbol.type.members.first; member; member = member.next)
10332 for(member = symbol.type.members.first; member; member = member.next)
10334 NamedLink value { name = CopyString(member.name) };
10335 exp.expType.members.Add(value);
10342 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10343 else if(exp.destType && !exp.destType.keepCast)
10345 if(!CheckExpressionType(exp, exp.destType, false))
10347 if(!exp.destType.count || unresolved)
10352 if(exp.destType.kind != ellipsisType)
10358 char expString[10240];
10359 expString[0] = '\0';
10361 PrintType(exp.destType, type2, false, true);
10363 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10365 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10366 else if(exp.type != dummyExp)
10367 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10372 char expString[10240] ;
10373 expString[0] = '\0';
10374 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10377 Compiler_Error($"unresolved identifier %s\n", expString);
10378 else if(exp.type != dummyExp)
10379 Compiler_Error($"couldn't determine type of %s\n", expString);
10390 PrintType(exp.expType, type1, false, true);
10391 PrintType(exp.destType, type2, false, true);
10394 //CheckExpressionType(exp, exp.destType, false);
10396 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10397 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10398 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10401 char expString[10240];
10402 expString[0] = '\0';
10403 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10406 CheckExpressionType(exp, exp.destType, false);
10408 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10409 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10410 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10412 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10413 FreeType(exp.expType);
10414 exp.destType.refCount++;
10415 exp.expType = exp.destType;
10420 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10422 Expression newExp { };
10423 char typeString[1024];
10424 OldList * specs = MkList();
10427 typeString[0] = '\0';
10431 if(exp.expType) exp.expType.refCount++;
10432 if(exp.expType) exp.expType.refCount++;
10433 exp.type = castExp;
10434 newExp.destType = exp.expType;
10436 PrintType(exp.expType, typeString, false, false);
10437 decl = SpecDeclFromString(typeString, specs, null);
10439 exp.cast.typeName = MkTypeName(specs, decl);
10440 exp.cast.exp = newExp;
10443 else if(unresolved)
10445 if(exp.identifier._class && exp.identifier._class.name)
10446 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10447 else if(exp.identifier.string && exp.identifier.string[0])
10448 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10450 else if(!exp.expType && exp.type != dummyExp)
10452 char expString[10240];
10453 expString[0] = '\0';
10454 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10455 Compiler_Error($"couldn't determine type of %s\n", expString);
10458 // Let's try to support any_object & typed_object here:
10460 ApplyAnyObjectLogic(exp);
10462 // Mark nohead classes as by reference, unless we're casting them to an integral type
10463 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10464 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
10465 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
10466 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
10468 exp.byReference = true;
10470 yylloc = oldyylloc;
10473 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10475 // THIS CODE WILL FIND NEXT MEMBER...
10478 *curMember = (*curMember).next;
10480 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10482 *curMember = subMemberStack[--(*subMemberStackPos)];
10483 *curMember = (*curMember).next;
10486 // SKIP ALL PROPERTIES HERE...
10487 while((*curMember) && (*curMember).isProperty)
10488 *curMember = (*curMember).next;
10490 if(subMemberStackPos)
10492 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10494 subMemberStack[(*subMemberStackPos)++] = *curMember;
10496 *curMember = (*curMember).members.first;
10497 while(*curMember && (*curMember).isProperty)
10498 *curMember = (*curMember).next;
10506 if(subMemberStackPos && *subMemberStackPos)
10508 *curMember = subMemberStack[--(*subMemberStackPos)];
10509 *curMember = (*curMember).next;
10513 Class lastCurClass = *curClass;
10515 if(*curClass == _class) break; // REACHED THE END
10517 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10518 *curMember = (*curClass).membersAndProperties.first;
10521 while((*curMember) && (*curMember).isProperty)
10522 *curMember = (*curMember).next;
10523 if(subMemberStackPos)
10525 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10527 subMemberStack[(*subMemberStackPos)++] = *curMember;
10529 *curMember = (*curMember).members.first;
10530 while(*curMember && (*curMember).isProperty)
10531 *curMember = (*curMember).next;
10539 static void ProcessInitializer(Initializer init, Type type)
10543 case expInitializer:
10544 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10546 // TESTING THIS FOR SHUTTING = 0 WARNING
10547 if(init.exp && !init.exp.destType)
10549 FreeType(init.exp.destType);
10550 init.exp.destType = type;
10551 if(type) type.refCount++;
10555 ProcessExpressionType(init.exp);
10556 init.isConstant = init.exp.isConstant;
10562 Expression exp = init.exp;
10563 Instantiation inst = exp.instance;
10564 MembersInit members;
10566 init.type = listInitializer;
10567 init.list = MkList();
10571 for(members = inst.members->first; members; members = members.next)
10573 if(members.type == dataMembersInit)
10576 for(member = members.dataMembers->first; member; member = member.next)
10578 ListAdd(init.list, member.initializer);
10579 member.initializer = null;
10582 // Discard all MembersInitMethod
10585 FreeExpression(exp);
10587 case listInitializer:
10590 Type initializerType = null;
10591 Class curClass = null;
10592 DataMember curMember = null;
10593 DataMember subMemberStack[256];
10594 int subMemberStackPos = 0;
10596 if(type && type.kind == arrayType)
10597 initializerType = Dereference(type);
10598 else if(type && (type.kind == structType || type.kind == unionType))
10599 initializerType = type.members.first;
10601 for(i = init.list->first; i; i = i.next)
10603 if(type && type.kind == classType && type._class && type._class.registered)
10605 // 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)
10606 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10607 // TODO: Generate error on initializing a private data member this way from another module...
10610 if(!curMember.dataType)
10611 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10612 initializerType = curMember.dataType;
10615 ProcessInitializer(i, initializerType);
10616 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10617 initializerType = initializerType.next;
10619 init.isConstant = false;
10622 if(type && type.kind == arrayType)
10623 FreeType(initializerType);
10625 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10627 Compiler_Error($"Assigning list initializer to non list\n");
10634 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10638 case baseSpecifier:
10640 if(spec.specifier == THISCLASS)
10644 spec.type = nameSpecifier;
10645 spec.name = ReplaceThisClass(thisClass);
10646 spec.symbol = FindClass(spec.name);
10647 ProcessSpecifier(spec, declareStruct);
10652 case nameSpecifier:
10654 Symbol symbol = FindType(curContext, spec.name);
10656 DeclareType(symbol.type, true, true);
10657 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10658 DeclareStruct(spec.name, false);
10661 case enumSpecifier:
10666 for(e = spec.list->first; e; e = e.next)
10669 ProcessExpressionType(e.exp);
10674 case structSpecifier:
10675 case unionSpecifier:
10677 if(spec.definitions)
10680 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10682 ProcessClass(spec.definitions, symbol);
10685 for(def = spec.definitions->first; def; def = def.next)
10687 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10688 ProcessDeclaration(def.decl);
10695 case classSpecifier:
10697 Symbol classSym = FindClass(spec.name);
10698 if(classSym && classSym.registered && classSym.registered.type == structClass)
10699 DeclareStruct(spec.name, false);
10707 static void ProcessDeclarator(Declarator decl)
10711 case identifierDeclarator:
10712 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10714 FreeSpecifier(decl.identifier._class);
10715 decl.identifier._class = null;
10718 case arrayDeclarator:
10720 ProcessExpressionType(decl.array.exp);
10721 case structDeclarator:
10722 case bracketsDeclarator:
10723 case functionDeclarator:
10724 case pointerDeclarator:
10725 case extendedDeclarator:
10726 case extendedDeclaratorEnd:
10727 if(decl.declarator)
10728 ProcessDeclarator(decl.declarator);
10729 if(decl.type == functionDeclarator)
10731 Identifier id = GetDeclId(decl);
10732 if(id && id._class)
10736 qualifiers = MkListOne(id._class);
10739 if(!decl.function.parameters)
10740 decl.function.parameters = MkList();
10741 decl.function.parameters->Insert(null, param);
10744 if(decl.function.parameters)
10748 for(param = decl.function.parameters->first; param; param = param.next)
10750 if(param.qualifiers && param.qualifiers->first)
10752 Specifier spec = param.qualifiers->first;
10753 if(spec && spec.specifier == TYPED_OBJECT)
10755 Declarator d = param.declarator;
10758 qualifiers = MkListOne(MkSpecifier(VOID));
10759 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10762 FreeList(param.qualifiers, FreeSpecifier);
10764 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10765 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10767 decl.function.parameters->Insert(param, newParam);
10770 else if(spec && spec.specifier == ANY_OBJECT)
10772 Declarator d = param.declarator;
10774 FreeList(param.qualifiers, FreeSpecifier);
10776 param.qualifiers = MkListOne(MkSpecifier(VOID));
10777 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10779 else if(spec.specifier == THISCLASS)
10783 spec.type = nameSpecifier;
10784 spec.name = ReplaceThisClass(thisClass);
10785 spec.symbol = FindClass(spec.name);
10786 ProcessSpecifier(spec, false);
10791 if(param.declarator)
10792 ProcessDeclarator(param.declarator);
10800 static void ProcessDeclaration(Declaration decl)
10805 case initDeclaration:
10807 bool declareStruct = false;
10809 lineNum = decl.pos.line;
10810 column = decl.pos.col;
10813 if(decl.declarators)
10817 for(d = decl.declarators->first; d; d = d.next)
10819 Type type, subType;
10820 ProcessDeclarator(d.declarator);
10822 type = ProcessType(decl.specifiers, d.declarator);
10826 ProcessInitializer(d.initializer, type);
10828 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
10830 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
10831 d.initializer.exp.type == instanceExp)
10833 if(type.kind == classType && type._class ==
10834 d.initializer.exp.expType._class)
10836 Instantiation inst = d.initializer.exp.instance;
10837 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
10839 d.initializer.exp.instance = null;
10840 if(decl.specifiers)
10841 FreeList(decl.specifiers, FreeSpecifier);
10842 FreeList(decl.declarators, FreeInitDeclarator);
10846 decl.type = instDeclaration;
10851 for(subType = type; subType;)
10853 if(subType.kind == classType)
10855 declareStruct = true;
10858 else if(subType.kind == pointerType)
10860 else if(subType.kind == arrayType)
10861 subType = subType.arrayType;
10871 if(decl.specifiers)
10874 for(s = decl.specifiers->first; s; s = s.next)
10876 ProcessSpecifier(s, declareStruct);
10881 case instDeclaration:
10883 ProcessInstantiationType(decl.inst);
10886 case structDeclaration:
10890 bool declareStruct = false;
10892 if(decl.declarators)
10894 for(d = decl.declarators->first; d; d = d.next)
10896 Type type = ProcessType(decl.specifiers, d.declarator);
10898 ProcessDeclarator(d);
10899 for(subType = type; subType;)
10901 if(subType.kind == classType)
10903 declareStruct = true;
10906 else if(subType.kind == pointerType)
10908 else if(subType.kind == arrayType)
10909 subType = subType.arrayType;
10916 if(decl.specifiers)
10918 for(spec = decl.specifiers->first; spec; spec = spec.next)
10919 ProcessSpecifier(spec, declareStruct);
10926 static FunctionDefinition curFunction;
10928 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
10930 char propName[1024], propNameM[1024];
10931 char getName[1024], setName[1024];
10934 DeclareProperty(prop, setName, getName);
10936 // eInstance_FireWatchers(object, prop);
10937 strcpy(propName, "__ecereProp_");
10938 FullClassNameCat(propName, prop._class.fullName, false);
10939 strcat(propName, "_");
10940 // strcat(propName, prop.name);
10941 FullClassNameCat(propName, prop.name, true);
10942 MangleClassName(propName);
10944 strcpy(propNameM, "__ecerePropM_");
10945 FullClassNameCat(propNameM, prop._class.fullName, false);
10946 strcat(propNameM, "_");
10947 // strcat(propNameM, prop.name);
10948 FullClassNameCat(propNameM, prop.name, true);
10949 MangleClassName(propNameM);
10951 if(prop.isWatchable)
10954 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10955 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10956 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10959 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10960 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10961 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10967 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10968 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10969 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10972 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10973 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10974 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10977 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
10978 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
10979 curFunction.propSet.fireWatchersDone = true;
10982 static void ProcessStatement(Statement stmt)
10986 lineNum = stmt.pos.line;
10987 column = stmt.pos.col;
10992 ProcessStatement(stmt.labeled.stmt);
10995 // This expression should be constant...
10996 if(stmt.caseStmt.exp)
10998 FreeType(stmt.caseStmt.exp.destType);
10999 stmt.caseStmt.exp.destType = curSwitchType;
11000 if(curSwitchType) curSwitchType.refCount++;
11001 ProcessExpressionType(stmt.caseStmt.exp);
11002 ComputeExpression(stmt.caseStmt.exp);
11004 if(stmt.caseStmt.stmt)
11005 ProcessStatement(stmt.caseStmt.stmt);
11009 if(stmt.compound.context)
11014 Statement prevCompound = curCompound;
11015 Context prevContext = curContext;
11017 if(!stmt.compound.isSwitch)
11018 curCompound = stmt;
11019 curContext = stmt.compound.context;
11021 if(stmt.compound.declarations)
11023 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11024 ProcessDeclaration(decl);
11026 if(stmt.compound.statements)
11028 for(s = stmt.compound.statements->first; s; s = s.next)
11029 ProcessStatement(s);
11032 curContext = prevContext;
11033 curCompound = prevCompound;
11037 case expressionStmt:
11040 if(stmt.expressions)
11042 for(exp = stmt.expressions->first; exp; exp = exp.next)
11043 ProcessExpressionType(exp);
11051 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11052 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11053 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11054 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11056 ProcessExpressionType(exp);
11058 if(stmt.ifStmt.stmt)
11059 ProcessStatement(stmt.ifStmt.stmt);
11060 if(stmt.ifStmt.elseStmt)
11061 ProcessStatement(stmt.ifStmt.elseStmt);
11066 Type oldSwitchType = curSwitchType;
11067 if(stmt.switchStmt.exp)
11070 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11080 e.exp.destType = destType;
11083 ProcessExpressionType(exp);
11086 curSwitchType = exp.expType;
11089 ProcessStatement(stmt.switchStmt.stmt);
11090 curSwitchType = oldSwitchType;
11095 if(stmt.whileStmt.exp)
11099 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11100 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11101 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11102 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11104 ProcessExpressionType(exp);
11107 if(stmt.whileStmt.stmt)
11108 ProcessStatement(stmt.whileStmt.stmt);
11113 if(stmt.doWhile.exp)
11117 if(stmt.doWhile.exp->last)
11119 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11120 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11121 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11123 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11125 ProcessExpressionType(exp);
11128 if(stmt.doWhile.stmt)
11129 ProcessStatement(stmt.doWhile.stmt);
11135 if(stmt.forStmt.init)
11136 ProcessStatement(stmt.forStmt.init);
11138 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11140 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11141 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11142 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11145 if(stmt.forStmt.check)
11146 ProcessStatement(stmt.forStmt.check);
11147 if(stmt.forStmt.increment)
11149 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11150 ProcessExpressionType(exp);
11153 if(stmt.forStmt.stmt)
11154 ProcessStatement(stmt.forStmt.stmt);
11159 Identifier id = stmt.forEachStmt.id;
11160 OldList * exp = stmt.forEachStmt.exp;
11161 OldList * filter = stmt.forEachStmt.filter;
11162 Statement block = stmt.forEachStmt.stmt;
11163 char iteratorType[1024];
11166 bool isBuiltin = exp && exp->last &&
11167 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11168 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11169 Expression arrayExp;
11170 char * typeString = null;
11171 int builtinCount = 0;
11173 for(e = exp ? exp->first : null; e; e = e.next)
11177 FreeType(e.destType);
11178 e.destType = ProcessTypeString("Container", false);
11180 if(!isBuiltin || e.next)
11181 ProcessExpressionType(e);
11184 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11185 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11186 eClass_IsDerived(source._class.registered, containerClass)))
11188 Class _class = source ? source._class.registered : null;
11190 Expression expIt = null;
11191 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
11192 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11193 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11194 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11195 stmt.type = compoundStmt;
11197 stmt.compound.context = Context { };
11198 stmt.compound.context.parent = curContext;
11199 curContext = stmt.compound.context;
11201 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11203 Class mapClass = eSystem_FindClass(privateModule, "Map");
11204 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11205 isCustomAVLTree = true;
11206 if(eClass_IsDerived(source._class.registered, avlTreeClass))
11208 else if(eClass_IsDerived(source._class.registered, mapClass))
11211 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11212 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11214 Class listClass = eSystem_FindClass(privateModule, "List");
11216 isList = eClass_IsDerived(source._class.registered, listClass);
11222 OldList * specs = MkList();
11223 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11224 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11225 stmt.compound.declarations = MkListOne(
11226 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11227 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11228 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11229 MkInitializerAssignment(MkExpBrackets(exp))))));
11234 char typeStringBuf[1024];
11236 // TODO: Merge this code?
11237 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11238 if(((Expression)exp->last).type == castExp)
11240 TypeName typeName = ((Expression)exp->last).cast.typeName;
11242 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11245 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11246 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11247 arrayExp.destType._class.registered.templateArgs)
11249 Class templateClass = arrayExp.destType._class.registered;
11250 typeString = templateClass.templateArgs[2].dataTypeString;
11252 else if(arrayExp.list)
11254 // Guess type from expressions in the array
11256 for(e = arrayExp.list->first; e; e = e.next)
11258 ProcessExpressionType(e);
11261 if(!type) { type = e.expType; type.refCount++; }
11264 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11265 if(!MatchTypeExpression(e, type, null, false))
11271 e = arrayExp.list->first;
11272 ProcessExpressionType(e);
11275 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11276 if(!MatchTypeExpression(e, type, null, false))
11278 FreeType(e.expType);
11289 FreeType(e.expType);
11296 typeStringBuf[0] = '\0';
11297 PrintType(type, typeStringBuf, false, true);
11298 typeString = typeStringBuf;
11304 OldList * initializers = MkList();
11306 OldList * specs = MkList();
11311 builtinCount = arrayExp.list->count;
11312 type = ProcessTypeString(typeString, false);
11313 while(e = arrayExp.list->first)
11315 arrayExp.list->Remove(e);
11318 ProcessExpressionType(e);
11319 ListAdd(initializers, MkInitializerAssignment(e));
11322 delete arrayExp.list;
11324 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11325 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11326 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11328 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
11330 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
11331 ), MkInitializerList(initializers)))));
11332 FreeList(exp, FreeExpression);
11336 arrayExp.expType = ProcessTypeString("Container", false);
11337 Compiler_Error($"Couldn't determine type of array elements\n");
11342 OldList * specs = MkList();
11344 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11345 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11346 stmt.compound.declarations = MkListOne(
11347 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11348 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11349 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11350 MkInitializerAssignment(MkExpBrackets(exp))))));
11353 else if(isLinkList && !isList)
11356 OldList * specs = MkList();
11357 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11358 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11359 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11360 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11361 MkInitializerAssignment(MkExpBrackets(exp))))));
11363 /*else if(isCustomAVLTree)
11366 OldList * specs = MkList();
11367 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11368 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11369 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11370 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11371 MkInitializerAssignment(MkExpBrackets(exp))))));
11373 else if(_class.templateArgs)
11376 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11378 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11380 stmt.compound.declarations = MkListOne(
11381 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11382 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11383 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11385 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11389 // Reparent sub-contexts in this statement
11393 if(block.compound.context)
11394 block.compound.context.parent = stmt.compound.context;
11397 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
11398 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
11399 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
11400 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
11403 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
11404 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
11407 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
11408 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
11411 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
11412 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
11415 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
11416 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
11419 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
11420 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
11422 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
11425 case expressionStmt:
11431 case badDeclarationStmt:
11432 case fireWatchersStmt:
11433 case stopWatchingStmt:
11440 block = MkIfStmt(filter, block, null);
11444 stmt.compound.statements = MkListOne(MkForStmt(
11445 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11446 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11447 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11448 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11450 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11451 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11452 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11457 //OldList * specs = MkList();
11458 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11460 sprintf(count, "%d", builtinCount);
11462 stmt.compound.statements = MkListOne(MkForStmt(
11463 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11464 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11465 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11466 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11470 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11471 stmt.compound.statements = MkListOne(MkForStmt(
11472 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11473 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11474 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11475 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11478 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11479 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11480 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11482 else if(isLinkList && !isList)
11484 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11485 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11486 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11487 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11489 stmt.compound.statements = MkListOne(MkForStmt(
11490 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11491 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11492 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11497 OldList * specs = MkList();
11498 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11499 stmt.compound.statements = MkListOne(MkForStmt(
11500 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11501 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11502 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11503 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11504 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11507 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11508 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11509 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11511 /*else if(isCustomAVLTree)
11513 stmt.compound.statements = MkListOne(MkForStmt(
11514 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11515 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11516 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11517 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11520 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11521 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11522 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11526 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11527 MkIdentifier("Next")), null)), block));
11529 ProcessExpressionType(expIt);
11530 if(stmt.compound.declarations->first)
11531 ProcessDeclaration(stmt.compound.declarations->first);
11534 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11536 ProcessStatement(stmt);
11537 curContext = stmt.compound.context.parent;
11542 Compiler_Error($"Expression is not a container\n");
11555 if(stmt.expressions)
11557 for(exp = stmt.expressions->first; exp; exp = exp.next)
11561 if(curFunction && !curFunction.type)
11562 curFunction.type = ProcessType(
11563 curFunction.specifiers, curFunction.declarator);
11564 FreeType(exp.destType);
11565 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11566 if(exp.destType) exp.destType.refCount++;
11568 ProcessExpressionType(exp);
11573 case badDeclarationStmt:
11575 ProcessDeclaration(stmt.decl);
11581 if(stmt.asmStmt.inputFields)
11583 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11584 if(field.expression)
11585 ProcessExpressionType(field.expression);
11587 if(stmt.asmStmt.outputFields)
11589 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11590 if(field.expression)
11591 ProcessExpressionType(field.expression);
11593 if(stmt.asmStmt.clobberedFields)
11595 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11597 if(field.expression)
11598 ProcessExpressionType(field.expression);
11605 PropertyWatch propWatch;
11606 OldList * watches = stmt._watch.watches;
11607 Expression object = stmt._watch.object;
11608 Expression watcher = stmt._watch.watcher;
11610 ProcessExpressionType(watcher);
11612 ProcessExpressionType(object);
11616 if(watcher || thisClass)
11618 External external = curExternal;
11619 Context context = curContext;
11621 stmt.type = expressionStmt;
11622 stmt.expressions = MkList();
11624 curExternal = external.prev;
11626 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11628 ClassFunction func;
11629 char watcherName[1024];
11630 Class watcherClass = watcher ?
11631 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11632 External createdExternal;
11634 // Create a declaration above
11635 External externalDecl = MkExternalDeclaration(null);
11636 ast->Insert(curExternal.prev, externalDecl);
11638 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11639 if(propWatch.deleteWatch)
11640 strcat(watcherName, "_delete");
11644 for(propID = propWatch.properties->first; propID; propID = propID.next)
11646 strcat(watcherName, "_");
11647 strcat(watcherName, propID.string);
11651 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11653 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11654 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11655 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11656 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11657 ProcessClassFunctionBody(func, propWatch.compound);
11658 propWatch.compound = null;
11660 //afterExternal = afterExternal ? afterExternal : curExternal;
11662 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11663 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11665 createdExternal.symbol.idCode = external.symbol.idCode;
11667 curExternal = createdExternal;
11668 ProcessFunction(createdExternal.function);
11671 // Create a declaration above
11673 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11674 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11675 externalDecl.declaration = decl;
11676 if(decl.symbol && !decl.symbol.pointerExternal)
11677 decl.symbol.pointerExternal = externalDecl;
11680 if(propWatch.deleteWatch)
11682 OldList * args = MkList();
11683 ListAdd(args, CopyExpression(object));
11684 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11685 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11686 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11690 Class _class = object.expType._class.registered;
11693 for(propID = propWatch.properties->first; propID; propID = propID.next)
11695 char propName[1024];
11696 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11699 char getName[1024], setName[1024];
11700 OldList * args = MkList();
11702 DeclareProperty(prop, setName, getName);
11704 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11705 strcpy(propName, "__ecereProp_");
11706 FullClassNameCat(propName, prop._class.fullName, false);
11707 strcat(propName, "_");
11708 // strcat(propName, prop.name);
11709 FullClassNameCat(propName, prop.name, true);
11711 ListAdd(args, CopyExpression(object));
11712 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11713 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11714 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11716 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11719 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11724 Compiler_Error($"Invalid watched object\n");
11727 curExternal = external;
11728 curContext = context;
11731 FreeExpression(watcher);
11733 FreeExpression(object);
11734 FreeList(watches, FreePropertyWatch);
11737 Compiler_Error($"No observer specified and not inside a _class\n");
11741 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11743 ProcessStatement(propWatch.compound);
11749 case fireWatchersStmt:
11751 OldList * watches = stmt._watch.watches;
11752 Expression object = stmt._watch.object;
11754 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11755 // printf("%X\n", watches);
11756 // printf("%X\n", stmt._watch.watches);
11758 ProcessExpressionType(object);
11763 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11769 stmt.type = expressionStmt;
11770 stmt.expressions = MkList();
11772 // Check if we're inside a property set
11773 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11775 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
11779 //Compiler_Error($"No property specified and not inside a property set\n");
11783 for(propID = watches->first; propID; propID = propID.next)
11785 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11788 CreateFireWatcher(prop, object, stmt);
11791 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
11796 // Fire all properties!
11799 for(base = _class; base; base = base.base)
11801 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
11803 if(prop.isProperty && prop.isWatchable)
11805 CreateFireWatcher(prop, object, stmt);
11812 FreeExpression(object);
11813 FreeList(watches, FreeIdentifier);
11816 Compiler_Error($"Invalid object specified and not inside a class\n");
11820 case stopWatchingStmt:
11822 OldList * watches = stmt._watch.watches;
11823 Expression object = stmt._watch.object;
11824 Expression watcher = stmt._watch.watcher;
11827 ProcessExpressionType(object);
11829 ProcessExpressionType(watcher);
11832 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
11834 if(watcher || thisClass)
11840 stmt.type = expressionStmt;
11841 stmt.expressions = MkList();
11846 // eInstance_StopWatching(object, null, watcher);
11848 ListAdd(args, CopyExpression(object));
11849 ListAdd(args, MkExpConstant("0"));
11850 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11851 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11855 for(propID = watches->first; propID; propID = propID.next)
11857 char propName[1024];
11858 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11861 char getName[1024], setName[1024];
11862 OldList * args = MkList();
11864 DeclareProperty(prop, setName, getName);
11866 // eInstance_StopWatching(object, prop, watcher);
11867 strcpy(propName, "__ecereProp_");
11868 FullClassNameCat(propName, prop._class.fullName, false);
11869 strcat(propName, "_");
11870 // strcat(propName, prop.name);
11871 FullClassNameCat(propName, prop.name, true);
11872 MangleClassName(propName);
11874 ListAdd(args, CopyExpression(object));
11875 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11876 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11877 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11880 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11885 FreeExpression(object);
11887 FreeExpression(watcher);
11888 FreeList(watches, FreeIdentifier);
11891 Compiler_Error($"Invalid object specified and not inside a class\n");
11894 Compiler_Error($"No observer specified and not inside a class\n");
11901 static void ProcessFunction(FunctionDefinition function)
11903 Identifier id = GetDeclId(function.declarator);
11904 Symbol symbol = function.declarator ? function.declarator.symbol : null;
11905 Type type = symbol ? symbol.type : null;
11906 Class oldThisClass = thisClass;
11907 Context oldTopContext = topContext;
11909 yylloc = function.loc;
11910 // Process thisClass
11912 if(type && type.thisClass)
11914 Symbol classSym = type.thisClass;
11915 Class _class = type.thisClass.registered;
11916 char className[1024];
11917 char structName[1024];
11918 Declarator funcDecl;
11921 bool typedObject = false;
11923 if(_class && !_class.base)
11925 _class = currentClass;
11926 if(_class && !_class.symbol)
11927 _class.symbol = FindClass(_class.fullName);
11928 classSym = _class ? _class.symbol : null;
11929 typedObject = true;
11932 thisClass = _class;
11934 if(inCompiler && _class)
11936 if(type.kind == functionType)
11938 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
11940 //TypeName param = symbol.type.params.first;
11941 Type param = symbol.type.params.first;
11942 symbol.type.params.Remove(param);
11943 //FreeTypeName(param);
11946 if(type.classObjectType != classPointer)
11948 symbol.type.params.Insert(null, MkClassType(_class.fullName));
11949 symbol.type.staticMethod = true;
11950 symbol.type.thisClass = null;
11952 // HIGH DANGER: VERIFYING THIS...
11953 symbol.type.extraParam = false;
11957 strcpy(className, "__ecereClass_");
11958 FullClassNameCat(className, _class.fullName, true);
11960 MangleClassName(className);
11963 FullClassNameCat(structName, _class.fullName, false);
11968 funcDecl = GetFuncDecl(function.declarator);
11971 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11973 TypeName param = funcDecl.function.parameters->first;
11974 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11976 funcDecl.function.parameters->Remove(param);
11977 FreeTypeName(param);
11981 // DANGER: Watch for this... Check if it's a Conversion?
11982 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
11984 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
11985 if(!function.propertyNoThis)
11987 TypeName thisParam;
11989 if(type.classObjectType != classPointer)
11991 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
11992 if(!funcDecl.function.parameters)
11993 funcDecl.function.parameters = MkList();
11994 funcDecl.function.parameters->Insert(null, thisParam);
11999 if(type.classObjectType != classPointer)
12001 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12002 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12005 thisParam = TypeName
12007 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12008 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12010 funcDecl.function.parameters->Insert(null, thisParam);
12015 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12017 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12018 funcDecl = GetFuncDecl(initDecl.declarator);
12021 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12023 TypeName param = funcDecl.function.parameters->first;
12024 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12026 funcDecl.function.parameters->Remove(param);
12027 FreeTypeName(param);
12031 if(type.classObjectType != classPointer)
12033 // DANGER: Watch for this... Check if it's a Conversion?
12034 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12036 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12038 if(!funcDecl.function.parameters)
12039 funcDecl.function.parameters = MkList();
12040 funcDecl.function.parameters->Insert(null, thisParam);
12047 // Add this to the context
12050 if(type.classObjectType != classPointer)
12052 thisSymbol = Symbol
12054 string = CopyString("this");
12055 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12057 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12059 if(typedObject && thisSymbol.type)
12061 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12062 thisSymbol.type.byReference = type.byReference;
12063 thisSymbol.type.typedByReference = type.byReference;
12065 thisSymbol = Symbol { string = CopyString("class") };
12066 function.body.compound.context.symbols.Add(thisSymbol);
12072 // Pointer to class data
12074 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12076 DataMember member = null;
12079 for(base = _class; base && base.type != systemClass; base = base.next)
12081 for(member = base.membersAndProperties.first; member; member = member.next)
12082 if(!member.isProperty)
12088 for(member = _class.membersAndProperties.first; member; member = member.next)
12089 if(!member.isProperty)
12093 char pointerName[1024];
12096 Initializer initializer;
12097 Expression exp, bytePtr;
12099 strcpy(pointerName, "__ecerePointer_");
12100 FullClassNameCat(pointerName, _class.fullName, false);
12102 char className[1024];
12103 strcpy(className, "__ecereClass_");
12104 FullClassNameCat(className, classSym.string, true);
12105 MangleClassName(className);
12108 DeclareClass(classSym, className);
12112 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12117 sprintf(string, "%d", _class.offset);
12118 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12122 // ([bytePtr] + [className]->offset)
12123 exp = QBrackets(MkExpOp(bytePtr, '+',
12124 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12127 // (this ? [exp] : 0)
12128 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12132 kind = pointerType;
12133 type = Type { refCount = 1, kind = voidType };
12138 yylloc = function.body.loc;
12139 // ([structName] *) [exp]
12140 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12141 initializer = MkInitializerAssignment(
12142 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12144 // [structName] * [pointerName] = [initializer];
12145 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12148 Context prevContext = curContext;
12149 curContext = function.body.compound.context;
12151 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12152 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12154 curContext = prevContext;
12158 decl.symbol = null;
12160 if(!function.body.compound.declarations)
12161 function.body.compound.declarations = MkList();
12162 function.body.compound.declarations->Insert(null, decl);
12168 // Loop through the function and replace undeclared identifiers
12169 // which are a member of the class (methods, properties or data)
12170 // by "this.[member]"
12177 FreeSpecifier(id._class);
12180 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12182 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12183 id = GetDeclId(initDecl.declarator);
12185 FreeSpecifier(id._class);
12190 topContext = function.body.compound.context;
12192 FunctionDefinition oldFunction = curFunction;
12193 curFunction = function;
12195 ProcessStatement(function.body);
12197 // If this is a property set and no firewatchers has been done yet, add one here
12198 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12200 Statement prevCompound = curCompound;
12201 Context prevContext = curContext;
12203 Statement fireWatchers = MkFireWatchersStmt(null, null);
12204 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12205 ListAdd(function.body.compound.statements, fireWatchers);
12207 curCompound = function.body;
12208 curContext = function.body.compound.context;
12210 ProcessStatement(fireWatchers);
12212 curContext = prevContext;
12213 curCompound = prevCompound;
12217 curFunction = oldFunction;
12220 if(function.declarator)
12222 ProcessDeclarator(function.declarator);
12225 topContext = oldTopContext;
12226 thisClass = oldThisClass;
12229 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12230 static void ProcessClass(OldList definitions, Symbol symbol)
12233 External external = curExternal;
12234 Class regClass = symbol ? symbol.registered : null;
12236 // Process all functions
12237 for(def = definitions.first; def; def = def.next)
12239 if(def.type == functionClassDef)
12241 if(def.function.declarator)
12242 curExternal = def.function.declarator.symbol.pointerExternal;
12244 curExternal = external;
12246 ProcessFunction((FunctionDefinition)def.function);
12248 else if(def.type == declarationClassDef)
12250 if(def.decl.type == instDeclaration)
12252 thisClass = regClass;
12253 ProcessInstantiationType(def.decl.inst);
12259 Class backThisClass = thisClass;
12260 if(regClass) thisClass = regClass;
12261 ProcessDeclaration(def.decl);
12262 thisClass = backThisClass;
12265 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12267 MemberInit defProperty;
12269 // Add this to the context
12270 Symbol thisSymbol = Symbol
12272 string = CopyString("this");
12273 type = regClass ? MkClassType(regClass.fullName) : null;
12275 globalContext.symbols.Add((BTNode)thisSymbol);
12277 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12279 thisClass = regClass;
12280 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12284 globalContext.symbols.Remove((BTNode)thisSymbol);
12285 FreeSymbol(thisSymbol);
12287 else if(def.type == propertyClassDef && def.propertyDef)
12289 PropertyDef prop = def.propertyDef;
12291 // Add this to the context
12293 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12294 globalContext.symbols.Add(thisSymbol);
12297 thisClass = regClass;
12304 string = CopyString("this");
12305 type = MkClassType(regClass.fullName);
12307 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12310 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12311 ProcessStatement(prop.setStmt);
12319 string = CopyString("this");
12320 type = MkClassType(regClass.fullName);
12322 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12325 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12326 ProcessStatement(prop.getStmt);
12334 string = CopyString("this");
12335 type = MkClassType(regClass.fullName);
12337 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12340 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12341 ProcessStatement(prop.issetStmt);
12347 globalContext.symbols.Remove(thisSymbol);
12348 FreeSymbol(thisSymbol);
12351 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12353 PropertyWatch propertyWatch = def.propertyWatch;
12355 thisClass = regClass;
12356 if(propertyWatch.compound)
12360 string = CopyString("this");
12361 type = regClass ? MkClassType(regClass.fullName) : null;
12364 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12366 curExternal = null;
12367 ProcessStatement(propertyWatch.compound);
12374 void DeclareFunctionUtil(String s)
12376 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12381 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12382 strcpy(name, "__ecereFunction_");
12383 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12384 DeclareFunction(function, name);
12388 void ComputeDataTypes()
12392 External after = null;
12394 currentClass = null;
12396 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12398 for(external = ast->first; external; external = external.next)
12400 if(external.type == declarationExternal)
12402 Declaration decl = external.declaration;
12405 OldList * decls = decl.declarators;
12408 InitDeclarator initDecl = decls->first;
12411 Declarator declarator = initDecl.declarator;
12412 if(declarator && declarator.type == identifierDeclarator)
12414 Identifier id = declarator.identifier;
12415 if(id && id.string)
12417 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12419 external.symbol.id = -1001, external.symbol.idCode = -1001;
12430 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12431 ast->Insert(after, temp);
12432 curExternal = temp;
12434 DeclareFunctionUtil("eSystem_New");
12435 DeclareFunctionUtil("eSystem_New0");
12436 DeclareFunctionUtil("eSystem_Renew");
12437 DeclareFunctionUtil("eSystem_Renew0");
12438 DeclareFunctionUtil("eSystem_Delete");
12439 DeclareFunctionUtil("eClass_GetProperty");
12440 DeclareFunctionUtil("eInstance_FireSelfWatchers");
12442 DeclareStruct("ecere::com::Class", false);
12443 DeclareStruct("ecere::com::Instance", false);
12444 DeclareStruct("ecere::com::Property", false);
12445 DeclareStruct("ecere::com::DataMember", false);
12446 DeclareStruct("ecere::com::Method", false);
12447 DeclareStruct("ecere::com::SerialBuffer", false);
12448 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12452 for(external = ast->first; external; external = external.next)
12454 afterExternal = curExternal = external;
12455 if(external.type == functionExternal)
12457 currentClass = external.function._class;
12458 ProcessFunction(external.function);
12460 // There shouldn't be any _class member access here anyways...
12461 else if(external.type == declarationExternal)
12463 currentClass = null;
12464 ProcessDeclaration(external.declaration);
12466 else if(external.type == classExternal)
12468 ClassDefinition _class = external._class;
12469 currentClass = external.symbol.registered;
12470 if(_class.definitions)
12472 ProcessClass(_class.definitions, _class.symbol);
12476 // Free class data...
12477 ast->Remove(external);
12481 else if(external.type == nameSpaceExternal)
12483 thisNameSpace = external.id.string;
12486 currentClass = null;
12487 thisNameSpace = null;
12489 delete temp.symbol;