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, i64, int64, PrintInt64) \
4009 macro(o, UInt64##name, ui64, uint64, 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, i64, int64, PrintInt64) \
4021 macro(o, UInt64##name, ui64, uint64, 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.type == stringExp && op.kind == pointerType)
4197 op.ui64 = (uint64)exp.string;
4198 op.kind = pointerType;
4201 else if(exp.isConstant && exp.type == constantExp)
4208 if(exp.constant[0] == '\'')
4209 op.c = exp.constant[1];
4210 else if(type.isSigned)
4212 op.c = (char)strtol(exp.constant, null, 0);
4217 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4225 op.s = (short)strtol(exp.constant, null, 0);
4230 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4238 op.i = (int)strtol(exp.constant, null, 0);
4243 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4251 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4256 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4259 op.kind = int64Type;
4264 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4269 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4272 op.kind = int64Type;
4277 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4282 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4285 op.kind = int64Type;
4288 op.f = (float)strtod(exp.constant, null);
4292 op.d = (double)strtod(exp.constant, null);
4295 //case classType: For when we have operator overloading...
4296 // Pointer additions
4297 //case functionType:
4301 op.ui64 = _strtoui64(exp.constant, null, 0);
4302 op.kind = pointerType;
4312 static void UnusedFunction()
4315 a.OnGetString(0,0,0);
4318 extern int __ecereVMethodID_class_OnGetString;
4321 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4323 DataMember dataMember;
4324 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4326 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4327 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4331 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4333 void * ptr = inst.data + dataMember.offset + offset;
4334 char * result = null;
4335 exp.loc = member.loc = inst.loc;
4336 ((Identifier)member.identifiers->first).loc = inst.loc;
4338 if(!dataMember.dataType)
4339 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4340 type = dataMember.dataType;
4341 if(type.kind == classType)
4343 Class _class = type._class.registered;
4344 if(_class.type == enumClass)
4346 Class enumClass = eSystem_FindClass(privateModule, "enum");
4349 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4351 for(item = e.values.first; item; item = item.next)
4353 if((int)item.data == *(int *)ptr)
4361 exp.identifier = MkIdentifier(result);
4362 exp.type = identifierExp;
4363 exp.destType = MkClassType(_class.fullName);
4364 ProcessExpressionType(exp);
4368 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4370 if(!_class.dataType)
4371 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4372 type = _class.dataType;
4381 FreeExpContents(exp);
4383 exp.constant = PrintFloat(*(float*)ptr);
4384 exp.type = constantExp;
4389 FreeExpContents(exp);
4391 exp.constant = PrintDouble(*(double*)ptr);
4392 exp.type = constantExp;
4397 FreeExpContents(exp);
4399 exp.constant = PrintInt(*(int*)ptr);
4400 exp.type = constantExp;
4405 FreeExpContents(exp);
4407 exp.constant = PrintInt64(*(int64*)ptr);
4408 exp.type = constantExp;
4413 FreeExpContents(exp);
4414 // TODO: This should probably use proper type
4415 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4416 exp.type = constantExp;
4421 FreeExpContents(exp);
4422 // TODO: This should probably use proper type
4423 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4424 exp.type = constantExp;
4428 Compiler_Error($"Unhandled type populating instance\n");
4431 ListAdd(memberList, member);
4434 if(parentDataMember.type == unionMember)
4439 void PopulateInstance(Instantiation inst)
4441 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4442 Class _class = classSym.registered;
4443 DataMember dataMember;
4444 OldList * memberList = MkList();
4445 // Added this check and ->Add to prevent memory leaks on bad code
4447 inst.members = MkListOne(MkMembersInitList(memberList));
4449 inst.members->Add(MkMembersInitList(memberList));
4450 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4452 if(!dataMember.isProperty)
4454 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4455 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4459 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4461 void * ptr = inst.data + dataMember.offset;
4462 char * result = null;
4464 exp.loc = member.loc = inst.loc;
4465 ((Identifier)member.identifiers->first).loc = inst.loc;
4467 if(!dataMember.dataType)
4468 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4469 type = dataMember.dataType;
4470 if(type.kind == classType)
4472 Class _class = type._class.registered;
4473 if(_class.type == enumClass)
4475 Class enumClass = eSystem_FindClass(privateModule, "enum");
4478 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4480 for(item = e.values.first; item; item = item.next)
4482 if((int)item.data == *(int *)ptr)
4491 exp.identifier = MkIdentifier(result);
4492 exp.type = identifierExp;
4493 exp.destType = MkClassType(_class.fullName);
4494 ProcessExpressionType(exp);
4497 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4499 if(!_class.dataType)
4500 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4501 type = _class.dataType;
4510 exp.constant = PrintFloat(*(float*)ptr);
4511 exp.type = constantExp;
4516 exp.constant = PrintDouble(*(double*)ptr);
4517 exp.type = constantExp;
4522 exp.constant = PrintInt(*(int*)ptr);
4523 exp.type = constantExp;
4528 exp.constant = PrintInt64(*(int64*)ptr);
4529 exp.type = constantExp;
4534 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4535 exp.type = constantExp;
4539 Compiler_Error($"Unhandled type populating instance\n");
4542 ListAdd(memberList, member);
4548 void ComputeInstantiation(Expression exp)
4550 Instantiation inst = exp.instance;
4551 MembersInit members;
4552 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4553 Class _class = classSym ? classSym.registered : null;
4554 DataMember curMember = null;
4555 Class curClass = null;
4556 DataMember subMemberStack[256];
4557 int subMemberStackPos = 0;
4560 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4562 // Don't recompute the instantiation...
4563 // Non Simple classes will have become constants by now
4567 if(_class.type == normalClass || _class.type == noHeadClass)
4569 inst.data = (byte *)eInstance_New(_class);
4570 if(_class.type == normalClass)
4571 ((Instance)inst.data)._refCount++;
4574 inst.data = new0 byte[_class.structSize];
4579 for(members = inst.members->first; members; members = members.next)
4581 switch(members.type)
4583 case dataMembersInit:
4585 if(members.dataMembers)
4588 for(member = members.dataMembers->first; member; member = member.next)
4590 Identifier ident = member.identifiers ? member.identifiers->first : null;
4593 Property prop = null;
4594 DataMember dataMember = null;
4595 Method method = null;
4596 uint dataMemberOffset;
4600 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4603 if(curMember.isProperty)
4604 prop = (Property)curMember;
4607 dataMember = curMember;
4609 // CHANGED THIS HERE
4610 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4612 // 2013/17/29 -- It seems that this was missing here!
4613 if(_class.type == normalClass)
4614 dataMemberOffset += _class.base.structSize;
4615 // dataMemberOffset = dataMember.offset;
4622 prop = eClass_FindProperty(_class, ident.string, privateModule);
4626 if(prop.memberAccess == publicAccess)
4628 curMember = (DataMember)prop;
4629 curClass = prop._class;
4634 DataMember _subMemberStack[256];
4635 int _subMemberStackPos = 0;
4637 // FILL MEMBER STACK
4638 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4643 if(dataMember.memberAccess == publicAccess)
4645 curMember = dataMember;
4646 curClass = dataMember._class;
4647 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4648 subMemberStackPos = _subMemberStackPos;
4654 if(found && member.initializer && member.initializer.type == expInitializer)
4656 Expression value = member.initializer.exp;
4658 bool deepMember = false;
4661 type = prop.dataType;
4665 if(!dataMember.dataType)
4666 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4668 type = dataMember.dataType;
4671 if(ident && ident.next)
4675 // for(; ident && type; ident = ident.next)
4676 for(ident = ident.next; ident && type; ident = ident.next)
4678 if(type.kind == classType)
4680 prop = eClass_FindProperty(type._class.registered,
4681 ident.string, privateModule);
4683 type = prop.dataType;
4686 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4687 ident.string, &dataMemberOffset, privateModule, null, null);
4689 type = dataMember.dataType;
4692 else if(type.kind == structType || type.kind == unionType)
4695 for(memberType = type.members.first; memberType; memberType = memberType.next)
4697 if(!strcmp(memberType.name, ident.string))
4708 FreeType(value.destType);
4709 value.destType = type;
4710 if(type) type.refCount++;
4711 ComputeExpression(value);
4713 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4715 if(type.kind == classType)
4717 Class _class = type._class.registered;
4718 if(_class.type == bitClass || _class.type == unitClass ||
4719 _class.type == enumClass)
4721 if(!_class.dataType)
4722 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4723 type = _class.dataType;
4729 void * ptr = inst.data + dataMemberOffset;
4731 if(value.type == constantExp)
4737 GetInt(value, (int*)ptr);
4742 GetInt64(value, (int64*)ptr);
4747 GetIntPtr(value, (intptr*)ptr);
4752 GetIntSize(value, (intsize*)ptr);
4757 GetFloat(value, (float*)ptr);
4762 GetDouble(value, (double *)ptr);
4767 else if(value.type == instanceExp)
4769 if(type.kind == classType)
4771 Class _class = type._class.registered;
4772 if(_class.type == structClass)
4774 ComputeTypeSize(type);
4775 if(value.instance.data)
4776 memcpy(ptr, value.instance.data, type.size);
4783 if(value.type == instanceExp && value.instance.data)
4785 if(type.kind == classType)
4787 Class _class = type._class.registered;
4788 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
4790 void (*Set)(void *, void *) = (void *)prop.Set;
4791 Set(inst.data, value.instance.data);
4792 PopulateInstance(inst);
4796 else if(value.type == constantExp)
4802 void (*Set)(void *, double) = (void *)prop.Set;
4803 Set(inst.data, strtod(value.constant, null) );
4808 void (*Set)(void *, float) = (void *)prop.Set;
4809 Set(inst.data, (float)(strtod(value.constant, null)));
4814 void (*Set)(void *, int) = (void *)prop.Set;
4815 Set(inst.data, (int)strtol(value.constant, null, 0));
4820 void (*Set)(void *, int64) = (void *)prop.Set;
4821 Set(inst.data, _strtoi64(value.constant, null, 0));
4826 void (*Set)(void *, intptr) = (void *)prop.Set;
4827 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
4832 void (*Set)(void *, intsize) = (void *)prop.Set;
4833 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
4838 else if(value.type == stringExp)
4841 ReadString(temp, value.string);
4842 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
4846 else if(!deepMember && type && _class.type == unitClass)
4850 // Only support converting units to units for now...
4851 if(value.type == constantExp)
4853 if(type.kind == classType)
4855 Class _class = type._class.registered;
4856 if(_class.type == unitClass)
4858 if(!_class.dataType)
4859 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4860 type = _class.dataType;
4863 // TODO: Assuming same base type for units...
4869 float (*Set)(float) = (void *)prop.Set;
4870 GetFloat(member.initializer.exp, &fValue);
4871 exp.constant = PrintFloat(Set(fValue));
4872 exp.type = constantExp;
4878 double (*Set)(double) = (void *)prop.Set;
4879 GetDouble(member.initializer.exp, &dValue);
4880 exp.constant = PrintDouble(Set(dValue));
4881 exp.type = constantExp;
4888 else if(!deepMember && type && _class.type == bitClass)
4892 if(value.type == instanceExp && value.instance.data)
4894 unsigned int (*Set)(void *) = (void *)prop.Set;
4895 bits = Set(value.instance.data);
4897 else if(value.type == constantExp)
4903 BitMember bitMember = (BitMember) dataMember;
4906 GetInt(value, &part);
4907 bits = (bits & ~bitMember.mask);
4908 if(!bitMember.dataType)
4909 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
4911 type = bitMember.dataType;
4913 if(type.kind == classType && type._class && type._class.registered)
4915 if(!type._class.registered.dataType)
4916 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4917 type = type._class.registered.dataType;
4925 bits |= ((char)part << bitMember.pos);
4927 bits |= ((unsigned char)part << bitMember.pos);
4931 bits |= ((short)part << bitMember.pos);
4933 bits |= ((unsigned short)part << bitMember.pos);
4938 bits |= ((int)part << bitMember.pos);
4940 bits |= ((unsigned int)part << bitMember.pos);
4944 bits |= ((int64)part << bitMember.pos);
4946 bits |= ((uint64)part << bitMember.pos);
4951 bits |= ((intptr)part << bitMember.pos);
4955 bits |= ((uintptr)part << bitMember.pos);
4961 bits |= ((ssize_t)(intsize)part << bitMember.pos);
4965 bits |= ((size_t) (uintsize)part << bitMember.pos);
4974 if(_class && _class.type == unitClass)
4976 ComputeExpression(member.initializer.exp);
4977 exp.constant = member.initializer.exp.constant;
4978 exp.type = constantExp;
4980 member.initializer.exp.constant = null;
4990 if(_class && _class.type == bitClass)
4992 exp.constant = PrintHexUInt(bits);
4993 exp.type = constantExp;
4995 if(exp.type != instanceExp)
5001 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5003 if(exp.op.op == SIZEOF)
5005 FreeExpContents(exp);
5006 exp.type = constantExp;
5007 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5018 // Provide default unary +
5019 Expression exp2 = exp.op.exp2;
5021 FreeExpContents(exp);
5022 FreeType(exp.expType);
5023 FreeType(exp.destType);
5029 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5031 // unary arithmetic increment and decrement
5032 //OPERATOR_ALL(UNARY, ++, Inc)
5033 //OPERATOR_ALL(UNARY, --, Dec)
5036 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5038 // unary logical negation
5040 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5048 // binary arithmetic
5050 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5053 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5056 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5059 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5062 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5064 // binary arithmetic assignment
5065 //OPERATOR_ALL(BINARY, =, Asign)
5066 //OPERATOR_ALL(BINARY, +=, AddAsign)
5067 //OPERATOR_ALL(BINARY, -=, SubAsign)
5068 //OPERATOR_ALL(BINARY, *=, MulAsign)
5069 //OPERATOR_ALL(BINARY, /=, DivAsign)
5070 //OPERATOR_ALL(BINARY, %=, ModAsign)
5075 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5079 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5082 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5085 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5088 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5090 // binary bitwise assignment
5091 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5092 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5093 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5094 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5095 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5096 // binary logical equality
5098 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5101 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5105 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5108 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5110 // binary logical relational
5112 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5115 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5118 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5121 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5128 void ComputeExpression(Expression exp)
5130 char expString[10240];
5131 expString[0] = '\0';
5133 PrintExpression(exp, expString);
5140 ComputeInstantiation(exp);
5149 Expression exp1, exp2 = null;
5153 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5155 ComputeExpression(exp.op.exp2);
5158 ComputeExpression(exp.op.exp1);
5161 op1 = GetOperand(exp1);
5162 if(op1.type) op1.type.refCount++;
5165 op2 = GetOperand(exp2);
5166 if(op2.type) op2.type.refCount++;
5172 op1 = GetOperand(exp1);
5173 if(op1.type) op1.type.refCount++;
5176 CallOperator(exp, exp1, exp2, op1, op2);
5183 if(exp.op.exp1 && exp.op.exp2)
5188 FreeExpContents(exp);
5189 op1.ops.BitAnd(exp, op1, op2);
5198 FreeExpContents(exp);
5199 op1.ops.Mul(exp, op1, op2);
5208 FreeExpContents(exp);
5209 op1.ops.Add(exp, op1, op2);
5214 // Provide default unary +
5215 Expression exp2 = exp.op.exp2;
5217 FreeExpContents(exp);
5218 FreeType(exp.expType);
5219 FreeType(exp.destType);
5230 FreeExpContents(exp);
5231 op1.ops.Sub(exp, op1, op2);
5238 FreeExpContents(exp);
5239 op1.ops.Neg(exp, op1);
5246 FreeExpContents(exp);
5247 op1.ops.BitNot(exp, op1);
5253 FreeExpContents(exp);
5254 op1.ops.Not(exp, op1);
5257 // Binary only operators
5261 FreeExpContents(exp);
5262 op1.ops.Div(exp, op1, op2);
5268 FreeExpContents(exp);
5269 op1.ops.Mod(exp, op1, op2);
5281 FreeExpContents(exp);
5282 op1.ops.Sma(exp, op1, op2);
5291 FreeExpContents(exp);
5292 op1.ops.Grt(exp, op1, op2);
5301 FreeExpContents(exp);
5302 op1.ops.SmaEqu(exp, op1, op2);
5311 FreeExpContents(exp);
5312 op1.ops.GrtEqu(exp, op1, op2);
5321 FreeExpContents(exp);
5322 op1.ops.Equ(exp, op1, op2);
5331 FreeExpContents(exp);
5332 op1.ops.Nqu(exp, op1, op2);
5339 FreeExpContents(exp);
5340 op1.ops.BitOr(exp, op1, op2);
5346 FreeExpContents(exp);
5347 op1.ops.BitXor(exp, op1, op2);
5355 FreeExpContents(exp);
5356 exp.type = constantExp;
5357 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5361 if(op1.type) FreeType(op1.type);
5362 if(op2.type) FreeType(op2.type);
5366 case extensionExpressionExp:
5369 for(e = exp.list->first; e; e = n)
5374 OldList * list = exp.list;
5375 ComputeExpression(e);
5376 //FreeExpContents(exp);
5377 FreeType(exp.expType);
5378 FreeType(exp.destType);
5395 exp.isConstant = true;
5397 ComputeExpression(exp.index.exp);
5398 if(!exp.index.exp.isConstant)
5399 exp.isConstant = false;
5401 for(e = exp.index.index->first; e; e = e.next)
5403 ComputeExpression(e);
5406 // Check if this type is int
5409 exp.isConstant = false;
5411 exp.expType = Dereference(exp.index.exp.expType);
5417 Expression memberExp = exp.member.exp;
5418 Identifier memberID = exp.member.member;
5421 ComputeExpression(exp.member.exp);
5422 type = exp.member.exp.expType;
5425 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);
5426 Property prop = null;
5427 DataMember member = null;
5428 Class convertTo = null;
5429 if(type.kind == subClassType && exp.member.exp.type == classExp)
5430 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5437 PrintTypeNoConst(type, string, false, true);
5438 classSym = FindClass(string);
5439 _class = classSym ? classSym.registered : null;
5442 if(exp.member.member)
5444 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5446 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5448 if(!prop && !member && _class && exp.member.member)
5450 Symbol classSym = FindClass(exp.member.member.string);
5452 _class = classSym ? classSym.registered : null;
5453 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5460 Type type = prop.dataType;
5461 // TODO: Assuming same base type for units...
5462 if(_class.type == unitClass)
5464 if(type.kind == classType)
5466 Class _class = type._class.registered;
5467 if(_class.type == unitClass)
5469 if(!_class.dataType)
5470 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5471 type = _class.dataType;
5479 float (*Get)(float) = (void *)prop.Get;
5480 GetFloat(exp.member.exp, &value);
5481 exp.constant = PrintFloat(Get ? Get(value) : value);
5482 exp.type = constantExp;
5488 double (*Get)(double);
5489 GetDouble(exp.member.exp, &value);
5492 Get = (void *)prop.Set;
5494 Get = (void *)prop.Get;
5495 exp.constant = PrintDouble(Get ? Get(value) : value);
5496 exp.type = constantExp;
5505 Expression value = exp.member.exp;
5508 ProcessPropertyType(prop);
5510 type = prop.dataType;
5513 // printf("Investigate this\n");
5515 else if(_class.type == structClass)
5521 Class propertyClass = type._class.registered;
5522 if(propertyClass.type == structClass && value.type == instanceExp)
5524 void (*Set)(void *, void *) = (void *)prop.Set;
5525 exp.instance = Instantiation { };
5526 exp.instance.data = new0 byte[_class.structSize];
5527 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5528 exp.instance.loc = exp.loc;
5529 exp.type = instanceExp;
5530 Set(exp.instance.data, value.instance.data);
5531 PopulateInstance(exp.instance);
5538 void (*Set)(void *, int) = (void *)prop.Set;
5540 exp.instance = Instantiation { };
5541 exp.instance.data = new0 byte[_class.structSize];
5542 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5543 exp.instance.loc = exp.loc;
5544 exp.type = instanceExp;
5546 GetInt(value, &intValue);
5548 Set(exp.instance.data, intValue);
5549 PopulateInstance(exp.instance);
5555 void (*Set)(void *, int64) = (void *)prop.Set;
5557 exp.instance = Instantiation { };
5558 exp.instance.data = new0 byte[_class.structSize];
5559 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5560 exp.instance.loc = exp.loc;
5561 exp.type = instanceExp;
5563 GetInt64(value, &intValue);
5565 Set(exp.instance.data, intValue);
5566 PopulateInstance(exp.instance);
5573 void (*Set)(void *, intptr) = (void *)prop.Set;
5575 exp.instance = Instantiation { };
5576 exp.instance.data = new0 byte[_class.structSize];
5577 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5578 exp.instance.loc = exp.loc;
5579 exp.type = instanceExp;
5581 GetIntPtr(value, &intValue);
5583 Set(exp.instance.data, intValue);
5584 PopulateInstance(exp.instance);
5591 void (*Set)(void *, intsize) = (void *)prop.Set;
5593 exp.instance = Instantiation { };
5594 exp.instance.data = new0 byte[_class.structSize];
5595 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5596 exp.instance.loc = exp.loc;
5597 exp.type = instanceExp;
5599 GetIntSize(value, &intValue);
5601 Set(exp.instance.data, intValue);
5602 PopulateInstance(exp.instance);
5608 void (*Set)(void *, double) = (void *)prop.Set;
5610 exp.instance = Instantiation { };
5611 exp.instance.data = new0 byte[_class.structSize];
5612 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5613 exp.instance.loc = exp.loc;
5614 exp.type = instanceExp;
5616 GetDouble(value, &doubleValue);
5618 Set(exp.instance.data, doubleValue);
5619 PopulateInstance(exp.instance);
5624 else if(_class.type == bitClass)
5630 Class propertyClass = type._class.registered;
5631 if(propertyClass.type == structClass && value.instance.data)
5633 unsigned int (*Set)(void *) = (void *)prop.Set;
5634 unsigned int bits = Set(value.instance.data);
5635 exp.constant = PrintHexUInt(bits);
5636 exp.type = constantExp;
5639 else if(_class.type == bitClass)
5642 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5645 GetUInt(exp.member.exp, &value);
5647 exp.constant = PrintHexUInt(bits);
5648 exp.type = constantExp;
5656 if(_class.type == bitClass)
5659 GetUInt(exp.member.exp, &value);
5665 Class _class = type._class.registered;
5666 if(_class.type == structClass)
5668 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5670 exp.instance = Instantiation { };
5671 exp.instance.data = new0 byte[_class.structSize];
5672 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5673 exp.instance.loc = exp.loc;
5674 //exp.instance.fullSet = true;
5675 exp.type = instanceExp;
5676 Get(value, exp.instance.data);
5677 PopulateInstance(exp.instance);
5679 else if(_class.type == bitClass)
5681 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5682 uint64 bits = Get(value);
5683 exp.constant = PrintHexUInt64(bits);
5684 exp.type = constantExp;
5690 else if(_class.type == structClass)
5692 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5697 Class _class = type._class.registered;
5698 if(_class.type == structClass && value)
5700 void (*Get)(void *, void *) = (void *)prop.Get;
5702 exp.instance = Instantiation { };
5703 exp.instance.data = new0 byte[_class.structSize];
5704 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5705 exp.instance.loc = exp.loc;
5706 //exp.instance.fullSet = true;
5707 exp.type = instanceExp;
5708 Get(value, exp.instance.data);
5709 PopulateInstance(exp.instance);
5717 char * value = exp.member.exp.instance.data;
5722 Class _class = type._class.registered;
5723 if(_class.type == normalClass)
5725 void *(*Get)(void *) = (void *)prop.Get;
5727 exp.instance = Instantiation { };
5728 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5729 exp.type = instanceExp;
5730 exp.instance.data = Get(value, exp.instance.data);
5742 exp.isConstant = false;
5750 if(exp.type != ExpressionType::memberExp)
5752 FreeExpression(memberExp);
5753 FreeIdentifier(memberID);
5759 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5760 FreeExpContents(exp);
5761 exp.constant = PrintUInt(ComputeTypeSize(type));
5762 exp.type = constantExp;
5768 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5769 if(classSym && classSym.registered)
5771 if(classSym.registered.fixed)
5773 FreeSpecifier(exp._class);
5774 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5775 exp.type = constantExp;
5779 char className[1024];
5780 strcpy(className, "__ecereClass_");
5781 FullClassNameCat(className, classSym.string, true);
5782 MangleClassName(className);
5784 DeclareClass(classSym, className);
5786 FreeExpContents(exp);
5787 exp.type = pointerExp;
5788 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5789 exp.member.member = MkIdentifier("structSize");
5799 if(exp.type == castExp)
5802 ComputeExpression(exp.cast.exp);
5805 if(e && exp.expType)
5808 type = exp.destType;
5811 if(type.kind == classType)
5813 Class _class = type._class.registered;
5814 if(_class && (_class.type == unitClass || _class.type == bitClass))
5816 if(!_class.dataType)
5817 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5818 type = _class.dataType;
5830 FreeExpContents(exp);
5831 exp.constant = PrintChar(value);
5832 exp.type = constantExp;
5836 unsigned char value;
5837 GetUChar(e, &value);
5838 FreeExpContents(exp);
5839 exp.constant = PrintUChar(value);
5840 exp.type = constantExp;
5847 GetShort(e, &value);
5848 FreeExpContents(exp);
5849 exp.constant = PrintShort(value);
5850 exp.type = constantExp;
5854 unsigned short value;
5855 GetUShort(e, &value);
5856 FreeExpContents(exp);
5857 exp.constant = PrintUShort(value);
5858 exp.type = constantExp;
5866 FreeExpContents(exp);
5867 exp.constant = PrintInt(value);
5868 exp.type = constantExp;
5874 FreeExpContents(exp);
5875 exp.constant = PrintUInt(value);
5876 exp.type = constantExp;
5883 GetInt64(e, &value);
5884 FreeExpContents(exp);
5885 exp.constant = PrintInt64(value);
5886 exp.type = constantExp;
5891 GetUInt64(e, &value);
5892 FreeExpContents(exp);
5893 exp.constant = PrintUInt64(value);
5894 exp.type = constantExp;
5901 GetIntPtr(e, &value);
5902 FreeExpContents(exp);
5903 exp.constant = PrintInt64((int64)value);
5904 exp.type = constantExp;
5909 GetUIntPtr(e, &value);
5910 FreeExpContents(exp);
5911 exp.constant = PrintUInt64((uint64)value);
5912 exp.type = constantExp;
5919 GetIntSize(e, &value);
5920 FreeExpContents(exp);
5921 exp.constant = PrintInt64((int64)value);
5922 exp.type = constantExp;
5927 GetUIntSize(e, &value);
5928 FreeExpContents(exp);
5929 exp.constant = PrintUInt64((uint64)value);
5930 exp.type = constantExp;
5936 GetFloat(e, &value);
5937 FreeExpContents(exp);
5938 exp.constant = PrintFloat(value);
5939 exp.type = constantExp;
5945 GetDouble(e, &value);
5946 FreeExpContents(exp);
5947 exp.constant = PrintDouble(value);
5948 exp.type = constantExp;
5962 // Caring only about last expression for now...
5963 ComputeExpression(exp.cond.exp->last);
5964 if(exp.cond.elseExp)
5965 ComputeExpression(exp.cond.elseExp);
5967 ComputeExpression(exp.cond.cond);
5969 op1 = GetOperand(exp.cond.cond);
5970 if(op1.type) op1.type.refCount++;
5971 op2 = GetOperand(exp.cond.exp->last);
5972 if(op2.type) op2.type.refCount++;
5973 op3 = GetOperand(exp.cond.elseExp);
5974 if(op3.type) op3.type.refCount++;
5976 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
5977 if(op1.type) FreeType(op1.type);
5978 if(op2.type) FreeType(op2.type);
5979 if(op3.type) FreeType(op3.type);
5985 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
5990 OldList converts { };
5993 if(destType.kind == voidType)
5996 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
6000 // for(convert = converts.last; convert; convert = convert.prev)
6001 for(convert = converts.first; convert; convert = convert.next)
6003 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6006 Expression newExp { };
6007 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6009 // TODO: Check this...
6011 newExp.destType = null;
6016 exp.type = memberExp;
6017 exp.addedThis = true;
6018 exp.member.exp = newExp;
6019 FreeType(exp.member.exp.expType);
6021 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6022 exp.member.exp.expType.classObjectType = objectType;
6023 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6024 exp.member.memberType = propertyMember;
6025 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6026 // TESTING THIS... for (int)degrees
6027 exp.needCast = true;
6028 if(exp.expType) exp.expType.refCount++;
6029 ApplyAnyObjectLogic(exp.member.exp);
6034 /*if(exp.isConstant)
6036 // Color { ColorRGB = [exp] };
6037 exp.type = instanceExp;
6038 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6039 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6040 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6044 // If not constant, don't turn it yet into an instantiation
6045 // (Go through the deep members system first)
6046 exp.type = memberExp;
6047 exp.addedThis = true;
6048 exp.member.exp = newExp;
6050 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6051 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6052 newExp.expType._class.registered.type == noHeadClass)
6054 newExp.byReference = true;
6057 FreeType(exp.member.exp.expType);
6058 /*exp.member.exp.expType = convert.convert.dataType;
6059 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6060 exp.member.exp.expType = null;
6061 if(convert.convert.dataType)
6063 exp.member.exp.expType = { };
6064 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6065 exp.member.exp.expType.refCount = 1;
6066 exp.member.exp.expType.classObjectType = objectType;
6067 ApplyAnyObjectLogic(exp.member.exp);
6070 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6071 exp.member.memberType = reverseConversionMember;
6072 exp.expType = convert.resultType ? convert.resultType :
6073 MkClassType(convert.convert._class.fullName);
6074 exp.needCast = true;
6075 if(convert.resultType) convert.resultType.refCount++;
6081 FreeType(exp.expType);
6084 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6085 exp.needCast = true;
6086 if(exp.expType) exp.expType.refCount++;
6090 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6091 exp.needCast = true;
6092 if(convert.resultType)
6093 convert.resultType.refCount++;
6097 if(exp.isConstant && inCompiler)
6098 ComputeExpression(exp);
6100 converts.Free(FreeConvert);
6103 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6105 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6107 if(!result && exp.expType && exp.destType)
6109 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6110 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6111 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6112 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6116 // if(result) CheckTemplateTypes(exp);
6120 void CheckTemplateTypes(Expression exp)
6122 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6124 Expression newExp { };
6128 if(exp.destType) exp.destType.refCount++;
6129 if(exp.expType) exp.expType.refCount++;
6133 switch(exp.expType.kind)
6136 if(exp.destType.classObjectType)
6138 // We need to pass the address, just pass it along (Undo what was done above)
6139 if(exp.destType) exp.destType.refCount--;
6140 if(exp.expType) exp.expType.refCount--;
6145 // If we're looking for value:
6146 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6148 OldList * unionDefs = MkList();
6149 OldList * statements = MkList();
6150 context = PushContext();
6151 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6152 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6153 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6154 exp.type = extensionCompoundExp;
6155 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6156 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6157 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6158 exp.compound.compound.context = context;
6159 PopContext(context);
6164 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6165 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6169 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6171 Expression newExp { };
6175 if(exp.destType) exp.destType.refCount++;
6176 if(exp.expType) exp.expType.refCount++;
6180 switch(exp.expType.kind)
6183 if(exp.destType.classObjectType)
6185 // We need to pass the address, just pass it along (Undo what was done above)
6186 if(exp.destType) exp.destType.refCount--;
6187 if(exp.expType) exp.expType.refCount--;
6192 // If we're looking for value:
6193 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6195 OldList * unionDefs = MkList();
6196 OldList * statements = MkList();
6197 context = PushContext();
6198 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6199 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6200 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6201 exp.type = extensionCompoundExp;
6202 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6203 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6204 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6205 exp.compound.compound.context = context;
6206 PopContext(context);
6211 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6213 exp.type = bracketsExp;
6214 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6215 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6216 ProcessExpressionType(exp.list->first);
6221 exp.type = bracketsExp;
6222 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6223 newExp.needCast = true;
6224 ProcessExpressionType(exp.list->first);
6230 if(exp.expType.kind == templateType)
6232 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6235 FreeType(exp.destType);
6236 FreeType(exp.expType);
6241 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6246 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6247 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6251 char typeString[1024];
6253 OldList * specs = MkList();
6254 typeString[0] = '\0';
6255 PrintType(exp.expType, typeString, false, false);
6256 decl = SpecDeclFromString(typeString, specs, null);
6259 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6260 exp.cast.typeName = MkTypeName(specs, decl);
6261 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6262 exp.cast.exp.needCast = true;
6269 // TODO: The Symbol tree should be reorganized by namespaces
6271 // - Tree of all symbols within (stored without namespace)
6272 // - Tree of sub-namespaces
6274 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6276 int nsLen = strlen(nameSpace);
6278 // Start at the name space prefix
6279 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6281 char * s = symbol.string;
6282 if(!strncmp(s, nameSpace, nsLen))
6284 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6287 for(c = strlen(s)-1; c >= 0; c--)
6292 if(!strcmp(namePart, name))
6294 // TODO: Error on ambiguity
6304 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6307 char nameSpace[1024];
6309 bool gotColon = false;
6311 nameSpace[0] = '\0';
6312 for(c = strlen(name)-1; c >= 0; c--)
6319 namePart = name+c+1;
6320 while(c >= 0 && name[c] == ':') c--;
6323 // Try an exact match first
6324 Symbol symbol = (Symbol)tree.FindString(name);
6328 // Namespace specified
6329 memcpy(nameSpace, name, c + 1);
6332 return ScanWithNameSpace(tree, nameSpace, namePart);
6336 // Looking for a global symbol, e.g. ::Sleep()
6337 Symbol symbol = (Symbol)tree.FindString(namePart);
6342 // Name only (no namespace specified)
6343 Symbol symbol = (Symbol)tree.FindString(namePart);
6346 return ScanWithNameSpace(tree, "", namePart);
6351 static void ProcessDeclaration(Declaration decl);
6353 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6356 //Time startTime = GetTime();
6358 // Optimize this later? Do this before/less?
6360 Symbol symbol = null;
6361 // First, check if the identifier is declared inside the function
6362 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6364 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6366 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6372 strcpy(curName, thisNameSpace);
6373 strcat(curName, "::");
6374 strcat(curName, name);
6375 // Try to resolve in current namespace first
6376 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6379 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6382 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6384 if(symbol || ctx == endContext) break;
6386 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6388 if(symbol.pointerExternal.type == functionExternal)
6390 FunctionDefinition function = symbol.pointerExternal.function;
6392 // Modified this recently...
6393 Context tmpContext = curContext;
6395 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6396 curContext = tmpContext;
6398 symbol.pointerExternal.symbol = symbol;
6401 DeclareType(symbol.type, true, true);
6403 ast->Insert(curExternal.prev, symbol.pointerExternal);
6405 symbol.id = curExternal.symbol.idCode;
6408 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6410 ast->Move(symbol.pointerExternal, curExternal.prev);
6411 symbol.id = curExternal.symbol.idCode;
6415 //findSymbolTotalTime += GetTime() - startTime;
6420 static void GetTypeSpecs(Type type, OldList * specs)
6422 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6427 if(type._class.registered)
6429 if(!type._class.registered.dataType)
6430 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6431 GetTypeSpecs(type._class.registered.dataType, specs);
6435 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6436 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6437 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6438 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6439 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6440 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6441 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6442 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6445 ListAdd(specs, MkSpecifier(INT)); break;
6449 static void PrintArraySize(Type arrayType, char * string)
6454 if(arrayType.enumClass)
6455 strcat(size, arrayType.enumClass.string);
6456 else if(arrayType.arraySizeExp)
6457 PrintExpression(arrayType.arraySizeExp, size);
6459 strcat(string, size);
6462 // WARNING : This function expects a null terminated string since it recursively concatenate...
6463 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6467 if(printConst && type.constant)
6468 strcat(string, "const ");
6473 Symbol c = type._class;
6474 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6475 // look into merging with thisclass ?
6476 if(type.classObjectType == typedObject)
6477 strcat(string, "typed_object");
6478 else if(type.classObjectType == anyObject)
6479 strcat(string, "any_object");
6483 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6485 if(type.byReference)
6486 strcat(string, " &");
6489 case voidType: strcat(string, "void"); break;
6490 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6491 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6492 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6493 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6494 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6495 case _BoolType: strcat(string, "_Bool"); break;
6496 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6497 case floatType: strcat(string, "float"); break;
6498 case doubleType: strcat(string, "double"); break;
6502 strcat(string, "struct ");
6503 strcat(string, type.enumName);
6505 else if(type.typeName)
6506 strcat(string, type.typeName);
6510 strcat(string, "struct { ");
6511 for(member = type.members.first; member; member = member.next)
6513 PrintType(member, string, true, fullName);
6514 strcat(string,"; ");
6522 strcat(string, "union ");
6523 strcat(string, type.enumName);
6525 else if(type.typeName)
6526 strcat(string, type.typeName);
6529 strcat(string, "union ");
6530 strcat(string,"(unnamed)");
6536 strcat(string, "enum ");
6537 strcat(string, type.enumName);
6539 else if(type.typeName)
6540 strcat(string, type.typeName);
6542 strcat(string, "int"); // "enum");
6545 strcat(string, "...");
6548 strcat(string, "subclass(");
6549 strcat(string, type._class ? type._class.string : "int");
6550 strcat(string, ")");
6553 strcat(string, type.templateParameter.identifier.string);
6556 strcat(string, "thisclass");
6559 strcat(string, "__builtin_va_list");
6565 static void PrintName(Type type, char * string, bool fullName)
6567 if(type.name && type.name[0])
6570 strcat(string, type.name);
6573 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6574 if(name) name += 2; else name = type.name;
6575 strcat(string, name);
6580 static void PrintAttribs(Type type, char * string)
6584 if(type.dllExport) strcat(string, "dllexport ");
6585 if(type.attrStdcall) strcat(string, "stdcall ");
6589 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
6591 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6593 Type attrType = null;
6594 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
6595 PrintAttribs(type, string);
6596 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
6597 strcat(string, " const");
6598 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
6599 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6600 strcat(string, " (");
6601 if(type.kind == pointerType)
6603 if(type.type.kind == functionType || type.type.kind == methodType)
6604 PrintAttribs(type.type, string);
6606 if(type.kind == pointerType)
6608 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
6609 strcat(string, "*");
6611 strcat(string, " *");
6613 if(printConst && type.constant && type.kind == pointerType)
6614 strcat(string, " const");
6617 PrintTypeSpecs(type, string, fullName, printConst);
6620 static void PostPrintType(Type type, char * string, bool fullName)
6622 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6623 strcat(string, ")");
6624 if(type.kind == arrayType)
6625 PrintArraySize(type, string);
6626 else if(type.kind == functionType)
6629 strcat(string, "(");
6630 for(param = type.params.first; param; param = param.next)
6632 PrintType(param, string, true, fullName);
6633 if(param.next) strcat(string, ", ");
6635 strcat(string, ")");
6637 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6638 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
6642 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6644 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
6646 PrePrintType(type, string, fullName, null, printConst);
6648 if(type.thisClass || (printName && type.name && type.name[0]))
6649 strcat(string, " ");
6650 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
6652 Symbol _class = type.thisClass;
6653 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
6655 if(type.classObjectType == classPointer)
6656 strcat(string, "class");
6658 strcat(string, type.byReference ? "typed_object&" : "typed_object");
6660 else if(_class && _class.string)
6662 String s = _class.string;
6667 char * name = RSearchString(s, "::", strlen(s), true, false);
6668 if(name) name += 2; else name = s;
6669 strcat(string, name);
6672 strcat(string, "::");
6675 if(printName && type.name)
6676 PrintName(type, string, fullName);
6677 PostPrintType(type, string, fullName);
6678 if(type.bitFieldCount)
6681 sprintf(count, ":%d", type.bitFieldCount);
6682 strcat(string, count);
6686 void PrintType(Type type, char * string, bool printName, bool fullName)
6688 _PrintType(type, string, printName, fullName, true);
6691 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
6693 _PrintType(type, string, printName, fullName, false);
6696 static Type FindMember(Type type, char * string)
6699 for(memberType = type.members.first; memberType; memberType = memberType.next)
6701 if(!memberType.name)
6703 Type subType = FindMember(memberType, string);
6707 else if(!strcmp(memberType.name, string))
6713 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6716 for(memberType = type.members.first; memberType; memberType = memberType.next)
6718 if(!memberType.name)
6720 Type subType = FindMember(memberType, string);
6723 *offset += memberType.offset;
6727 else if(!strcmp(memberType.name, string))
6729 *offset += memberType.offset;
6736 public bool GetParseError() { return parseError; }
6738 Expression ParseExpressionString(char * expression)
6742 fileInput = TempFile { };
6743 fileInput.Write(expression, 1, strlen(expression));
6744 fileInput.Seek(0, start);
6747 parsedExpression = null;
6749 expression_yyparse();
6752 return parsedExpression;
6755 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6757 Identifier id = exp.identifier;
6758 Method method = null;
6759 Property prop = null;
6760 DataMember member = null;
6761 ClassProperty classProp = null;
6763 if(_class && _class.type == enumClass)
6765 NamedLink value = null;
6766 Class enumClass = eSystem_FindClass(privateModule, "enum");
6770 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6772 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6773 for(value = e.values.first; value; value = value.next)
6775 if(!strcmp(value.name, id.string))
6782 FreeExpContents(exp);
6784 exp.type = constantExp;
6785 exp.isConstant = true;
6786 if(!strcmp(baseClass.dataTypeString, "int"))
6787 sprintf(constant, "%d",(int)value.data);
6789 sprintf(constant, "0x%X",(int)value.data);
6790 exp.constant = CopyString(constant);
6791 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6792 exp.expType = MkClassType(baseClass.fullName);
6800 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6802 ProcessMethodType(method);
6809 // TOCHECK: Put it back to what it was...
6810 // methodClass = _class;
6811 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6816 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
6819 ProcessPropertyType(prop);
6820 exp.expType = prop.dataType;
6821 if(prop.dataType) prop.dataType.refCount++;
6824 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
6826 if(!member.dataType)
6827 member.dataType = ProcessTypeString(member.dataTypeString, false);
6828 exp.expType = member.dataType;
6829 if(member.dataType) member.dataType.refCount++;
6832 else if((classProp = eClass_FindClassProperty(_class, id.string)))
6834 if(!classProp.dataType)
6835 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
6837 if(classProp.constant)
6839 FreeExpContents(exp);
6841 exp.isConstant = true;
6842 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
6844 //char constant[256];
6845 exp.type = stringExp;
6846 exp.constant = QMkString((char *)classProp.Get(_class));
6851 exp.type = constantExp;
6852 sprintf(constant, "%d", (int)classProp.Get(_class));
6853 exp.constant = CopyString(constant);
6861 exp.expType = classProp.dataType;
6862 if(classProp.dataType) classProp.dataType.refCount++;
6868 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
6870 BinaryTree * tree = &nameSpace.functions;
6871 GlobalData data = (GlobalData)tree->FindString(name);
6875 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
6877 data = ScanGlobalData(child, name);
6885 static GlobalData FindGlobalData(char * name)
6888 NameSpace * nameSpace;
6889 nameSpace = globalData;
6890 for(c = 0; name[c]; c++)
6892 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
6894 NameSpace * newSpace;
6895 char * spaceName = new char[c - start + 1];
6896 strncpy(spaceName, name + start, c - start);
6897 spaceName[c-start] = '\0';
6898 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
6902 nameSpace = newSpace;
6903 if(name[c] == ':') c++;
6909 return ScanGlobalData(nameSpace, name + start);
6914 static int definedExpStackPos;
6915 static void * definedExpStack[512];
6917 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
6918 void ReplaceExpContents(Expression checkedExp, Expression newExp)
6920 Expression prev = checkedExp.prev, next = checkedExp.next;
6922 FreeExpContents(checkedExp);
6923 FreeType(checkedExp.expType);
6924 FreeType(checkedExp.destType);
6926 *checkedExp = *newExp;
6930 checkedExp.prev = prev;
6931 checkedExp.next = next;
6934 void ApplyAnyObjectLogic(Expression e)
6936 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
6938 char debugExpString[4096];
6939 debugExpString[0] = '\0';
6940 PrintExpression(e, debugExpString);
6943 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
6945 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
6946 //ellipsisDestType = destType;
6949 Type type = e.expType;
6950 Class _class = null;
6951 //Type destType = e.destType;
6953 if(type.kind == classType && type._class && type._class.registered)
6955 _class = type._class.registered;
6957 else if(type.kind == subClassType)
6959 _class = FindClass("ecere::com::Class").registered;
6963 char string[1024] = "";
6966 PrintTypeNoConst(type, string, false, true);
6967 classSym = FindClass(string);
6968 if(classSym) _class = classSym.registered;
6971 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...
6972 (!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))) ||
6973 destType.byReference)))
6975 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
6977 Expression checkedExp = e, newExp;
6979 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6981 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6983 if(checkedExp.type == extensionCompoundExp)
6985 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6988 checkedExp = checkedExp.list->last;
6990 else if(checkedExp.type == castExp)
6991 checkedExp = checkedExp.cast.exp;
6994 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
6996 newExp = checkedExp.op.exp2;
6997 checkedExp.op.exp2 = null;
6998 FreeExpContents(checkedExp);
7000 if(e.expType && e.expType.passAsTemplate)
7003 ComputeTypeSize(e.expType);
7004 sprintf(size, "%d", e.expType.size);
7005 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7006 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7007 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7010 ReplaceExpContents(checkedExp, newExp);
7011 e.byReference = true;
7013 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7015 Expression checkedExp, newExp;
7018 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7020 e.type == identifierExp ||
7021 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7022 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7023 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7026 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7028 Context context = PushContext();
7030 OldList * specs = MkList();
7031 char typeString[1024];
7032 Expression newExp { };
7034 typeString[0] = '\0';
7037 //if(e.destType) e.destType.refCount++;
7038 // if(exp.expType) exp.expType.refCount++;
7041 newExp.expType = null;
7043 PrintTypeNoConst(e.expType, typeString, false, true);
7044 decl = SpecDeclFromString(typeString, specs, null);
7045 newExp.destType = ProcessType(specs, decl);
7047 curContext = context;
7049 // We need a current compound for this
7053 OldList * stmts = MkList();
7054 e.type = extensionCompoundExp;
7055 sprintf(name, "__internalValue%03X", internalValueCounter++);
7056 if(!curCompound.compound.declarations)
7057 curCompound.compound.declarations = MkList();
7058 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7059 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7060 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7061 e.compound = MkCompoundStmt(null, stmts);
7064 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7067 e.compound = MkCompoundStmt(
7068 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7069 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7071 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7075 Type type = e.destType;
7077 CopyTypeInto(e.destType, type);
7078 e.destType.refCount = 1;
7079 e.destType.classObjectType = none;
7083 e.compound.compound.context = context;
7084 PopContext(context);
7085 curContext = context.parent;
7089 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7091 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7093 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7095 if(checkedExp.type == extensionCompoundExp)
7097 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7100 checkedExp = checkedExp.list->last;
7102 else if(checkedExp.type == castExp)
7103 checkedExp = checkedExp.cast.exp;
7106 Expression operand { };
7107 operand = *checkedExp;
7108 checkedExp.destType = null;
7109 checkedExp.expType = null;
7111 checkedExp.type = opExp;
7112 checkedExp.op.op = '&';
7113 checkedExp.op.exp1 = null;
7114 checkedExp.op.exp2 = operand;
7116 //newExp = MkExpOp(null, '&', checkedExp);
7118 //ReplaceExpContents(checkedExp, newExp);
7125 // If expression type is a simple class, make it an address
7126 // FixReference(e, true);
7129 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7130 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7131 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7133 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"))
7135 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7139 Expression thisExp { };
7142 thisExp.prev = null;
7143 thisExp.next = null;
7146 e.type = bracketsExp;
7147 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7148 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7149 ((Expression)e.list->first).byReference = true;
7151 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7153 e.expType = thisExp.expType;
7154 e.expType.refCount++;
7159 CopyTypeInto(e.expType, thisExp.expType);
7160 e.expType.byReference = false;
7161 e.expType.refCount = 1;
7163 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7164 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7166 e.expType.classObjectType = none;
7171 // TOFIX: Try this for a nice IDE crash!
7173 // The other way around
7176 if(destType && e.expType &&
7177 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7178 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7179 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7181 if(destType.kind == ellipsisType)
7183 Compiler_Error($"Unspecified type\n");
7185 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7187 bool byReference = e.expType.byReference;
7188 Expression thisExp { };
7190 OldList * specs = MkList();
7191 char typeString[1024]; // Watch buffer overruns
7193 ClassObjectType backupClassObjectType;
7194 bool backupByReference;
7196 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7201 backupClassObjectType = type.classObjectType;
7202 backupByReference = type.byReference;
7204 type.classObjectType = none;
7205 type.byReference = false;
7207 typeString[0] = '\0';
7208 PrintType(type, typeString, false, true);
7209 decl = SpecDeclFromString(typeString, specs, null);
7211 type.classObjectType = backupClassObjectType;
7212 type.byReference = backupByReference;
7215 thisExp.prev = null;
7216 thisExp.next = null;
7219 if( ( type.kind == classType && type._class && type._class.registered &&
7220 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7221 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7222 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7223 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7228 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7231 CopyTypeInto(e.expType, type);
7232 e.expType.byReference = false;
7233 e.expType.refCount = 1;
7238 e.cast.typeName = MkTypeName(specs, decl);
7239 e.cast.exp = thisExp;
7240 e.byReference = true;
7244 e.destType = destType;
7245 destType.refCount++;
7250 void ProcessExpressionType(Expression exp)
7252 bool unresolved = false;
7253 Location oldyylloc = yylloc;
7254 bool notByReference = false;
7256 char debugExpString[4096];
7257 debugExpString[0] = '\0';
7258 PrintExpression(exp, debugExpString);
7260 if(!exp || exp.expType)
7263 //eSystem_Logf("%s\n", expString);
7265 // Testing this here
7271 Identifier id = exp.identifier;
7272 if(!id || !topContext) return;
7274 // DOING THIS LATER NOW...
7275 if(id._class && id._class.name)
7277 id.classSym = id._class.symbol; // FindClass(id._class.name);
7278 /* TODO: Name Space Fix ups
7280 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7284 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7286 exp.expType = ProcessTypeString("Module", true);
7289 else */if(strstr(id.string, "__ecereClass") == id.string)
7291 exp.expType = ProcessTypeString("ecere::com::Class", true);
7294 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7296 // Added this here as well
7297 ReplaceClassMembers(exp, thisClass);
7298 if(exp.type != identifierExp)
7300 ProcessExpressionType(exp);
7304 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7309 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7310 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7311 if(!symbol/* && exp.destType*/)
7313 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7319 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7320 if(exp.type != identifierExp)
7322 ProcessExpressionType(exp);
7326 // Static methods called from inside the _class
7327 else if(currentClass && !id._class)
7329 if(ResolveIdWithClass(exp, currentClass, true))
7332 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7336 // If we manage to resolve this symbol
7339 Type type = symbol.type;
7340 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7342 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7344 Context context = SetupTemplatesContext(_class);
7345 type = ReplaceThisClassType(_class);
7346 FinishTemplatesContext(context);
7347 if(type) type.refCount = 0; // We'll be incrementing it right below...
7350 FreeSpecifier(id._class);
7353 id.string = CopyString(symbol.string);
7359 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7360 // Add missing cases here... enum Classes...
7361 exp.isConstant = true;
7363 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7364 if(symbol.isParam || !strcmp(id.string, "this"))
7366 if(_class && _class.type == structClass && !type.declaredWithStruct)
7367 exp.byReference = true;
7369 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7370 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7371 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7372 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7374 Identifier id = exp.identifier;
7375 exp.type = bracketsExp;
7376 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7380 if(symbol.isIterator)
7382 if(symbol.isIterator == 3)
7384 exp.type = bracketsExp;
7385 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7386 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7388 ProcessExpressionType(exp);
7390 else if(symbol.isIterator != 4)
7392 exp.type = memberExp;
7393 exp.member.exp = MkExpIdentifier(exp.identifier);
7394 exp.member.exp.expType = exp.expType;
7395 /*if(symbol.isIterator == 6)
7396 exp.member.member = MkIdentifier("key");
7398 exp.member.member = MkIdentifier("data");
7400 ProcessExpressionType(exp);
7407 DefinedExpression definedExp = null;
7408 if(thisNameSpace && !(id._class && !id._class.name))
7411 strcpy(name, thisNameSpace);
7413 strcat(name, id.string);
7414 definedExp = eSystem_FindDefine(privateModule, name);
7417 definedExp = eSystem_FindDefine(privateModule, id.string);
7421 for(c = 0; c<definedExpStackPos; c++)
7422 if(definedExpStack[c] == definedExp)
7424 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7426 Location backupYylloc = yylloc;
7427 File backInput = fileInput;
7428 definedExpStack[definedExpStackPos++] = definedExp;
7430 fileInput = TempFile { };
7431 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7432 fileInput.Seek(0, start);
7435 parsedExpression = null;
7437 expression_yyparse();
7440 fileInput = backInput;
7442 yylloc = backupYylloc;
7444 if(parsedExpression)
7447 exp.type = bracketsExp;
7448 exp.list = MkListOne(parsedExpression);
7449 parsedExpression.loc = yylloc;
7450 ProcessExpressionType(exp);
7451 definedExpStackPos--;
7454 definedExpStackPos--;
7460 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7466 GlobalData data = null;
7467 if(thisNameSpace && !(id._class && !id._class.name))
7470 strcpy(name, thisNameSpace);
7472 strcat(name, id.string);
7473 data = FindGlobalData(name);
7476 data = FindGlobalData(id.string);
7479 DeclareGlobalData(data);
7480 exp.expType = data.dataType;
7481 if(data.dataType) data.dataType.refCount++;
7484 id.string = CopyString(data.fullName);
7485 FreeSpecifier(id._class);
7492 GlobalFunction function = null;
7493 if(thisNameSpace && !(id._class && !id._class.name))
7496 strcpy(name, thisNameSpace);
7498 strcat(name, id.string);
7499 function = eSystem_FindFunction(privateModule, name);
7502 function = eSystem_FindFunction(privateModule, id.string);
7507 id.string = CopyString(function.name);
7510 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7511 strcpy(name, "__ecereFunction_");
7512 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7513 if(DeclareFunction(function, name))
7516 id.string = CopyString(name);
7518 exp.expType = function.dataType;
7519 if(function.dataType) function.dataType.refCount++;
7521 FreeSpecifier(id._class);
7538 if(!exp.instance._class)
7540 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7542 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7546 //classSym = FindClass(exp.instance._class.fullName);
7547 //_class = classSym ? classSym.registered : null;
7549 ProcessInstantiationType(exp.instance);
7550 exp.isConstant = exp.instance.isConstant;
7553 if(_class.type == unitClass && _class.base.type != systemClass)
7556 Type destType = exp.destType;
7558 exp.destType = MkClassType(_class.base.fullName);
7559 exp.expType = MkClassType(_class.fullName);
7560 CheckExpressionType(exp, exp.destType, true);
7562 exp.destType = destType;
7564 exp.expType = MkClassType(_class.fullName);
7567 if(exp.instance._class)
7569 exp.expType = MkClassType(exp.instance._class.name);
7570 /*if(exp.expType._class && exp.expType._class.registered &&
7571 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7572 exp.expType.byReference = true;*/
7580 char * constant = exp.constant;
7588 if(constant[0] == '\'')
7590 if((int)((byte *)constant)[1] > 127)
7593 unichar ch = UTF8GetChar(constant + 1, &nb);
7594 if(nb < 2) ch = constant[1];
7596 exp.constant = PrintUInt(ch);
7597 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7598 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7599 type._class = FindClass("unichar");
7601 type.isSigned = false;
7605 type.kind = charType;
7606 type.isSigned = true;
7611 char * dot = strchr(constant, '.');
7612 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
7616 exponent = strchr(constant, 'p');
7617 if(!exponent) exponent = strchr(constant, 'P');
7621 exponent = strchr(constant, 'e');
7622 if(!exponent) exponent = strchr(constant, 'E');
7627 if(strchr(constant, 'f') || strchr(constant, 'F'))
7628 type.kind = floatType;
7630 type.kind = doubleType;
7631 type.isSigned = true;
7635 bool isSigned = constant[0] == '-';
7636 int64 i64 = strtoll(constant, null, 0);
7637 uint64 ui64 = strtoull(constant, null, 0);
7638 bool is64Bit = false;
7651 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
7655 else if(constant[0] != '0' || !constant[1])
7658 type.kind = is64Bit ? int64Type : intType;
7659 type.isSigned = isSigned;
7662 exp.isConstant = true;
7663 if(exp.destType && exp.destType.kind == doubleType)
7664 type.kind = doubleType;
7665 else if(exp.destType && exp.destType.kind == floatType)
7666 type.kind = floatType;
7667 else if(exp.destType && exp.destType.kind == int64Type)
7668 type.kind = int64Type;
7674 exp.isConstant = true; // Why wasn't this constant?
7691 ProcessExpressionType(exp._new.size);
7696 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7698 DeclareType(exp.expType.type, false, false);
7702 ProcessExpressionType(exp._renew.size);
7703 ProcessExpressionType(exp._renew.exp);
7708 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7710 DeclareType(exp.expType.type, false, false);
7714 bool assign = false, boolResult = false, boolOps = false;
7715 Type type1 = null, type2 = null;
7716 bool useDestType = false, useSideType = false;
7717 Location oldyylloc = yylloc;
7718 bool useSideUnit = false;
7720 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7729 // Assignment Operators
7743 // boolean Operators
7745 // Expect boolean operators
7747 //boolResult = true;
7751 // Expect boolean operands
7762 // Gives boolean result
7770 // Just added these... testing
7775 // DANGER: Verify units
7780 if(exp.op.op != '*' || exp.op.exp1)
7787 /*// Implement speed etc.
7793 if(exp.op.op == '&')
7795 // Added this here earlier for Iterator address as key
7796 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7798 Identifier id = exp.op.exp2.identifier;
7799 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7800 if(symbol && symbol.isIterator == 2)
7802 exp.type = memberExp;
7803 exp.member.exp = exp.op.exp2;
7804 exp.member.member = MkIdentifier("key");
7806 exp.op.exp2.expType = symbol.type;
7807 symbol.type.refCount++;
7808 ProcessExpressionType(exp);
7812 // exp.op.exp2.usage.usageRef = true;
7816 //dummy.kind = TypeDummy;
7820 if(exp.destType && exp.destType.kind == classType &&
7821 exp.destType._class && exp.destType._class.registered && useDestType &&
7823 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
7824 exp.destType._class.registered.type == enumClass ||
7825 exp.destType._class.registered.type == bitClass
7828 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
7830 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7831 exp.op.exp1.destType = exp.destType;
7833 exp.destType.refCount++;
7837 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7838 exp.op.exp1.destType = dummy;
7842 // TESTING THIS HERE...
7843 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
7844 ProcessExpressionType(exp.op.exp1);
7845 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
7847 if(exp.op.exp1.destType == dummy)
7850 exp.op.exp1.destType = null;
7852 type1 = exp.op.exp1.expType;
7857 char expString[10240];
7858 expString[0] = '\0';
7859 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
7863 exp.op.exp2.destType = exp.op.exp1.expType;
7864 if(exp.op.exp1.expType)
7865 exp.op.exp1.expType.refCount++;
7869 exp.op.exp2.destType = exp.destType;
7871 exp.destType.refCount++;
7874 if(type1) type1.refCount++;
7875 exp.expType = type1;
7880 PrintExpression(exp.op.exp2, expString);
7882 if(type1 && type1.kind == pointerType)
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)
7886 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
7887 else if(exp.op.op == '=')
7889 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7890 exp.op.exp2.destType = type1;
7897 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
7898 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/* ||
7899 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
7902 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7903 exp.op.exp2.destType = type1;
7908 if(type1) type1.refCount++;
7909 exp.expType = type1;
7911 else if(exp.destType && exp.destType.kind == classType &&
7912 exp.destType._class && exp.destType._class.registered &&
7914 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
7915 (exp.destType._class.registered.type == enumClass && useDestType))
7918 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7919 exp.op.exp2.destType = exp.destType;
7921 exp.destType.refCount++;
7925 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7926 exp.op.exp2.destType = dummy;
7930 // TESTING THIS HERE... (DANGEROUS)
7931 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
7932 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
7934 FreeType(exp.op.exp2.destType);
7935 exp.op.exp2.destType = type1;
7938 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
7939 ProcessExpressionType(exp.op.exp2);
7940 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
7942 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
7944 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)
7946 if(exp.op.op != '=' && type1.type.kind == voidType)
7947 Compiler_Error($"void *: unknown size\n");
7949 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||
7950 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
7951 (exp.op.exp2.expType._class.registered.type == normalClass ||
7952 exp.op.exp2.expType._class.registered.type == structClass ||
7953 exp.op.exp2.expType._class.registered.type == noHeadClass)))
7955 if(exp.op.op == ADD_ASSIGN)
7956 Compiler_Error($"cannot add two pointers\n");
7958 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
7959 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
7961 if(exp.op.op == ADD_ASSIGN)
7962 Compiler_Error($"cannot add two pointers\n");
7966 char type1String[1024];
7967 char type2String[1024];
7968 type1String[0] = '\0';
7969 type2String[0] = '\0';
7971 PrintType(exp.op.exp2.expType, type1String, false, true);
7972 PrintType(type1, type2String, false, true);
7973 ChangeCh(expString, '\n', ' ');
7974 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
7978 if(exp.op.exp2.destType == dummy)
7981 exp.op.exp2.destType = null;
7984 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
7988 CopyTypeInto(type2, exp.op.exp2.expType);
7989 type2.isSigned = true;
7991 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
7993 type2 = { kind = intType };
7995 type2.isSigned = true;
7999 type2 = exp.op.exp2.expType;
8000 if(type2) type2.refCount++;
8004 dummy.kind = voidType;
8006 if(exp.op.op == SIZEOF)
8013 exp.isConstant = true;
8015 // Get type of dereferenced pointer
8016 else if(exp.op.op == '*' && !exp.op.exp1)
8018 exp.expType = Dereference(type2);
8019 if(type2 && type2.kind == classType)
8020 notByReference = true;
8022 else if(exp.op.op == '&' && !exp.op.exp1)
8023 exp.expType = Reference(type2);
8030 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8031 exp.op.exp1.destType = MkClassType("bool");
8032 exp.op.exp1.destType.truth = true;
8033 if(!exp.op.exp1.expType)
8034 ProcessExpressionType(exp.op.exp1);
8036 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8037 FreeType(exp.op.exp1.expType);
8038 exp.op.exp1.expType = MkClassType("bool");
8039 exp.op.exp1.expType.truth = true;
8043 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8044 exp.op.exp2.destType = MkClassType("bool");
8045 exp.op.exp2.destType.truth = true;
8046 if(!exp.op.exp2.expType)
8047 ProcessExpressionType(exp.op.exp2);
8049 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8050 FreeType(exp.op.exp2.expType);
8051 exp.op.exp2.expType = MkClassType("bool");
8052 exp.op.exp2.expType.truth = true;
8055 else if(exp.op.exp1 && exp.op.exp2 &&
8058 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8059 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8060 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8061 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8063 if(type1 && type2 &&
8064 // If either both are class or both are not class
8065 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8067 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8068 exp.op.exp2.destType = type1;
8070 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8071 exp.op.exp1.destType = type2;
8073 // Warning here for adding Radians + Degrees with no destination type
8074 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8075 type1._class.registered && type1._class.registered.type == unitClass &&
8076 type2._class.registered && type2._class.registered.type == unitClass &&
8077 type1._class.registered != type2._class.registered)
8078 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8079 type1._class.string, type2._class.string, type1._class.string);
8081 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8083 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8086 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8088 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8089 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8092 ProcessExpressionType(exp.op.exp1);
8094 if(type2.kind != pointerType)
8096 ProcessExpressionType(classExp);
8098 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8099 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8100 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8102 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8105 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8106 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8107 MkPointer(null, null), null)))),
8108 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8110 if(!exp.op.exp2.expType)
8114 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8118 ProcessExpressionType(exp.op.exp2);
8123 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)))
8125 if(type1.kind != classType && type1.type.kind == voidType)
8126 Compiler_Error($"void *: unknown size\n");
8127 exp.expType = type1;
8128 if(type1) type1.refCount++;
8130 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)))
8132 if(type2.kind != classType && type2.type.kind == voidType)
8133 Compiler_Error($"void *: unknown size\n");
8134 exp.expType = type2;
8135 if(type2) type2.refCount++;
8137 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8138 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8140 Compiler_Warning($"different levels of indirection\n");
8144 bool success = false;
8145 if(type1.kind == pointerType && type2.kind == pointerType)
8147 if(exp.op.op == '+')
8148 Compiler_Error($"cannot add two pointers\n");
8149 else if(exp.op.op == '-')
8151 // Pointer Subtraction gives integer
8152 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8161 if(type1.type.kind == templateType)
8163 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8166 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8168 ProcessExpressionType(classExp);
8170 exp.type = bracketsExp;
8171 exp.list = MkListOne(MkExpOp(
8172 MkExpBrackets(MkListOne(MkExpOp(
8173 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8175 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8177 //MkExpMember(classExp, MkIdentifier("typeSize"))
8179 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8180 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8182 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8185 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8186 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8187 MkPointer(null, null), null)))),
8188 MkExpMember(classExp, MkIdentifier("typeSize")))))
8193 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8202 if(!success && exp.op.exp1.type == constantExp)
8204 // If first expression is constant, try to match that first
8205 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8207 if(exp.expType) FreeType(exp.expType);
8208 exp.expType = exp.op.exp1.destType;
8209 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8212 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8214 if(exp.expType) FreeType(exp.expType);
8215 exp.expType = exp.op.exp2.destType;
8216 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8222 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8224 if(exp.expType) FreeType(exp.expType);
8225 exp.expType = exp.op.exp2.destType;
8226 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8229 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8231 if(exp.expType) FreeType(exp.expType);
8232 exp.expType = exp.op.exp1.destType;
8233 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8239 char expString1[10240];
8240 char expString2[10240];
8243 expString1[0] = '\0';
8244 expString2[0] = '\0';
8249 PrintExpression(exp.op.exp1, expString1);
8250 ChangeCh(expString1, '\n', ' ');
8251 PrintExpression(exp.op.exp2, expString2);
8252 ChangeCh(expString2, '\n', ' ');
8253 PrintType(exp.op.exp1.expType, type1, false, true);
8254 PrintType(exp.op.exp2.expType, type2, false, true);
8257 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8261 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8262 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8264 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8265 // Convert e.g. / 4 into / 4.0
8266 exp.op.exp1.destType = type2._class.registered.dataType;
8267 if(type2._class.registered.dataType)
8268 type2._class.registered.dataType.refCount++;
8269 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8270 exp.expType = type2;
8271 if(type2) type2.refCount++;
8273 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8275 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8276 // Convert e.g. / 4 into / 4.0
8277 exp.op.exp2.destType = type1._class.registered.dataType;
8278 if(type1._class.registered.dataType)
8279 type1._class.registered.dataType.refCount++;
8280 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8281 exp.expType = type1;
8282 if(type1) type1.refCount++;
8288 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8290 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8292 if(!type1._class.registered.dataType)
8293 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8294 exp.op.exp2.destType = type1._class.registered.dataType;
8295 exp.op.exp2.destType.refCount++;
8297 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8300 type2 = exp.op.exp2.destType;
8301 if(type2) type2.refCount++;
8303 exp.expType = type2;
8307 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8309 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8311 if(!type2._class.registered.dataType)
8312 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8313 exp.op.exp1.destType = type2._class.registered.dataType;
8314 exp.op.exp1.destType.refCount++;
8316 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8317 type1 = exp.op.exp1.destType;
8318 exp.expType = type1;
8322 // TESTING THIS NEW CODE
8323 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8325 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8327 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8329 if(exp.expType) FreeType(exp.expType);
8330 exp.expType = exp.op.exp1.expType;
8331 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8336 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8338 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8340 if(exp.expType) FreeType(exp.expType);
8341 exp.expType = exp.op.exp2.expType;
8342 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8350 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8351 exp.op.exp2.destType = type1;
8355 // Maybe this was meant to be an enum...
8356 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8358 Type oldType = exp.op.exp2.expType;
8359 exp.op.exp2.expType = null;
8360 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8363 exp.op.exp2.expType = oldType;
8368 // TESTING THIS HERE... LATEST ADDITION
8369 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8371 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8372 exp.op.exp2.destType = type2._class.registered.dataType;
8373 if(type2._class.registered.dataType)
8374 type2._class.registered.dataType.refCount++;
8375 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8377 //exp.expType = type2._class.registered.dataType; //type2;
8378 //if(type2) type2.refCount++;
8381 // TESTING THIS HERE... LATEST ADDITION
8382 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8384 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8385 exp.op.exp1.destType = type1._class.registered.dataType;
8386 if(type1._class.registered.dataType)
8387 type1._class.registered.dataType.refCount++;
8388 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8389 exp.expType = type1._class.registered.dataType; //type1;
8390 if(type1) type1.refCount++;
8394 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8396 if(exp.expType) FreeType(exp.expType);
8397 exp.expType = exp.op.exp2.destType;
8398 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8400 else if(type1 && type2)
8402 char expString1[10240];
8403 char expString2[10240];
8404 char type1String[1024];
8405 char type2String[1024];
8406 expString1[0] = '\0';
8407 expString2[0] = '\0';
8408 type1String[0] = '\0';
8409 type2String[0] = '\0';
8412 PrintExpression(exp.op.exp1, expString1);
8413 ChangeCh(expString1, '\n', ' ');
8414 PrintExpression(exp.op.exp2, expString2);
8415 ChangeCh(expString2, '\n', ' ');
8416 PrintType(exp.op.exp1.expType, type1String, false, true);
8417 PrintType(exp.op.exp2.expType, type2String, false, true);
8420 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8422 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8424 exp.expType = exp.op.exp1.expType;
8425 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8427 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8429 exp.expType = exp.op.exp2.expType;
8430 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8437 // Maybe this was meant to be an enum...
8438 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8440 Type oldType = exp.op.exp1.expType;
8441 exp.op.exp1.expType = null;
8442 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8445 exp.op.exp1.expType = oldType;
8448 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8449 exp.op.exp1.destType = type2;
8452 // TESTING THIS HERE... LATEST ADDITION
8453 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8455 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8456 exp.op.exp1.destType = type1._class.registered.dataType;
8457 if(type1._class.registered.dataType)
8458 type1._class.registered.dataType.refCount++;
8461 // TESTING THIS HERE... LATEST ADDITION
8462 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8464 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8465 exp.op.exp2.destType = type2._class.registered.dataType;
8466 if(type2._class.registered.dataType)
8467 type2._class.registered.dataType.refCount++;
8471 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8473 if(exp.expType) FreeType(exp.expType);
8474 exp.expType = exp.op.exp1.destType;
8475 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8479 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8481 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8483 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8484 // Convert e.g. / 4 into / 4.0
8485 exp.op.exp1.destType = type2._class.registered.dataType;
8486 if(type2._class.registered.dataType)
8487 type2._class.registered.dataType.refCount++;
8488 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8490 if(exp.op.op == '!')
8492 exp.expType = MkClassType("bool");
8493 exp.expType.truth = true;
8497 exp.expType = type2;
8498 if(type2) type2.refCount++;
8501 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8503 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8505 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8506 // Convert e.g. / 4 into / 4.0
8507 exp.op.exp2.destType = type1._class.registered.dataType;
8508 if(type1._class.registered.dataType)
8509 type1._class.registered.dataType.refCount++;
8510 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8512 exp.expType = type1;
8513 if(type1) type1.refCount++;
8518 if(exp.op.exp1 && !exp.op.exp1.expType)
8520 char expString[10000];
8521 expString[0] = '\0';
8524 PrintExpression(exp.op.exp1, expString);
8525 ChangeCh(expString, '\n', ' ');
8528 Compiler_Error($"couldn't determine type of %s\n", expString);
8530 if(exp.op.exp2 && !exp.op.exp2.expType)
8532 char expString[10240];
8533 expString[0] = '\0';
8536 PrintExpression(exp.op.exp2, expString);
8537 ChangeCh(expString, '\n', ' ');
8540 Compiler_Error($"couldn't determine type of %s\n", expString);
8545 FreeType(exp.expType);
8546 exp.expType = MkClassType("bool");
8547 exp.expType.truth = true;
8550 if(exp.op.op != SIZEOF)
8551 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8552 (!exp.op.exp2 || exp.op.exp2.isConstant);
8554 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8556 DeclareType(exp.op.exp2.expType, false, false);
8567 case extensionExpressionExp:
8570 exp.isConstant = true;
8571 for(e = exp.list->first; e; e = e.next)
8576 FreeType(e.destType);
8577 e.destType = exp.destType;
8578 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8580 ProcessExpressionType(e);
8582 exp.destType.count--;
8583 if(!exp.expType && !e.next)
8585 exp.expType = e.expType;
8586 if(e.expType) e.expType.refCount++;
8589 exp.isConstant = false;
8592 // In case a cast became a member...
8593 e = exp.list->first;
8594 if(!e.next && e.type == memberExp)
8596 // Preserve prev, next
8597 Expression next = exp.next, prev = exp.prev;
8600 FreeType(exp.expType);
8601 FreeType(exp.destType);
8611 ProcessExpressionType(exp);
8618 exp.isConstant = true;
8620 ProcessExpressionType(exp.index.exp);
8621 if(!exp.index.exp.isConstant)
8622 exp.isConstant = false;
8624 if(exp.index.exp.expType)
8626 Type source = exp.index.exp.expType;
8627 if(source.kind == classType && source._class && source._class.registered)
8629 Class _class = source._class.registered;
8630 Class c = _class.templateClass ? _class.templateClass : _class;
8631 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
8633 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8635 if(exp.index.index && exp.index.index->last)
8637 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8643 for(e = exp.index.index->first; e; e = e.next)
8645 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8647 if(e.destType) FreeType(e.destType);
8648 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8650 ProcessExpressionType(e);
8653 // Check if this type is int
8656 exp.isConstant = false;
8660 exp.expType = Dereference(exp.index.exp.expType);
8662 DeclareType(exp.expType, false, false);
8669 Type methodType = null;
8675 PrintExpression(exp.call.exp, name);
8676 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8678 //exp.call.exp.expType = null;
8679 PrintExpression(exp.call.exp, name);
8682 if(exp.call.exp.type == identifierExp)
8684 Expression idExp = exp.call.exp;
8685 Identifier id = idExp.identifier;
8686 if(!strcmp(id.string, "__builtin_frame_address"))
8688 exp.expType = ProcessTypeString("void *", true);
8689 if(exp.call.arguments && exp.call.arguments->first)
8690 ProcessExpressionType(exp.call.arguments->first);
8693 else if(!strcmp(id.string, "__ENDIAN_PAD"))
8695 exp.expType = ProcessTypeString("int", true);
8696 if(exp.call.arguments && exp.call.arguments->first)
8697 ProcessExpressionType(exp.call.arguments->first);
8700 else if(!strcmp(id.string, "Max") ||
8701 !strcmp(id.string, "Min") ||
8702 !strcmp(id.string, "Sgn") ||
8703 !strcmp(id.string, "Abs"))
8705 Expression a = null;
8706 Expression b = null;
8707 Expression tempExp1 = null, tempExp2 = null;
8708 if((!strcmp(id.string, "Max") ||
8709 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8711 a = exp.call.arguments->first;
8712 b = exp.call.arguments->last;
8716 else if(exp.call.arguments->count == 1)
8718 a = exp.call.arguments->first;
8724 exp.call.arguments->Clear();
8725 idExp.identifier = null;
8727 FreeExpContents(exp);
8729 ProcessExpressionType(a);
8731 ProcessExpressionType(b);
8733 exp.type = bracketsExp;
8734 exp.list = MkList();
8736 if(a.expType && (!b || b.expType))
8738 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8740 // Use the simpleStruct name/ids for now...
8743 OldList * specs = MkList();
8744 OldList * decls = MkList();
8746 char temp1[1024], temp2[1024];
8748 GetTypeSpecs(a.expType, specs);
8750 if(a && !a.isConstant && a.type != identifierExp)
8752 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8753 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8754 tempExp1 = QMkExpId(temp1);
8755 tempExp1.expType = a.expType;
8757 a.expType.refCount++;
8758 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8760 if(b && !b.isConstant && b.type != identifierExp)
8762 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8763 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8764 tempExp2 = QMkExpId(temp2);
8765 tempExp2.expType = b.expType;
8767 b.expType.refCount++;
8768 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8771 decl = MkDeclaration(specs, decls);
8772 if(!curCompound.compound.declarations)
8773 curCompound.compound.declarations = MkList();
8774 curCompound.compound.declarations->Insert(null, decl);
8779 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8781 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8783 MkExpCondition(MkExpBrackets(MkListOne(
8784 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8785 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8786 exp.expType = a.expType;
8788 a.expType.refCount++;
8790 else if(!strcmp(id.string, "Abs"))
8793 MkExpCondition(MkExpBrackets(MkListOne(
8794 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8795 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8796 exp.expType = a.expType;
8798 a.expType.refCount++;
8800 else if(!strcmp(id.string, "Sgn"))
8802 // ((!(a))?(0):(((a)<0)?(-1):(1)))
8804 MkExpCondition(MkExpBrackets(MkListOne(
8805 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
8806 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
8807 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8808 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
8809 exp.expType = ProcessTypeString("int", false);
8812 FreeExpression(tempExp1);
8813 if(tempExp2) FreeExpression(tempExp2);
8827 if(!exp.call.exp.destType)
8829 exp.call.exp.destType = dummy;
8832 ProcessExpressionType(exp.call.exp);
8833 if(exp.call.exp.destType == dummy)
8836 exp.call.exp.destType = null;
8841 // Check argument types against parameter types
8842 functionType = exp.call.exp.expType;
8844 if(functionType && functionType.kind == TypeKind::methodType)
8846 methodType = functionType;
8847 functionType = methodType.method.dataType;
8849 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
8850 // TOCHECK: Instead of doing this here could this be done per param?
8851 if(exp.call.exp.expType.usedClass)
8853 char typeString[1024];
8854 typeString[0] = '\0';
8856 Symbol back = functionType.thisClass;
8857 // Do not output class specifier here (thisclass was added to this)
8858 functionType.thisClass = null;
8859 PrintType(functionType, typeString, true, true);
8860 functionType.thisClass = back;
8862 if(strstr(typeString, "thisclass"))
8864 OldList * specs = MkList();
8867 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
8869 decl = SpecDeclFromString(typeString, specs, null);
8871 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
8872 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
8873 exp.call.exp.expType.usedClass))
8874 thisClassParams = false;
8876 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
8878 Class backupThisClass = thisClass;
8879 thisClass = exp.call.exp.expType.usedClass;
8880 ProcessDeclarator(decl);
8881 thisClass = backupThisClass;
8884 thisClassParams = true;
8886 functionType = ProcessType(specs, decl);
8887 functionType.refCount = 0;
8888 FinishTemplatesContext(context);
8891 FreeList(specs, FreeSpecifier);
8892 FreeDeclarator(decl);
8896 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
8898 Type type = functionType.type;
8899 if(!functionType.refCount)
8901 functionType.type = null;
8902 FreeType(functionType);
8904 //methodType = functionType;
8905 functionType = type;
8907 if(functionType && functionType.kind != TypeKind::functionType)
8909 Compiler_Error($"called object %s is not a function\n", name);
8911 else if(functionType)
8913 bool emptyParams = false, noParams = false;
8914 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
8915 Type type = functionType.params.first;
8916 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
8918 Location oldyylloc = yylloc;
8920 if(!type) emptyParams = true;
8923 if(functionType.extraParam && e && functionType.thisClass)
8925 e.destType = MkClassType(functionType.thisClass.string);
8929 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
8930 // Fixed #141 by adding '&& !functionType.extraParam'
8931 if(!functionType.staticMethod && !functionType.extraParam)
8933 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
8934 memberExp.member.exp.expType._class)
8936 type = MkClassType(memberExp.member.exp.expType._class.string);
8941 type = functionType.params.first;
8946 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
8948 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
8949 type.byReference = functionType.byReference;
8950 type.typedByReference = functionType.typedByReference;
8953 // Allow manually passing a class for typed object
8954 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
8958 type = functionType.params.first;
8966 if(type && type.kind == voidType)
8969 if(!type.refCount) FreeType(type);
8973 for( ; e; e = e.next)
8975 if(!type && !emptyParams)
8978 if(methodType && methodType.methodClass)
8979 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
8980 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
8981 noParams ? 0 : functionType.params.count);
8983 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
8984 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
8985 noParams ? 0 : functionType.params.count);
8989 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
8991 Type templatedType = null;
8992 Class _class = methodType.usedClass;
8993 ClassTemplateParameter curParam = null;
8995 if(_class && _class.templateArgs /*&& _class.templateClass*/)
8998 for(sClass = _class; sClass; sClass = sClass.base)
9000 if(sClass.templateClass) sClass = sClass.templateClass;
9002 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9004 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9007 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9009 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9010 id += nextClass.templateParams.count;
9019 if(curParam && _class.templateArgs[id].dataTypeString)
9021 ClassTemplateArgument arg = _class.templateArgs[id];
9023 Context context = SetupTemplatesContext(_class);
9026 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9027 templatedType = ProcessTypeString(arg.dataTypeString, false);
9028 FinishTemplatesContext(context);
9030 e.destType = templatedType;
9033 templatedType.passAsTemplate = true;
9034 // templatedType.refCount++;
9040 if(type) type.refCount++;
9045 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9047 e.destType = type.prev;
9048 e.destType.refCount++;
9053 if(type) type.refCount++;
9056 // Don't reach the end for the ellipsis
9057 if(type && type.kind != ellipsisType)
9059 Type next = type.next;
9060 if(!type.refCount) FreeType(type);
9065 if(type && type.kind != ellipsisType)
9067 if(methodType && methodType.methodClass)
9068 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9069 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9070 functionType.params.count + extra);
9072 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9073 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9074 functionType.params.count + extra);
9077 if(type && !type.refCount) FreeType(type);
9084 kind = TypeKind::functionType;
9087 if(exp.call.exp.type == identifierExp)
9089 char * string = exp.call.exp.identifier.string;
9093 Location oldyylloc = yylloc;
9095 yylloc = exp.call.exp.identifier.loc;
9096 if(strstr(string, "__builtin_") == string)
9100 functionType.returnType = exp.destType;
9101 exp.destType.refCount++;
9105 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9106 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9107 globalContext.symbols.Add((BTNode)symbol);
9108 if(strstr(symbol.string, "::"))
9109 globalContext.hasNameSpace = true;
9114 else if(exp.call.exp.type == memberExp)
9116 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9117 exp.call.exp.member.member.string);*/
9120 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9122 if(!functionType.returnType)
9124 functionType.returnType = Type
9131 if(functionType && functionType.kind == TypeKind::functionType)
9133 exp.expType = functionType.returnType;
9135 if(functionType.returnType)
9136 functionType.returnType.refCount++;
9138 if(!functionType.refCount)
9139 FreeType(functionType);
9142 if(exp.call.arguments)
9144 for(e = exp.call.arguments->first; e; e = e.next)
9146 Type destType = e.destType;
9147 ProcessExpressionType(e);
9155 Location oldyylloc = yylloc;
9157 Expression checkExp = exp.member.exp;
9160 if(checkExp.type == castExp)
9161 checkExp = checkExp.cast.exp;
9162 else if(checkExp.type == bracketsExp)
9163 checkExp = checkExp.list ? checkExp.list->first : null;
9168 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9169 exp.thisPtr = thisPtr;
9171 // DOING THIS LATER NOW...
9172 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9174 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9175 /* TODO: Name Space Fix ups
9176 if(!exp.member.member.classSym)
9177 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9181 ProcessExpressionType(exp.member.exp);
9182 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9183 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9185 exp.isConstant = false;
9188 exp.isConstant = exp.member.exp.isConstant;
9189 type = exp.member.exp.expType;
9193 if(type && (type.kind == templateType))
9195 Class _class = thisClass ? thisClass : currentClass;
9196 ClassTemplateParameter param = null;
9199 for(param = _class.templateParams.first; param; param = param.next)
9201 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9205 if(param && param.defaultArg.member)
9207 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9210 Expression expMember = exp.member.exp;
9212 OldList * specs = MkList();
9213 char thisClassTypeString[1024];
9215 FreeIdentifier(exp.member.member);
9217 ProcessExpressionType(argExp);
9220 char * colon = strstr(param.defaultArg.memberString, "::");
9223 char className[1024];
9226 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9227 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9230 strcpy(thisClassTypeString, _class.fullName);
9233 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9235 exp.expType = ProcessType(specs, decl);
9236 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9238 Class expClass = exp.expType._class.registered;
9239 Class cClass = null;
9244 char templateString[1024];
9245 ClassTemplateParameter param;
9246 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9247 for(cClass = expClass; cClass; cClass = cClass.base)
9250 for(param = cClass.templateParams.first; param; param = param.next)
9254 ClassTemplateArgument arg;
9255 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9256 arg = expClass.templateArgs[id];
9258 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9260 ClassTemplateParameter cParam;
9261 //int p = numParams - sClass.templateParams.count;
9264 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9266 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9268 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9270 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9272 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9273 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9285 strcat(argument, arg.name.string);
9286 strcat(argument, " = ");
9292 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9293 char expString[1024];
9294 OldList * specs = MkList();
9295 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9297 char * string = PrintHexUInt64(arg.expression.ui64);
9298 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9301 ProcessExpressionType(exp);
9302 ComputeExpression(exp);
9303 expString[0] = '\0';
9304 PrintExpression(exp, expString);
9305 strcat(argument, expString);
9307 FreeExpression(exp);
9312 strcat(argument, arg.member.name);
9315 case TemplateParameterType::type:
9317 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9319 if(!strcmp(arg.dataTypeString, "thisclass"))
9320 strcat(argument, thisClassTypeString);
9322 strcat(argument, arg.dataTypeString);
9329 if(paramCount) strcat(templateString, ", ");
9330 if(lastParam != p - 1)
9332 strcat(templateString, param.name);
9333 strcat(templateString, " = ");
9335 strcat(templateString, argument);
9344 int len = strlen(templateString);
9345 if(templateString[len-1] == '>') templateString[len++] = ' ';
9346 templateString[len++] = '>';
9347 templateString[len++] = '\0';
9350 Context context = SetupTemplatesContext(_class);
9351 FreeType(exp.expType);
9352 exp.expType = ProcessTypeString(templateString, false);
9353 FinishTemplatesContext(context);
9357 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9358 exp.type = bracketsExp;
9359 exp.list = MkListOne(MkExpOp(null, '*',
9364 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9365 MkExpBrackets(MkListOne(
9366 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9368 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9370 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9375 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9376 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9378 type = ProcessTemplateParameterType(type.templateParameter);
9381 // TODO: *** This seems to be where we should add method support for all basic types ***
9382 if(type && (type.kind == templateType));
9383 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9384 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
9385 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9386 (type.kind == pointerType && type.type.kind == charType)))
9388 Identifier id = exp.member.member;
9389 TypeKind typeKind = type.kind;
9390 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9391 if(typeKind == subClassType && exp.member.exp.type == classExp)
9393 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9394 typeKind = classType;
9399 if(typeKind == intType || typeKind == enumType)
9400 _class = eSystem_FindClass(privateModule, "int");
9403 if(type.kind == classType && type._class && type._class.registered)
9405 _class = type._class.registered;
9407 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
9409 _class = FindClass("char *").registered;
9411 else if(type.kind == pointerType)
9413 _class = eSystem_FindClass(privateModule, "uintptr");
9414 FreeType(exp.expType);
9415 exp.expType = ProcessTypeString("uintptr", false);
9416 exp.byReference = true;
9420 char string[1024] = "";
9422 PrintTypeNoConst(type, string, false, true);
9423 classSym = FindClass(string);
9424 if(classSym) _class = classSym.registered;
9432 (exp.member.exp.type == identifierExp &&
9433 !strcmp(exp.member.exp.identifier.string, "this"));*/
9434 Property prop = null;
9435 Method method = null;
9436 DataMember member = null;
9437 Property revConvert = null;
9438 ClassProperty classProp = null;
9440 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9441 exp.member.memberType = propertyMember;
9443 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9444 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9446 if(typeKind != subClassType)
9448 // Prioritize data members over properties for "this"
9449 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9451 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9452 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9454 prop = eClass_FindProperty(_class, id.string, privateModule);
9458 if(!member && !prop)
9459 prop = eClass_FindProperty(_class, id.string, privateModule);
9460 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9461 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9462 exp.member.thisPtr = true;
9464 // Prioritize properties over data members otherwise
9467 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9470 prop = eClass_FindProperty(_class, id.string, null);
9471 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9472 member = eClass_FindDataMember(_class, id.string, null, null, null);
9475 if(!prop && !member)
9477 method = eClass_FindMethod(_class, id.string, null);
9480 prop = eClass_FindProperty(_class, id.string, privateModule);
9481 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9482 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9488 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9495 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
9496 method = eClass_FindMethod(_class, id.string, privateModule);
9497 if(!prop && !member && !method)
9499 if(typeKind == subClassType)
9501 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9504 exp.member.memberType = classPropertyMember;
9505 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9509 // Assume this is a class_data member
9510 char structName[1024];
9511 Identifier id = exp.member.member;
9512 Expression classExp = exp.member.exp;
9515 FreeType(classExp.expType);
9516 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9518 strcpy(structName, "__ecereClassData_");
9519 FullClassNameCat(structName, type._class.string, false);
9520 exp.type = pointerExp;
9521 exp.member.member = id;
9523 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9524 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9525 MkExpBrackets(MkListOne(MkExpOp(
9526 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9527 MkExpMember(classExp, MkIdentifier("data"))), '+',
9528 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9533 ProcessExpressionType(exp);
9539 // Check for reverse conversion
9540 // (Convert in an instantiation later, so that we can use
9541 // deep properties system)
9542 Symbol classSym = FindClass(id.string);
9545 Class convertClass = classSym.registered;
9547 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9554 exp.member.memberType = propertyMember;
9556 ProcessPropertyType(prop);
9557 exp.expType = prop.dataType;
9558 if(prop.dataType) prop.dataType.refCount++;
9562 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9564 FreeExpContents(exp);
9565 exp.type = identifierExp;
9566 exp.identifier = MkIdentifier("class");
9567 ProcessExpressionType(exp);
9571 exp.member.memberType = dataMember;
9572 DeclareStruct(_class.fullName, false);
9573 if(!member.dataType)
9575 Context context = SetupTemplatesContext(_class);
9576 member.dataType = ProcessTypeString(member.dataTypeString, false);
9577 FinishTemplatesContext(context);
9579 exp.expType = member.dataType;
9580 if(member.dataType) member.dataType.refCount++;
9584 exp.member.memberType = reverseConversionMember;
9585 exp.expType = MkClassType(revConvert._class.fullName);
9593 exp.type = identifierExp;
9594 exp.identifier = exp.member.member;
9597 exp.member.memberType = methodMember;
9599 if(!method.dataType)
9600 ProcessMethodType(method);
9608 // Tricky spot here... To use instance versus class virtual table
9609 // Put it back to what it was... What did we break?
9611 // Had to put it back for overriding Main of Thread global instance
9613 //exp.expType.methodClass = _class;
9614 exp.expType.methodClass = (id && id._class) ? _class : null;
9616 // Need the actual class used for templated classes
9617 exp.expType.usedClass = _class;
9621 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9623 FreeExpContents(exp);
9624 exp.type = identifierExp;
9625 exp.identifier = MkIdentifier("class");
9626 ProcessExpressionType(exp);
9629 yylloc = exp.member.member.loc;
9630 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9632 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9635 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9640 while(tClass && !tClass.templateClass) tClass = tClass.base;
9642 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9645 ClassTemplateParameter curParam = null;
9648 for(sClass = tClass; sClass; sClass = sClass.base)
9651 if(sClass.templateClass) sClass = sClass.templateClass;
9652 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9654 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9656 for(sClass = sClass.base; sClass; sClass = sClass.base)
9657 id += sClass.templateParams.count;
9665 if(curParam && tClass.templateArgs[id].dataTypeString)
9667 ClassTemplateArgument arg = tClass.templateArgs[id];
9668 Context context = SetupTemplatesContext(tClass);
9670 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9671 FreeType(exp.expType);
9672 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9675 if(exp.expType.kind == thisClassType)
9677 FreeType(exp.expType);
9678 exp.expType = ReplaceThisClassType(_class);
9681 if(tClass.templateClass)
9682 exp.expType.passAsTemplate = true;
9683 //exp.expType.refCount++;
9686 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9687 //exp.destType.refCount++;
9689 if(exp.destType.kind == thisClassType)
9691 FreeType(exp.destType);
9692 exp.destType = ReplaceThisClassType(_class);
9696 FinishTemplatesContext(context);
9699 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9700 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9703 ClassTemplateParameter curParam = null;
9706 for(sClass = tClass; sClass; sClass = sClass.base)
9709 if(sClass.templateClass) sClass = sClass.templateClass;
9710 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9712 if(curParam.type == TemplateParameterType::type &&
9713 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9715 for(sClass = sClass.base; sClass; sClass = sClass.base)
9716 id += sClass.templateParams.count;
9726 ClassTemplateArgument arg = tClass.templateArgs[id];
9727 Context context = SetupTemplatesContext(tClass);
9730 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9732 basicType = ProcessTypeString(arg.dataTypeString, false);
9735 if(basicType.kind == thisClassType)
9737 FreeType(basicType);
9738 basicType = ReplaceThisClassType(_class);
9741 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9742 if(tClass.templateClass)
9743 basicType.passAsTemplate = true;
9746 FreeType(exp.expType);
9748 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9749 //exp.expType.refCount++;
9752 exp.destType = exp.expType;
9753 exp.destType.refCount++;
9757 Expression newExp { };
9758 OldList * specs = MkList();
9760 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9762 if(exp.destType) exp.destType.refCount++;
9763 if(exp.expType) exp.expType.refCount++;
9765 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9766 exp.cast.exp = newExp;
9767 //FreeType(exp.expType);
9768 //exp.expType = null;
9769 //ProcessExpressionType(sourceExp);
9772 FinishTemplatesContext(context);
9775 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9777 Class expClass = exp.expType._class.registered;
9780 Class cClass = null;
9785 char templateString[1024];
9786 ClassTemplateParameter param;
9787 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9788 while(cClass != expClass)
9791 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9794 for(param = cClass.templateParams.first; param; param = param.next)
9796 Class cClassCur = null;
9799 ClassTemplateParameter paramCur = null;
9800 ClassTemplateArgument arg;
9801 while(cClassCur != tClass && !paramCur)
9804 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
9805 cClassCur = sClassCur;
9807 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
9809 if(!strcmp(paramCur.name, param.name))
9817 if(paramCur && paramCur.type == TemplateParameterType::type)
9818 arg = tClass.templateArgs[cp];
9820 arg = expClass.templateArgs[p];
9827 strcat(argument, arg.name.string);
9828 strcat(argument, " = ");
9834 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9835 char expString[1024];
9836 OldList * specs = MkList();
9837 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9839 char * string = PrintHexUInt64(arg.expression.ui64);
9840 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9843 ProcessExpressionType(exp);
9844 ComputeExpression(exp);
9845 expString[0] = '\0';
9846 PrintExpression(exp, expString);
9847 strcat(argument, expString);
9849 FreeExpression(exp);
9854 strcat(argument, arg.member.name);
9857 case TemplateParameterType::type:
9859 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9860 strcat(argument, arg.dataTypeString);
9866 if(paramCount) strcat(templateString, ", ");
9867 if(lastParam != p - 1)
9869 strcat(templateString, param.name);
9870 strcat(templateString, " = ");
9872 strcat(templateString, argument);
9881 int len = strlen(templateString);
9882 if(templateString[len-1] == '>') templateString[len++] = ' ';
9883 templateString[len++] = '>';
9884 templateString[len++] = '\0';
9887 FreeType(exp.expType);
9889 Context context = SetupTemplatesContext(tClass);
9890 exp.expType = ProcessTypeString(templateString, false);
9891 FinishTemplatesContext(context);
9898 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
9900 else if(type && (type.kind == structType || type.kind == unionType))
9902 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
9905 exp.expType = memberType;
9907 memberType.refCount++;
9912 char expString[10240];
9913 expString[0] = '\0';
9914 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
9915 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
9918 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
9920 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9922 Identifier id = exp.member.member;
9923 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9926 FreeType(exp.expType);
9927 exp.expType = ReplaceThisClassType(_class);
9934 // Convert x->y into (*x).y
9937 Type destType = exp.destType;
9939 // DOING THIS LATER NOW...
9940 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9942 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9943 /* TODO: Name Space Fix ups
9944 if(!exp.member.member.classSym)
9945 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
9949 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
9950 exp.type = memberExp;
9953 ProcessExpressionType(exp);
9960 //ComputeExpression(exp);
9962 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
9963 if(classSym && classSym.registered)
9965 if(classSym.registered.type == noHeadClass)
9969 DeclareStruct(classSym.string, false);
9970 FreeSpecifier(exp._class);
9971 exp.type = typeSizeExp;
9972 FullClassNameCat(name, classSym.string, false);
9973 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
9977 if(classSym.registered.fixed)
9979 FreeSpecifier(exp._class);
9980 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
9981 exp.type = constantExp;
9985 char className[1024];
9986 strcpy(className, "__ecereClass_");
9987 FullClassNameCat(className, classSym.string, true);
9988 MangleClassName(className);
9990 DeclareClass(classSym, className);
9992 FreeExpContents(exp);
9993 exp.type = pointerExp;
9994 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
9995 exp.member.member = MkIdentifier("structSize");
10005 // exp.isConstant = true;
10010 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10017 exp.isConstant = true;
10019 DeclareType(type, false, false);
10025 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10027 FreeType(exp.cast.exp.destType);
10028 exp.cast.exp.destType = type;
10030 ProcessExpressionType(exp.cast.exp);
10032 exp.expType = type;
10035 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10036 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10038 void * prev = exp.prev, * next = exp.next;
10039 Type expType = exp.cast.exp.destType;
10040 Expression castExp = exp.cast.exp;
10041 Type destType = exp.destType;
10043 if(expType) expType.refCount++;
10045 //FreeType(exp.destType);
10046 FreeType(exp.expType);
10047 FreeTypeName(exp.cast.typeName);
10050 FreeType(exp.expType);
10051 FreeType(exp.destType);
10053 exp.expType = expType;
10054 exp.destType = destType;
10064 exp.isConstant = exp.cast.exp.isConstant;
10069 case extensionInitializerExp:
10071 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10072 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10073 // ProcessInitializer(exp.initializer.initializer, type);
10074 exp.expType = type;
10079 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10080 ProcessExpressionType(exp.vaArg.exp);
10081 exp.expType = type;
10087 exp.isConstant = true;
10089 FreeType(exp.cond.cond.destType);
10090 exp.cond.cond.destType = MkClassType("bool");
10091 exp.cond.cond.destType.truth = true;
10092 ProcessExpressionType(exp.cond.cond);
10093 if(!exp.cond.cond.isConstant)
10094 exp.isConstant = false;
10095 for(e = exp.cond.exp->first; e; e = e.next)
10099 FreeType(e.destType);
10100 e.destType = exp.destType;
10101 if(e.destType) e.destType.refCount++;
10103 ProcessExpressionType(e);
10106 exp.expType = e.expType;
10107 if(e.expType) e.expType.refCount++;
10110 exp.isConstant = false;
10113 FreeType(exp.cond.elseExp.destType);
10114 // Added this check if we failed to find an expType
10115 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10118 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10120 if(exp.cond.elseExp.destType)
10121 exp.cond.elseExp.destType.refCount++;
10122 ProcessExpressionType(exp.cond.elseExp);
10124 // FIXED THIS: Was done before calling process on elseExp
10125 if(!exp.cond.elseExp.isConstant)
10126 exp.isConstant = false;
10129 case extensionCompoundExp:
10131 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10133 Statement last = exp.compound.compound.statements->last;
10134 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10136 ((Expression)last.expressions->last).destType = exp.destType;
10138 exp.destType.refCount++;
10140 ProcessStatement(exp.compound);
10141 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10143 exp.expType.refCount++;
10149 Specifier spec = exp._classExp.specifiers->first;
10150 if(spec && spec.type == nameSpecifier)
10152 exp.expType = MkClassType(spec.name);
10153 exp.expType.kind = subClassType;
10154 exp.byReference = true;
10158 exp.expType = MkClassType("ecere::com::Class");
10159 exp.byReference = true;
10165 Class _class = thisClass ? thisClass : currentClass;
10168 Identifier id = exp.classData.id;
10169 char structName[1024];
10170 Expression classExp;
10171 strcpy(structName, "__ecereClassData_");
10172 FullClassNameCat(structName, _class.fullName, false);
10173 exp.type = pointerExp;
10174 exp.member.member = id;
10175 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10176 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10178 classExp = MkExpIdentifier(MkIdentifier("class"));
10180 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10181 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10182 MkExpBrackets(MkListOne(MkExpOp(
10183 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10184 MkExpMember(classExp, MkIdentifier("data"))), '+',
10185 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10188 ProcessExpressionType(exp);
10196 char * typeString = null;
10197 char typeStringBuf[1024];
10198 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10199 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10201 Class templateClass = exp.destType._class.registered;
10202 typeString = templateClass.templateArgs[2].dataTypeString;
10206 // Guess type from expressions in the array
10208 for(e = exp.list->first; e; e = e.next)
10210 ProcessExpressionType(e);
10213 if(!type) { type = e.expType; type.refCount++; }
10216 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10217 if(!MatchTypeExpression(e, type, null, false))
10223 e = exp.list->first;
10224 ProcessExpressionType(e);
10227 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10228 if(!MatchTypeExpression(e, type, null, false))
10230 FreeType(e.expType);
10241 FreeType(e.expType);
10248 typeStringBuf[0] = '\0';
10249 PrintTypeNoConst(type, typeStringBuf, false, true);
10250 typeString = typeStringBuf;
10258 (Container)& (struct BuiltInContainer)
10260 ._vTbl = class(BuiltInContainer)._vTbl,
10261 ._class = class(BuiltInContainer),
10263 .data = (int[]){ 1, 7, 3, 4, 5 },
10265 .type = class(int),
10268 char templateString[1024];
10269 OldList * initializers = MkList();
10270 OldList * structInitializers = MkList();
10271 OldList * specs = MkList();
10273 Declarator decl = SpecDeclFromString(typeString, specs, null);
10274 sprintf(templateString, "Container<%s>", typeString);
10279 type = ProcessTypeString(typeString, false);
10280 while(e = exp.list->first)
10282 exp.list->Remove(e);
10285 ProcessExpressionType(e);
10286 ListAdd(initializers, MkInitializerAssignment(e));
10292 DeclareStruct("ecere::com::BuiltInContainer", false);
10294 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10295 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10296 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10297 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10298 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10299 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10300 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10301 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10302 MkInitializerList(initializers))));
10303 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10304 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10305 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10306 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10307 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10308 exp.expType = ProcessTypeString(templateString, false);
10309 exp.type = bracketsExp;
10310 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10312 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10313 MkInitializerList(structInitializers)))));
10314 ProcessExpressionType(expExt);
10318 exp.expType = ProcessTypeString("Container", false);
10319 Compiler_Error($"Couldn't determine type of array elements\n");
10325 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10327 FreeType(exp.expType);
10328 exp.expType = ReplaceThisClassType(thisClass);
10331 // Resolve structures here
10332 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10334 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10335 // TODO: Fix members reference...
10338 if(exp.expType.kind != enumType)
10341 String enumName = CopyString(exp.expType.enumName);
10343 // Fixed a memory leak on self-referencing C structs typedefs
10344 // by instantiating a new type rather than simply copying members
10345 // into exp.expType
10346 FreeType(exp.expType);
10347 exp.expType = Type { };
10348 exp.expType.kind = symbol.type.kind;
10349 exp.expType.refCount++;
10350 exp.expType.enumName = enumName;
10352 exp.expType.members = symbol.type.members;
10353 for(member = symbol.type.members.first; member; member = member.next)
10359 for(member = symbol.type.members.first; member; member = member.next)
10361 NamedLink value { name = CopyString(member.name) };
10362 exp.expType.members.Add(value);
10369 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10370 else if(exp.destType && !exp.destType.keepCast)
10372 if(!CheckExpressionType(exp, exp.destType, false))
10374 if(!exp.destType.count || unresolved)
10379 if(exp.destType.kind != ellipsisType)
10385 char expString[10240];
10386 expString[0] = '\0';
10388 PrintType(exp.destType, type2, false, true);
10390 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10392 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10393 else if(exp.type != dummyExp)
10394 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10399 char expString[10240] ;
10400 expString[0] = '\0';
10401 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10404 Compiler_Error($"unresolved identifier %s\n", expString);
10405 else if(exp.type != dummyExp)
10406 Compiler_Error($"couldn't determine type of %s\n", expString);
10417 PrintType(exp.expType, type1, false, true);
10418 PrintType(exp.destType, type2, false, true);
10421 //CheckExpressionType(exp, exp.destType, false);
10423 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10424 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10425 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10428 char expString[10240];
10429 expString[0] = '\0';
10430 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10433 CheckExpressionType(exp, exp.destType, false);
10435 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10436 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10437 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10439 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10440 FreeType(exp.expType);
10441 exp.destType.refCount++;
10442 exp.expType = exp.destType;
10447 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10449 Expression newExp { };
10450 char typeString[1024];
10451 OldList * specs = MkList();
10454 typeString[0] = '\0';
10458 if(exp.expType) exp.expType.refCount++;
10459 if(exp.expType) exp.expType.refCount++;
10460 exp.type = castExp;
10461 newExp.destType = exp.expType;
10463 PrintType(exp.expType, typeString, false, false);
10464 decl = SpecDeclFromString(typeString, specs, null);
10466 exp.cast.typeName = MkTypeName(specs, decl);
10467 exp.cast.exp = newExp;
10470 else if(unresolved)
10472 if(exp.identifier._class && exp.identifier._class.name)
10473 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10474 else if(exp.identifier.string && exp.identifier.string[0])
10475 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10477 else if(!exp.expType && exp.type != dummyExp)
10479 char expString[10240];
10480 expString[0] = '\0';
10481 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10482 Compiler_Error($"couldn't determine type of %s\n", expString);
10485 // Let's try to support any_object & typed_object here:
10487 ApplyAnyObjectLogic(exp);
10489 // Mark nohead classes as by reference, unless we're casting them to an integral type
10490 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10491 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
10492 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
10493 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
10495 exp.byReference = true;
10497 yylloc = oldyylloc;
10500 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10502 // THIS CODE WILL FIND NEXT MEMBER...
10505 *curMember = (*curMember).next;
10507 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10509 *curMember = subMemberStack[--(*subMemberStackPos)];
10510 *curMember = (*curMember).next;
10513 // SKIP ALL PROPERTIES HERE...
10514 while((*curMember) && (*curMember).isProperty)
10515 *curMember = (*curMember).next;
10517 if(subMemberStackPos)
10519 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10521 subMemberStack[(*subMemberStackPos)++] = *curMember;
10523 *curMember = (*curMember).members.first;
10524 while(*curMember && (*curMember).isProperty)
10525 *curMember = (*curMember).next;
10533 if(subMemberStackPos && *subMemberStackPos)
10535 *curMember = subMemberStack[--(*subMemberStackPos)];
10536 *curMember = (*curMember).next;
10540 Class lastCurClass = *curClass;
10542 if(*curClass == _class) break; // REACHED THE END
10544 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10545 *curMember = (*curClass).membersAndProperties.first;
10548 while((*curMember) && (*curMember).isProperty)
10549 *curMember = (*curMember).next;
10550 if(subMemberStackPos)
10552 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10554 subMemberStack[(*subMemberStackPos)++] = *curMember;
10556 *curMember = (*curMember).members.first;
10557 while(*curMember && (*curMember).isProperty)
10558 *curMember = (*curMember).next;
10566 static void ProcessInitializer(Initializer init, Type type)
10570 case expInitializer:
10571 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10573 // TESTING THIS FOR SHUTTING = 0 WARNING
10574 if(init.exp && !init.exp.destType)
10576 FreeType(init.exp.destType);
10577 init.exp.destType = type;
10578 if(type) type.refCount++;
10582 ProcessExpressionType(init.exp);
10583 init.isConstant = init.exp.isConstant;
10589 Expression exp = init.exp;
10590 Instantiation inst = exp.instance;
10591 MembersInit members;
10593 init.type = listInitializer;
10594 init.list = MkList();
10598 for(members = inst.members->first; members; members = members.next)
10600 if(members.type == dataMembersInit)
10603 for(member = members.dataMembers->first; member; member = member.next)
10605 ListAdd(init.list, member.initializer);
10606 member.initializer = null;
10609 // Discard all MembersInitMethod
10612 FreeExpression(exp);
10614 case listInitializer:
10617 Type initializerType = null;
10618 Class curClass = null;
10619 DataMember curMember = null;
10620 DataMember subMemberStack[256];
10621 int subMemberStackPos = 0;
10623 if(type && type.kind == arrayType)
10624 initializerType = Dereference(type);
10625 else if(type && (type.kind == structType || type.kind == unionType))
10626 initializerType = type.members.first;
10628 for(i = init.list->first; i; i = i.next)
10630 if(type && type.kind == classType && type._class && type._class.registered)
10632 // 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)
10633 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10634 // TODO: Generate error on initializing a private data member this way from another module...
10637 if(!curMember.dataType)
10638 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10639 initializerType = curMember.dataType;
10642 ProcessInitializer(i, initializerType);
10643 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10644 initializerType = initializerType.next;
10646 init.isConstant = false;
10649 if(type && type.kind == arrayType)
10650 FreeType(initializerType);
10652 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10654 Compiler_Error($"Assigning list initializer to non list\n");
10661 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10665 case baseSpecifier:
10667 if(spec.specifier == THISCLASS)
10671 spec.type = nameSpecifier;
10672 spec.name = ReplaceThisClass(thisClass);
10673 spec.symbol = FindClass(spec.name);
10674 ProcessSpecifier(spec, declareStruct);
10679 case nameSpecifier:
10681 Symbol symbol = FindType(curContext, spec.name);
10683 DeclareType(symbol.type, true, true);
10684 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10685 DeclareStruct(spec.name, false);
10688 case enumSpecifier:
10693 for(e = spec.list->first; e; e = e.next)
10696 ProcessExpressionType(e.exp);
10701 case structSpecifier:
10702 case unionSpecifier:
10704 if(spec.definitions)
10707 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10709 ProcessClass(spec.definitions, symbol);
10712 for(def = spec.definitions->first; def; def = def.next)
10714 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10715 ProcessDeclaration(def.decl);
10722 case classSpecifier:
10724 Symbol classSym = FindClass(spec.name);
10725 if(classSym && classSym.registered && classSym.registered.type == structClass)
10726 DeclareStruct(spec.name, false);
10734 static void ProcessDeclarator(Declarator decl)
10738 case identifierDeclarator:
10739 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10741 FreeSpecifier(decl.identifier._class);
10742 decl.identifier._class = null;
10745 case arrayDeclarator:
10747 ProcessExpressionType(decl.array.exp);
10748 case structDeclarator:
10749 case bracketsDeclarator:
10750 case functionDeclarator:
10751 case pointerDeclarator:
10752 case extendedDeclarator:
10753 case extendedDeclaratorEnd:
10754 if(decl.declarator)
10755 ProcessDeclarator(decl.declarator);
10756 if(decl.type == functionDeclarator)
10758 Identifier id = GetDeclId(decl);
10759 if(id && id._class)
10763 qualifiers = MkListOne(id._class);
10766 if(!decl.function.parameters)
10767 decl.function.parameters = MkList();
10768 decl.function.parameters->Insert(null, param);
10771 if(decl.function.parameters)
10775 for(param = decl.function.parameters->first; param; param = param.next)
10777 if(param.qualifiers && param.qualifiers->first)
10779 Specifier spec = param.qualifiers->first;
10780 if(spec && spec.specifier == TYPED_OBJECT)
10782 Declarator d = param.declarator;
10785 qualifiers = MkListOne(MkSpecifier(VOID));
10786 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10789 FreeList(param.qualifiers, FreeSpecifier);
10791 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10792 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10794 decl.function.parameters->Insert(param, newParam);
10797 else if(spec && spec.specifier == ANY_OBJECT)
10799 Declarator d = param.declarator;
10801 FreeList(param.qualifiers, FreeSpecifier);
10803 param.qualifiers = MkListOne(MkSpecifier(VOID));
10804 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10806 else if(spec.specifier == THISCLASS)
10810 spec.type = nameSpecifier;
10811 spec.name = ReplaceThisClass(thisClass);
10812 spec.symbol = FindClass(spec.name);
10813 ProcessSpecifier(spec, false);
10818 if(param.declarator)
10819 ProcessDeclarator(param.declarator);
10827 static void ProcessDeclaration(Declaration decl)
10832 case initDeclaration:
10834 bool declareStruct = false;
10836 lineNum = decl.pos.line;
10837 column = decl.pos.col;
10840 if(decl.declarators)
10844 for(d = decl.declarators->first; d; d = d.next)
10846 Type type, subType;
10847 ProcessDeclarator(d.declarator);
10849 type = ProcessType(decl.specifiers, d.declarator);
10853 ProcessInitializer(d.initializer, type);
10855 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
10857 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
10858 d.initializer.exp.type == instanceExp)
10860 if(type.kind == classType && type._class ==
10861 d.initializer.exp.expType._class)
10863 Instantiation inst = d.initializer.exp.instance;
10864 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
10866 d.initializer.exp.instance = null;
10867 if(decl.specifiers)
10868 FreeList(decl.specifiers, FreeSpecifier);
10869 FreeList(decl.declarators, FreeInitDeclarator);
10873 decl.type = instDeclaration;
10878 for(subType = type; subType;)
10880 if(subType.kind == classType)
10882 declareStruct = true;
10885 else if(subType.kind == pointerType)
10887 else if(subType.kind == arrayType)
10888 subType = subType.arrayType;
10898 if(decl.specifiers)
10901 for(s = decl.specifiers->first; s; s = s.next)
10903 ProcessSpecifier(s, declareStruct);
10908 case instDeclaration:
10910 ProcessInstantiationType(decl.inst);
10913 case structDeclaration:
10917 bool declareStruct = false;
10919 if(decl.declarators)
10921 for(d = decl.declarators->first; d; d = d.next)
10923 Type type = ProcessType(decl.specifiers, d.declarator);
10925 ProcessDeclarator(d);
10926 for(subType = type; subType;)
10928 if(subType.kind == classType)
10930 declareStruct = true;
10933 else if(subType.kind == pointerType)
10935 else if(subType.kind == arrayType)
10936 subType = subType.arrayType;
10943 if(decl.specifiers)
10945 for(spec = decl.specifiers->first; spec; spec = spec.next)
10946 ProcessSpecifier(spec, declareStruct);
10953 static FunctionDefinition curFunction;
10955 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
10957 char propName[1024], propNameM[1024];
10958 char getName[1024], setName[1024];
10961 DeclareProperty(prop, setName, getName);
10963 // eInstance_FireWatchers(object, prop);
10964 strcpy(propName, "__ecereProp_");
10965 FullClassNameCat(propName, prop._class.fullName, false);
10966 strcat(propName, "_");
10967 // strcat(propName, prop.name);
10968 FullClassNameCat(propName, prop.name, true);
10969 MangleClassName(propName);
10971 strcpy(propNameM, "__ecerePropM_");
10972 FullClassNameCat(propNameM, prop._class.fullName, false);
10973 strcat(propNameM, "_");
10974 // strcat(propNameM, prop.name);
10975 FullClassNameCat(propNameM, prop.name, true);
10976 MangleClassName(propNameM);
10978 if(prop.isWatchable)
10981 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10982 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10983 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10986 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10987 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10988 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10994 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10995 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10996 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10999 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11000 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11001 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11004 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11005 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11006 curFunction.propSet.fireWatchersDone = true;
11009 static void ProcessStatement(Statement stmt)
11013 lineNum = stmt.pos.line;
11014 column = stmt.pos.col;
11019 ProcessStatement(stmt.labeled.stmt);
11022 // This expression should be constant...
11023 if(stmt.caseStmt.exp)
11025 FreeType(stmt.caseStmt.exp.destType);
11026 stmt.caseStmt.exp.destType = curSwitchType;
11027 if(curSwitchType) curSwitchType.refCount++;
11028 ProcessExpressionType(stmt.caseStmt.exp);
11029 ComputeExpression(stmt.caseStmt.exp);
11031 if(stmt.caseStmt.stmt)
11032 ProcessStatement(stmt.caseStmt.stmt);
11036 if(stmt.compound.context)
11041 Statement prevCompound = curCompound;
11042 Context prevContext = curContext;
11044 if(!stmt.compound.isSwitch)
11045 curCompound = stmt;
11046 curContext = stmt.compound.context;
11048 if(stmt.compound.declarations)
11050 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11051 ProcessDeclaration(decl);
11053 if(stmt.compound.statements)
11055 for(s = stmt.compound.statements->first; s; s = s.next)
11056 ProcessStatement(s);
11059 curContext = prevContext;
11060 curCompound = prevCompound;
11064 case expressionStmt:
11067 if(stmt.expressions)
11069 for(exp = stmt.expressions->first; exp; exp = exp.next)
11070 ProcessExpressionType(exp);
11078 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11079 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11080 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11081 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11083 ProcessExpressionType(exp);
11085 if(stmt.ifStmt.stmt)
11086 ProcessStatement(stmt.ifStmt.stmt);
11087 if(stmt.ifStmt.elseStmt)
11088 ProcessStatement(stmt.ifStmt.elseStmt);
11093 Type oldSwitchType = curSwitchType;
11094 if(stmt.switchStmt.exp)
11097 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11107 e.exp.destType = destType;
11110 ProcessExpressionType(exp);
11113 curSwitchType = exp.expType;
11116 ProcessStatement(stmt.switchStmt.stmt);
11117 curSwitchType = oldSwitchType;
11122 if(stmt.whileStmt.exp)
11126 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11127 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11128 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11129 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11131 ProcessExpressionType(exp);
11134 if(stmt.whileStmt.stmt)
11135 ProcessStatement(stmt.whileStmt.stmt);
11140 if(stmt.doWhile.exp)
11144 if(stmt.doWhile.exp->last)
11146 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11147 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11148 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11150 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11152 ProcessExpressionType(exp);
11155 if(stmt.doWhile.stmt)
11156 ProcessStatement(stmt.doWhile.stmt);
11162 if(stmt.forStmt.init)
11163 ProcessStatement(stmt.forStmt.init);
11165 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11167 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11168 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11169 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11172 if(stmt.forStmt.check)
11173 ProcessStatement(stmt.forStmt.check);
11174 if(stmt.forStmt.increment)
11176 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11177 ProcessExpressionType(exp);
11180 if(stmt.forStmt.stmt)
11181 ProcessStatement(stmt.forStmt.stmt);
11186 Identifier id = stmt.forEachStmt.id;
11187 OldList * exp = stmt.forEachStmt.exp;
11188 OldList * filter = stmt.forEachStmt.filter;
11189 Statement block = stmt.forEachStmt.stmt;
11190 char iteratorType[1024];
11193 bool isBuiltin = exp && exp->last &&
11194 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11195 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11196 Expression arrayExp;
11197 char * typeString = null;
11198 int builtinCount = 0;
11200 for(e = exp ? exp->first : null; e; e = e.next)
11204 FreeType(e.destType);
11205 e.destType = ProcessTypeString("Container", false);
11207 if(!isBuiltin || e.next)
11208 ProcessExpressionType(e);
11211 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11212 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11213 eClass_IsDerived(source._class.registered, containerClass)))
11215 Class _class = source ? source._class.registered : null;
11217 Expression expIt = null;
11218 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
11219 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11220 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11221 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11222 stmt.type = compoundStmt;
11224 stmt.compound.context = Context { };
11225 stmt.compound.context.parent = curContext;
11226 curContext = stmt.compound.context;
11228 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11230 Class mapClass = eSystem_FindClass(privateModule, "Map");
11231 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11232 isCustomAVLTree = true;
11233 if(eClass_IsDerived(source._class.registered, avlTreeClass))
11235 else if(eClass_IsDerived(source._class.registered, mapClass))
11238 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11239 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11241 Class listClass = eSystem_FindClass(privateModule, "List");
11243 isList = eClass_IsDerived(source._class.registered, listClass);
11249 OldList * specs = MkList();
11250 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11251 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11252 stmt.compound.declarations = MkListOne(
11253 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11254 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11255 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11256 MkInitializerAssignment(MkExpBrackets(exp))))));
11261 char typeStringBuf[1024];
11263 // TODO: Merge this code?
11264 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11265 if(((Expression)exp->last).type == castExp)
11267 TypeName typeName = ((Expression)exp->last).cast.typeName;
11269 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11272 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11273 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11274 arrayExp.destType._class.registered.templateArgs)
11276 Class templateClass = arrayExp.destType._class.registered;
11277 typeString = templateClass.templateArgs[2].dataTypeString;
11279 else if(arrayExp.list)
11281 // Guess type from expressions in the array
11283 for(e = arrayExp.list->first; e; e = e.next)
11285 ProcessExpressionType(e);
11288 if(!type) { type = e.expType; type.refCount++; }
11291 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11292 if(!MatchTypeExpression(e, type, null, false))
11298 e = arrayExp.list->first;
11299 ProcessExpressionType(e);
11302 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11303 if(!MatchTypeExpression(e, type, null, false))
11305 FreeType(e.expType);
11316 FreeType(e.expType);
11323 typeStringBuf[0] = '\0';
11324 PrintType(type, typeStringBuf, false, true);
11325 typeString = typeStringBuf;
11331 OldList * initializers = MkList();
11333 OldList * specs = MkList();
11338 builtinCount = arrayExp.list->count;
11339 type = ProcessTypeString(typeString, false);
11340 while(e = arrayExp.list->first)
11342 arrayExp.list->Remove(e);
11345 ProcessExpressionType(e);
11346 ListAdd(initializers, MkInitializerAssignment(e));
11349 delete arrayExp.list;
11351 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11352 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11353 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11355 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
11357 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
11358 ), MkInitializerList(initializers)))));
11359 FreeList(exp, FreeExpression);
11363 arrayExp.expType = ProcessTypeString("Container", false);
11364 Compiler_Error($"Couldn't determine type of array elements\n");
11369 OldList * specs = MkList();
11371 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11372 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11373 stmt.compound.declarations = MkListOne(
11374 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11375 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11376 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11377 MkInitializerAssignment(MkExpBrackets(exp))))));
11380 else if(isLinkList && !isList)
11383 OldList * specs = MkList();
11384 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11385 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11386 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11387 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11388 MkInitializerAssignment(MkExpBrackets(exp))))));
11390 /*else if(isCustomAVLTree)
11393 OldList * specs = MkList();
11394 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11395 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11396 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11397 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11398 MkInitializerAssignment(MkExpBrackets(exp))))));
11400 else if(_class.templateArgs)
11403 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11405 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11407 stmt.compound.declarations = MkListOne(
11408 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11409 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11410 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11412 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11416 // Reparent sub-contexts in this statement
11420 if(block.compound.context)
11421 block.compound.context.parent = stmt.compound.context;
11424 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
11425 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
11426 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
11427 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
11430 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
11431 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
11434 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
11435 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
11438 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
11439 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
11442 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
11443 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
11446 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
11447 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
11449 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
11452 case expressionStmt:
11458 case badDeclarationStmt:
11459 case fireWatchersStmt:
11460 case stopWatchingStmt:
11467 block = MkIfStmt(filter, block, null);
11471 stmt.compound.statements = MkListOne(MkForStmt(
11472 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11473 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11474 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11475 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11477 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11478 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11479 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11484 //OldList * specs = MkList();
11485 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11487 sprintf(count, "%d", builtinCount);
11489 stmt.compound.statements = MkListOne(MkForStmt(
11490 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11491 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11492 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11493 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11497 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11498 stmt.compound.statements = MkListOne(MkForStmt(
11499 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11500 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11501 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11502 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11505 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11506 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11507 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11509 else if(isLinkList && !isList)
11511 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11512 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11513 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11514 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11516 stmt.compound.statements = MkListOne(MkForStmt(
11517 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11518 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11519 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11524 OldList * specs = MkList();
11525 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11526 stmt.compound.statements = MkListOne(MkForStmt(
11527 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11528 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11529 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11530 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11531 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11534 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11535 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11536 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11538 /*else if(isCustomAVLTree)
11540 stmt.compound.statements = MkListOne(MkForStmt(
11541 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11542 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11543 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11544 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11547 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11548 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11549 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11553 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11554 MkIdentifier("Next")), null)), block));
11556 ProcessExpressionType(expIt);
11557 if(stmt.compound.declarations->first)
11558 ProcessDeclaration(stmt.compound.declarations->first);
11561 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11563 ProcessStatement(stmt);
11564 curContext = stmt.compound.context.parent;
11569 Compiler_Error($"Expression is not a container\n");
11582 if(stmt.expressions)
11584 for(exp = stmt.expressions->first; exp; exp = exp.next)
11588 if(curFunction && !curFunction.type)
11589 curFunction.type = ProcessType(
11590 curFunction.specifiers, curFunction.declarator);
11591 FreeType(exp.destType);
11592 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11593 if(exp.destType) exp.destType.refCount++;
11595 ProcessExpressionType(exp);
11600 case badDeclarationStmt:
11602 ProcessDeclaration(stmt.decl);
11608 if(stmt.asmStmt.inputFields)
11610 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11611 if(field.expression)
11612 ProcessExpressionType(field.expression);
11614 if(stmt.asmStmt.outputFields)
11616 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11617 if(field.expression)
11618 ProcessExpressionType(field.expression);
11620 if(stmt.asmStmt.clobberedFields)
11622 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11624 if(field.expression)
11625 ProcessExpressionType(field.expression);
11632 PropertyWatch propWatch;
11633 OldList * watches = stmt._watch.watches;
11634 Expression object = stmt._watch.object;
11635 Expression watcher = stmt._watch.watcher;
11637 ProcessExpressionType(watcher);
11639 ProcessExpressionType(object);
11643 if(watcher || thisClass)
11645 External external = curExternal;
11646 Context context = curContext;
11648 stmt.type = expressionStmt;
11649 stmt.expressions = MkList();
11651 curExternal = external.prev;
11653 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11655 ClassFunction func;
11656 char watcherName[1024];
11657 Class watcherClass = watcher ?
11658 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11659 External createdExternal;
11661 // Create a declaration above
11662 External externalDecl = MkExternalDeclaration(null);
11663 ast->Insert(curExternal.prev, externalDecl);
11665 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11666 if(propWatch.deleteWatch)
11667 strcat(watcherName, "_delete");
11671 for(propID = propWatch.properties->first; propID; propID = propID.next)
11673 strcat(watcherName, "_");
11674 strcat(watcherName, propID.string);
11678 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11680 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11681 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11682 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11683 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11684 ProcessClassFunctionBody(func, propWatch.compound);
11685 propWatch.compound = null;
11687 //afterExternal = afterExternal ? afterExternal : curExternal;
11689 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11690 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11692 createdExternal.symbol.idCode = external.symbol.idCode;
11694 curExternal = createdExternal;
11695 ProcessFunction(createdExternal.function);
11698 // Create a declaration above
11700 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11701 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11702 externalDecl.declaration = decl;
11703 if(decl.symbol && !decl.symbol.pointerExternal)
11704 decl.symbol.pointerExternal = externalDecl;
11707 if(propWatch.deleteWatch)
11709 OldList * args = MkList();
11710 ListAdd(args, CopyExpression(object));
11711 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11712 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11713 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11717 Class _class = object.expType._class.registered;
11720 for(propID = propWatch.properties->first; propID; propID = propID.next)
11722 char propName[1024];
11723 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11726 char getName[1024], setName[1024];
11727 OldList * args = MkList();
11729 DeclareProperty(prop, setName, getName);
11731 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11732 strcpy(propName, "__ecereProp_");
11733 FullClassNameCat(propName, prop._class.fullName, false);
11734 strcat(propName, "_");
11735 // strcat(propName, prop.name);
11736 FullClassNameCat(propName, prop.name, true);
11738 ListAdd(args, CopyExpression(object));
11739 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11740 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11741 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11743 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11746 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11751 Compiler_Error($"Invalid watched object\n");
11754 curExternal = external;
11755 curContext = context;
11758 FreeExpression(watcher);
11760 FreeExpression(object);
11761 FreeList(watches, FreePropertyWatch);
11764 Compiler_Error($"No observer specified and not inside a _class\n");
11768 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11770 ProcessStatement(propWatch.compound);
11776 case fireWatchersStmt:
11778 OldList * watches = stmt._watch.watches;
11779 Expression object = stmt._watch.object;
11781 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11782 // printf("%X\n", watches);
11783 // printf("%X\n", stmt._watch.watches);
11785 ProcessExpressionType(object);
11790 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11796 stmt.type = expressionStmt;
11797 stmt.expressions = MkList();
11799 // Check if we're inside a property set
11800 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11802 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
11806 //Compiler_Error($"No property specified and not inside a property set\n");
11810 for(propID = watches->first; propID; propID = propID.next)
11812 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11815 CreateFireWatcher(prop, object, stmt);
11818 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
11823 // Fire all properties!
11826 for(base = _class; base; base = base.base)
11828 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
11830 if(prop.isProperty && prop.isWatchable)
11832 CreateFireWatcher(prop, object, stmt);
11839 FreeExpression(object);
11840 FreeList(watches, FreeIdentifier);
11843 Compiler_Error($"Invalid object specified and not inside a class\n");
11847 case stopWatchingStmt:
11849 OldList * watches = stmt._watch.watches;
11850 Expression object = stmt._watch.object;
11851 Expression watcher = stmt._watch.watcher;
11854 ProcessExpressionType(object);
11856 ProcessExpressionType(watcher);
11859 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
11861 if(watcher || thisClass)
11867 stmt.type = expressionStmt;
11868 stmt.expressions = MkList();
11873 // eInstance_StopWatching(object, null, watcher);
11875 ListAdd(args, CopyExpression(object));
11876 ListAdd(args, MkExpConstant("0"));
11877 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11878 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11882 for(propID = watches->first; propID; propID = propID.next)
11884 char propName[1024];
11885 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11888 char getName[1024], setName[1024];
11889 OldList * args = MkList();
11891 DeclareProperty(prop, setName, getName);
11893 // eInstance_StopWatching(object, prop, watcher);
11894 strcpy(propName, "__ecereProp_");
11895 FullClassNameCat(propName, prop._class.fullName, false);
11896 strcat(propName, "_");
11897 // strcat(propName, prop.name);
11898 FullClassNameCat(propName, prop.name, true);
11899 MangleClassName(propName);
11901 ListAdd(args, CopyExpression(object));
11902 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11903 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11904 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11907 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11912 FreeExpression(object);
11914 FreeExpression(watcher);
11915 FreeList(watches, FreeIdentifier);
11918 Compiler_Error($"Invalid object specified and not inside a class\n");
11921 Compiler_Error($"No observer specified and not inside a class\n");
11928 static void ProcessFunction(FunctionDefinition function)
11930 Identifier id = GetDeclId(function.declarator);
11931 Symbol symbol = function.declarator ? function.declarator.symbol : null;
11932 Type type = symbol ? symbol.type : null;
11933 Class oldThisClass = thisClass;
11934 Context oldTopContext = topContext;
11936 yylloc = function.loc;
11937 // Process thisClass
11939 if(type && type.thisClass)
11941 Symbol classSym = type.thisClass;
11942 Class _class = type.thisClass.registered;
11943 char className[1024];
11944 char structName[1024];
11945 Declarator funcDecl;
11948 bool typedObject = false;
11950 if(_class && !_class.base)
11952 _class = currentClass;
11953 if(_class && !_class.symbol)
11954 _class.symbol = FindClass(_class.fullName);
11955 classSym = _class ? _class.symbol : null;
11956 typedObject = true;
11959 thisClass = _class;
11961 if(inCompiler && _class)
11963 if(type.kind == functionType)
11965 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
11967 //TypeName param = symbol.type.params.first;
11968 Type param = symbol.type.params.first;
11969 symbol.type.params.Remove(param);
11970 //FreeTypeName(param);
11973 if(type.classObjectType != classPointer)
11975 symbol.type.params.Insert(null, MkClassType(_class.fullName));
11976 symbol.type.staticMethod = true;
11977 symbol.type.thisClass = null;
11979 // HIGH DANGER: VERIFYING THIS...
11980 symbol.type.extraParam = false;
11984 strcpy(className, "__ecereClass_");
11985 FullClassNameCat(className, _class.fullName, true);
11987 MangleClassName(className);
11990 FullClassNameCat(structName, _class.fullName, false);
11995 funcDecl = GetFuncDecl(function.declarator);
11998 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12000 TypeName param = funcDecl.function.parameters->first;
12001 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12003 funcDecl.function.parameters->Remove(param);
12004 FreeTypeName(param);
12008 // DANGER: Watch for this... Check if it's a Conversion?
12009 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12011 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12012 if(!function.propertyNoThis)
12014 TypeName thisParam;
12016 if(type.classObjectType != classPointer)
12018 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12019 if(!funcDecl.function.parameters)
12020 funcDecl.function.parameters = MkList();
12021 funcDecl.function.parameters->Insert(null, thisParam);
12026 if(type.classObjectType != classPointer)
12028 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12029 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12032 thisParam = TypeName
12034 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12035 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12037 funcDecl.function.parameters->Insert(null, thisParam);
12042 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12044 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12045 funcDecl = GetFuncDecl(initDecl.declarator);
12048 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12050 TypeName param = funcDecl.function.parameters->first;
12051 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12053 funcDecl.function.parameters->Remove(param);
12054 FreeTypeName(param);
12058 if(type.classObjectType != classPointer)
12060 // DANGER: Watch for this... Check if it's a Conversion?
12061 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12063 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12065 if(!funcDecl.function.parameters)
12066 funcDecl.function.parameters = MkList();
12067 funcDecl.function.parameters->Insert(null, thisParam);
12074 // Add this to the context
12077 if(type.classObjectType != classPointer)
12079 thisSymbol = Symbol
12081 string = CopyString("this");
12082 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12084 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12086 if(typedObject && thisSymbol.type)
12088 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12089 thisSymbol.type.byReference = type.byReference;
12090 thisSymbol.type.typedByReference = type.byReference;
12092 thisSymbol = Symbol { string = CopyString("class") };
12093 function.body.compound.context.symbols.Add(thisSymbol);
12099 // Pointer to class data
12101 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12103 DataMember member = null;
12106 for(base = _class; base && base.type != systemClass; base = base.next)
12108 for(member = base.membersAndProperties.first; member; member = member.next)
12109 if(!member.isProperty)
12115 for(member = _class.membersAndProperties.first; member; member = member.next)
12116 if(!member.isProperty)
12120 char pointerName[1024];
12123 Initializer initializer;
12124 Expression exp, bytePtr;
12126 strcpy(pointerName, "__ecerePointer_");
12127 FullClassNameCat(pointerName, _class.fullName, false);
12129 char className[1024];
12130 strcpy(className, "__ecereClass_");
12131 FullClassNameCat(className, classSym.string, true);
12132 MangleClassName(className);
12135 DeclareClass(classSym, className);
12139 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12144 sprintf(string, "%d", _class.offset);
12145 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12149 // ([bytePtr] + [className]->offset)
12150 exp = QBrackets(MkExpOp(bytePtr, '+',
12151 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12154 // (this ? [exp] : 0)
12155 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12159 kind = pointerType;
12160 type = Type { refCount = 1, kind = voidType };
12165 yylloc = function.body.loc;
12166 // ([structName] *) [exp]
12167 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12168 initializer = MkInitializerAssignment(
12169 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12171 // [structName] * [pointerName] = [initializer];
12172 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12175 Context prevContext = curContext;
12176 curContext = function.body.compound.context;
12178 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12179 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12181 curContext = prevContext;
12185 decl.symbol = null;
12187 if(!function.body.compound.declarations)
12188 function.body.compound.declarations = MkList();
12189 function.body.compound.declarations->Insert(null, decl);
12195 // Loop through the function and replace undeclared identifiers
12196 // which are a member of the class (methods, properties or data)
12197 // by "this.[member]"
12204 FreeSpecifier(id._class);
12207 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12209 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12210 id = GetDeclId(initDecl.declarator);
12212 FreeSpecifier(id._class);
12217 topContext = function.body.compound.context;
12219 FunctionDefinition oldFunction = curFunction;
12220 curFunction = function;
12222 ProcessStatement(function.body);
12224 // If this is a property set and no firewatchers has been done yet, add one here
12225 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12227 Statement prevCompound = curCompound;
12228 Context prevContext = curContext;
12230 Statement fireWatchers = MkFireWatchersStmt(null, null);
12231 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12232 ListAdd(function.body.compound.statements, fireWatchers);
12234 curCompound = function.body;
12235 curContext = function.body.compound.context;
12237 ProcessStatement(fireWatchers);
12239 curContext = prevContext;
12240 curCompound = prevCompound;
12244 curFunction = oldFunction;
12247 if(function.declarator)
12249 ProcessDeclarator(function.declarator);
12252 topContext = oldTopContext;
12253 thisClass = oldThisClass;
12256 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12257 static void ProcessClass(OldList definitions, Symbol symbol)
12260 External external = curExternal;
12261 Class regClass = symbol ? symbol.registered : null;
12263 // Process all functions
12264 for(def = definitions.first; def; def = def.next)
12266 if(def.type == functionClassDef)
12268 if(def.function.declarator)
12269 curExternal = def.function.declarator.symbol.pointerExternal;
12271 curExternal = external;
12273 ProcessFunction((FunctionDefinition)def.function);
12275 else if(def.type == declarationClassDef)
12277 if(def.decl.type == instDeclaration)
12279 thisClass = regClass;
12280 ProcessInstantiationType(def.decl.inst);
12286 Class backThisClass = thisClass;
12287 if(regClass) thisClass = regClass;
12288 ProcessDeclaration(def.decl);
12289 thisClass = backThisClass;
12292 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12294 MemberInit defProperty;
12296 // Add this to the context
12297 Symbol thisSymbol = Symbol
12299 string = CopyString("this");
12300 type = regClass ? MkClassType(regClass.fullName) : null;
12302 globalContext.symbols.Add((BTNode)thisSymbol);
12304 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12306 thisClass = regClass;
12307 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12311 globalContext.symbols.Remove((BTNode)thisSymbol);
12312 FreeSymbol(thisSymbol);
12314 else if(def.type == propertyClassDef && def.propertyDef)
12316 PropertyDef prop = def.propertyDef;
12318 // Add this to the context
12320 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12321 globalContext.symbols.Add(thisSymbol);
12324 thisClass = regClass;
12331 string = CopyString("this");
12332 type = MkClassType(regClass.fullName);
12334 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12337 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12338 ProcessStatement(prop.setStmt);
12346 string = CopyString("this");
12347 type = MkClassType(regClass.fullName);
12349 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12352 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12353 ProcessStatement(prop.getStmt);
12361 string = CopyString("this");
12362 type = MkClassType(regClass.fullName);
12364 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12367 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12368 ProcessStatement(prop.issetStmt);
12374 globalContext.symbols.Remove(thisSymbol);
12375 FreeSymbol(thisSymbol);
12378 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12380 PropertyWatch propertyWatch = def.propertyWatch;
12382 thisClass = regClass;
12383 if(propertyWatch.compound)
12387 string = CopyString("this");
12388 type = regClass ? MkClassType(regClass.fullName) : null;
12391 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12393 curExternal = null;
12394 ProcessStatement(propertyWatch.compound);
12401 void DeclareFunctionUtil(String s)
12403 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12408 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12409 strcpy(name, "__ecereFunction_");
12410 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12411 DeclareFunction(function, name);
12415 void ComputeDataTypes()
12419 External after = null;
12421 currentClass = null;
12423 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12425 for(external = ast->first; external; external = external.next)
12427 if(external.type == declarationExternal)
12429 Declaration decl = external.declaration;
12432 OldList * decls = decl.declarators;
12435 InitDeclarator initDecl = decls->first;
12438 Declarator declarator = initDecl.declarator;
12439 if(declarator && declarator.type == identifierDeclarator)
12441 Identifier id = declarator.identifier;
12442 if(id && id.string)
12444 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12446 external.symbol.id = -1001, external.symbol.idCode = -1001;
12457 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12458 ast->Insert(after, temp);
12459 curExternal = temp;
12461 DeclareFunctionUtil("eSystem_New");
12462 DeclareFunctionUtil("eSystem_New0");
12463 DeclareFunctionUtil("eSystem_Renew");
12464 DeclareFunctionUtil("eSystem_Renew0");
12465 DeclareFunctionUtil("eSystem_Delete");
12466 DeclareFunctionUtil("eClass_GetProperty");
12467 DeclareFunctionUtil("eInstance_FireSelfWatchers");
12469 DeclareStruct("ecere::com::Class", false);
12470 DeclareStruct("ecere::com::Instance", false);
12471 DeclareStruct("ecere::com::Property", false);
12472 DeclareStruct("ecere::com::DataMember", false);
12473 DeclareStruct("ecere::com::Method", false);
12474 DeclareStruct("ecere::com::SerialBuffer", false);
12475 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12479 for(external = ast->first; external; external = external.next)
12481 afterExternal = curExternal = external;
12482 if(external.type == functionExternal)
12484 currentClass = external.function._class;
12485 ProcessFunction(external.function);
12487 // There shouldn't be any _class member access here anyways...
12488 else if(external.type == declarationExternal)
12490 currentClass = null;
12491 ProcessDeclaration(external.declaration);
12493 else if(external.type == classExternal)
12495 ClassDefinition _class = external._class;
12496 currentClass = external.symbol.registered;
12497 if(_class.definitions)
12499 ProcessClass(_class.definitions, _class.symbol);
12503 // Free class data...
12504 ast->Remove(external);
12508 else if(external.type == nameSpaceExternal)
12510 thisNameSpace = external.id.string;
12513 currentClass = null;
12514 thisNameSpace = null;
12516 delete temp.symbol;