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.isConstant && exp.type == constantExp)
4202 if(exp.constant[0] == '\'')
4203 op.c = exp.constant[1];
4204 else if(type.isSigned)
4206 op.c = (char)strtol(exp.constant, null, 0);
4211 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4219 op.s = (short)strtol(exp.constant, null, 0);
4224 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4232 op.i = (int)strtol(exp.constant, null, 0);
4237 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4245 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4250 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4253 op.kind = int64Type;
4258 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4263 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4266 op.kind = int64Type;
4271 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4276 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4279 op.kind = int64Type;
4282 op.f = (float)strtod(exp.constant, null);
4286 op.d = (double)strtod(exp.constant, null);
4289 //case classType: For when we have operator overloading...
4290 // Pointer additions
4291 //case functionType:
4295 op.ui64 = _strtoui64(exp.constant, null, 0);
4296 op.kind = pointerType;
4306 static void UnusedFunction()
4309 a.OnGetString(0,0,0);
4312 extern int __ecereVMethodID_class_OnGetString;
4315 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4317 DataMember dataMember;
4318 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4320 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4321 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4325 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4327 void * ptr = inst.data + dataMember.offset + offset;
4328 char * result = null;
4329 exp.loc = member.loc = inst.loc;
4330 ((Identifier)member.identifiers->first).loc = inst.loc;
4332 if(!dataMember.dataType)
4333 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4334 type = dataMember.dataType;
4335 if(type.kind == classType)
4337 Class _class = type._class.registered;
4338 if(_class.type == enumClass)
4340 Class enumClass = eSystem_FindClass(privateModule, "enum");
4343 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4345 for(item = e.values.first; item; item = item.next)
4347 if((int)item.data == *(int *)ptr)
4355 exp.identifier = MkIdentifier(result);
4356 exp.type = identifierExp;
4357 exp.destType = MkClassType(_class.fullName);
4358 ProcessExpressionType(exp);
4362 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4364 if(!_class.dataType)
4365 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4366 type = _class.dataType;
4375 FreeExpContents(exp);
4377 exp.constant = PrintFloat(*(float*)ptr);
4378 exp.type = constantExp;
4383 FreeExpContents(exp);
4385 exp.constant = PrintDouble(*(double*)ptr);
4386 exp.type = constantExp;
4391 FreeExpContents(exp);
4393 exp.constant = PrintInt(*(int*)ptr);
4394 exp.type = constantExp;
4399 FreeExpContents(exp);
4401 exp.constant = PrintInt64(*(int64*)ptr);
4402 exp.type = constantExp;
4407 FreeExpContents(exp);
4408 // TODO: This should probably use proper type
4409 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4410 exp.type = constantExp;
4415 FreeExpContents(exp);
4416 // TODO: This should probably use proper type
4417 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4418 exp.type = constantExp;
4422 Compiler_Error($"Unhandled type populating instance\n");
4425 ListAdd(memberList, member);
4428 if(parentDataMember.type == unionMember)
4433 void PopulateInstance(Instantiation inst)
4435 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4436 Class _class = classSym.registered;
4437 DataMember dataMember;
4438 OldList * memberList = MkList();
4439 // Added this check and ->Add to prevent memory leaks on bad code
4441 inst.members = MkListOne(MkMembersInitList(memberList));
4443 inst.members->Add(MkMembersInitList(memberList));
4444 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4446 if(!dataMember.isProperty)
4448 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4449 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4453 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4455 void * ptr = inst.data + dataMember.offset;
4456 char * result = null;
4458 exp.loc = member.loc = inst.loc;
4459 ((Identifier)member.identifiers->first).loc = inst.loc;
4461 if(!dataMember.dataType)
4462 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4463 type = dataMember.dataType;
4464 if(type.kind == classType)
4466 Class _class = type._class.registered;
4467 if(_class.type == enumClass)
4469 Class enumClass = eSystem_FindClass(privateModule, "enum");
4472 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4474 for(item = e.values.first; item; item = item.next)
4476 if((int)item.data == *(int *)ptr)
4485 exp.identifier = MkIdentifier(result);
4486 exp.type = identifierExp;
4487 exp.destType = MkClassType(_class.fullName);
4488 ProcessExpressionType(exp);
4491 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4493 if(!_class.dataType)
4494 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4495 type = _class.dataType;
4504 exp.constant = PrintFloat(*(float*)ptr);
4505 exp.type = constantExp;
4510 exp.constant = PrintDouble(*(double*)ptr);
4511 exp.type = constantExp;
4516 exp.constant = PrintInt(*(int*)ptr);
4517 exp.type = constantExp;
4522 exp.constant = PrintInt64(*(int64*)ptr);
4523 exp.type = constantExp;
4528 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4529 exp.type = constantExp;
4533 Compiler_Error($"Unhandled type populating instance\n");
4536 ListAdd(memberList, member);
4542 void ComputeInstantiation(Expression exp)
4544 Instantiation inst = exp.instance;
4545 MembersInit members;
4546 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4547 Class _class = classSym ? classSym.registered : null;
4548 DataMember curMember = null;
4549 Class curClass = null;
4550 DataMember subMemberStack[256];
4551 int subMemberStackPos = 0;
4554 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4556 // Don't recompute the instantiation...
4557 // Non Simple classes will have become constants by now
4561 if(_class.type == normalClass || _class.type == noHeadClass)
4563 inst.data = (byte *)eInstance_New(_class);
4564 if(_class.type == normalClass)
4565 ((Instance)inst.data)._refCount++;
4568 inst.data = new0 byte[_class.structSize];
4573 for(members = inst.members->first; members; members = members.next)
4575 switch(members.type)
4577 case dataMembersInit:
4579 if(members.dataMembers)
4582 for(member = members.dataMembers->first; member; member = member.next)
4584 Identifier ident = member.identifiers ? member.identifiers->first : null;
4587 Property prop = null;
4588 DataMember dataMember = null;
4589 Method method = null;
4590 uint dataMemberOffset;
4594 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4597 if(curMember.isProperty)
4598 prop = (Property)curMember;
4601 dataMember = curMember;
4603 // CHANGED THIS HERE
4604 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4606 // 2013/17/29 -- It seems that this was missing here!
4607 if(_class.type == normalClass)
4608 dataMemberOffset += _class.base.structSize;
4609 // dataMemberOffset = dataMember.offset;
4616 prop = eClass_FindProperty(_class, ident.string, privateModule);
4620 if(prop.memberAccess == publicAccess)
4622 curMember = (DataMember)prop;
4623 curClass = prop._class;
4628 DataMember _subMemberStack[256];
4629 int _subMemberStackPos = 0;
4631 // FILL MEMBER STACK
4632 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4637 if(dataMember.memberAccess == publicAccess)
4639 curMember = dataMember;
4640 curClass = dataMember._class;
4641 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4642 subMemberStackPos = _subMemberStackPos;
4648 if(found && member.initializer && member.initializer.type == expInitializer)
4650 Expression value = member.initializer.exp;
4652 bool deepMember = false;
4655 type = prop.dataType;
4659 if(!dataMember.dataType)
4660 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4662 type = dataMember.dataType;
4665 if(ident && ident.next)
4669 // for(; ident && type; ident = ident.next)
4670 for(ident = ident.next; ident && type; ident = ident.next)
4672 if(type.kind == classType)
4674 prop = eClass_FindProperty(type._class.registered,
4675 ident.string, privateModule);
4677 type = prop.dataType;
4680 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4681 ident.string, &dataMemberOffset, privateModule, null, null);
4683 type = dataMember.dataType;
4686 else if(type.kind == structType || type.kind == unionType)
4689 for(memberType = type.members.first; memberType; memberType = memberType.next)
4691 if(!strcmp(memberType.name, ident.string))
4702 FreeType(value.destType);
4703 value.destType = type;
4704 if(type) type.refCount++;
4705 ComputeExpression(value);
4707 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4709 if(type.kind == classType)
4711 Class _class = type._class.registered;
4712 if(_class.type == bitClass || _class.type == unitClass ||
4713 _class.type == enumClass)
4715 if(!_class.dataType)
4716 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4717 type = _class.dataType;
4723 void * ptr = inst.data + dataMemberOffset;
4725 if(value.type == constantExp)
4731 GetInt(value, (int*)ptr);
4736 GetInt64(value, (int64*)ptr);
4741 GetIntPtr(value, (intptr*)ptr);
4746 GetIntSize(value, (intsize*)ptr);
4751 GetFloat(value, (float*)ptr);
4756 GetDouble(value, (double *)ptr);
4761 else if(value.type == instanceExp)
4763 if(type.kind == classType)
4765 Class _class = type._class.registered;
4766 if(_class.type == structClass)
4768 ComputeTypeSize(type);
4769 if(value.instance.data)
4770 memcpy(ptr, value.instance.data, type.size);
4777 if(value.type == instanceExp && value.instance.data)
4779 if(type.kind == classType)
4781 Class _class = type._class.registered;
4782 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
4784 void (*Set)(void *, void *) = (void *)prop.Set;
4785 Set(inst.data, value.instance.data);
4786 PopulateInstance(inst);
4790 else if(value.type == constantExp)
4796 void (*Set)(void *, double) = (void *)prop.Set;
4797 Set(inst.data, strtod(value.constant, null) );
4802 void (*Set)(void *, float) = (void *)prop.Set;
4803 Set(inst.data, (float)(strtod(value.constant, null)));
4808 void (*Set)(void *, int) = (void *)prop.Set;
4809 Set(inst.data, (int)strtol(value.constant, null, 0));
4814 void (*Set)(void *, int64) = (void *)prop.Set;
4815 Set(inst.data, _strtoi64(value.constant, null, 0));
4820 void (*Set)(void *, intptr) = (void *)prop.Set;
4821 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
4826 void (*Set)(void *, intsize) = (void *)prop.Set;
4827 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
4832 else if(value.type == stringExp)
4835 ReadString(temp, value.string);
4836 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
4840 else if(!deepMember && type && _class.type == unitClass)
4844 // Only support converting units to units for now...
4845 if(value.type == constantExp)
4847 if(type.kind == classType)
4849 Class _class = type._class.registered;
4850 if(_class.type == unitClass)
4852 if(!_class.dataType)
4853 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4854 type = _class.dataType;
4857 // TODO: Assuming same base type for units...
4863 float (*Set)(float) = (void *)prop.Set;
4864 GetFloat(member.initializer.exp, &fValue);
4865 exp.constant = PrintFloat(Set(fValue));
4866 exp.type = constantExp;
4872 double (*Set)(double) = (void *)prop.Set;
4873 GetDouble(member.initializer.exp, &dValue);
4874 exp.constant = PrintDouble(Set(dValue));
4875 exp.type = constantExp;
4882 else if(!deepMember && type && _class.type == bitClass)
4886 if(value.type == instanceExp && value.instance.data)
4888 unsigned int (*Set)(void *) = (void *)prop.Set;
4889 bits = Set(value.instance.data);
4891 else if(value.type == constantExp)
4897 BitMember bitMember = (BitMember) dataMember;
4900 GetInt(value, &part);
4901 bits = (bits & ~bitMember.mask);
4902 if(!bitMember.dataType)
4903 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
4905 type = bitMember.dataType;
4907 if(type.kind == classType && type._class && type._class.registered)
4909 if(!type._class.registered.dataType)
4910 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4911 type = type._class.registered.dataType;
4919 bits |= ((char)part << bitMember.pos);
4921 bits |= ((unsigned char)part << bitMember.pos);
4925 bits |= ((short)part << bitMember.pos);
4927 bits |= ((unsigned short)part << bitMember.pos);
4932 bits |= ((int)part << bitMember.pos);
4934 bits |= ((unsigned int)part << bitMember.pos);
4938 bits |= ((int64)part << bitMember.pos);
4940 bits |= ((uint64)part << bitMember.pos);
4945 bits |= ((intptr)part << bitMember.pos);
4949 bits |= ((uintptr)part << bitMember.pos);
4955 bits |= ((ssize_t)(intsize)part << bitMember.pos);
4959 bits |= ((size_t) (uintsize)part << bitMember.pos);
4968 if(_class && _class.type == unitClass)
4970 ComputeExpression(member.initializer.exp);
4971 exp.constant = member.initializer.exp.constant;
4972 exp.type = constantExp;
4974 member.initializer.exp.constant = null;
4984 if(_class && _class.type == bitClass)
4986 exp.constant = PrintHexUInt(bits);
4987 exp.type = constantExp;
4989 if(exp.type != instanceExp)
4995 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
4997 if(exp.op.op == SIZEOF)
4999 FreeExpContents(exp);
5000 exp.type = constantExp;
5001 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5012 // Provide default unary +
5013 Expression exp2 = exp.op.exp2;
5015 FreeExpContents(exp);
5016 FreeType(exp.expType);
5017 FreeType(exp.destType);
5023 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5025 // unary arithmetic increment and decrement
5026 //OPERATOR_ALL(UNARY, ++, Inc)
5027 //OPERATOR_ALL(UNARY, --, Dec)
5030 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5032 // unary logical negation
5034 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5042 // binary arithmetic
5044 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5047 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5050 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5053 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5056 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5058 // binary arithmetic assignment
5059 //OPERATOR_ALL(BINARY, =, Asign)
5060 //OPERATOR_ALL(BINARY, +=, AddAsign)
5061 //OPERATOR_ALL(BINARY, -=, SubAsign)
5062 //OPERATOR_ALL(BINARY, *=, MulAsign)
5063 //OPERATOR_ALL(BINARY, /=, DivAsign)
5064 //OPERATOR_ALL(BINARY, %=, ModAsign)
5069 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5073 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5076 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5079 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5082 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5084 // binary bitwise assignment
5085 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5086 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5087 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5088 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5089 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5090 // binary logical equality
5092 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5095 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5099 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5102 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5104 // binary logical relational
5106 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5109 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5112 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5115 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5122 void ComputeExpression(Expression exp)
5124 char expString[10240];
5125 expString[0] = '\0';
5127 PrintExpression(exp, expString);
5134 ComputeInstantiation(exp);
5143 Expression exp1, exp2 = null;
5147 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5149 ComputeExpression(exp.op.exp2);
5152 ComputeExpression(exp.op.exp1);
5155 op1 = GetOperand(exp1);
5156 if(op1.type) op1.type.refCount++;
5159 op2 = GetOperand(exp2);
5160 if(op2.type) op2.type.refCount++;
5166 op1 = GetOperand(exp1);
5167 if(op1.type) op1.type.refCount++;
5170 CallOperator(exp, exp1, exp2, op1, op2);
5177 if(exp.op.exp1 && exp.op.exp2)
5182 FreeExpContents(exp);
5183 op1.ops.BitAnd(exp, op1, op2);
5192 FreeExpContents(exp);
5193 op1.ops.Mul(exp, op1, op2);
5202 FreeExpContents(exp);
5203 op1.ops.Add(exp, op1, op2);
5208 // Provide default unary +
5209 Expression exp2 = exp.op.exp2;
5211 FreeExpContents(exp);
5212 FreeType(exp.expType);
5213 FreeType(exp.destType);
5224 FreeExpContents(exp);
5225 op1.ops.Sub(exp, op1, op2);
5232 FreeExpContents(exp);
5233 op1.ops.Neg(exp, op1);
5240 FreeExpContents(exp);
5241 op1.ops.BitNot(exp, op1);
5247 FreeExpContents(exp);
5248 op1.ops.Not(exp, op1);
5251 // Binary only operators
5255 FreeExpContents(exp);
5256 op1.ops.Div(exp, op1, op2);
5262 FreeExpContents(exp);
5263 op1.ops.Mod(exp, op1, op2);
5275 FreeExpContents(exp);
5276 op1.ops.Sma(exp, op1, op2);
5285 FreeExpContents(exp);
5286 op1.ops.Grt(exp, op1, op2);
5295 FreeExpContents(exp);
5296 op1.ops.SmaEqu(exp, op1, op2);
5305 FreeExpContents(exp);
5306 op1.ops.GrtEqu(exp, op1, op2);
5315 FreeExpContents(exp);
5316 op1.ops.Equ(exp, op1, op2);
5325 FreeExpContents(exp);
5326 op1.ops.Nqu(exp, op1, op2);
5333 FreeExpContents(exp);
5334 op1.ops.BitOr(exp, op1, op2);
5340 FreeExpContents(exp);
5341 op1.ops.BitXor(exp, op1, op2);
5349 FreeExpContents(exp);
5350 exp.type = constantExp;
5351 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5355 if(op1.type) FreeType(op1.type);
5356 if(op2.type) FreeType(op2.type);
5360 case extensionExpressionExp:
5363 for(e = exp.list->first; e; e = n)
5368 OldList * list = exp.list;
5369 ComputeExpression(e);
5370 //FreeExpContents(exp);
5371 FreeType(exp.expType);
5372 FreeType(exp.destType);
5389 exp.isConstant = true;
5391 ComputeExpression(exp.index.exp);
5392 if(!exp.index.exp.isConstant)
5393 exp.isConstant = false;
5395 for(e = exp.index.index->first; e; e = e.next)
5397 ComputeExpression(e);
5400 // Check if this type is int
5403 exp.isConstant = false;
5405 exp.expType = Dereference(exp.index.exp.expType);
5411 Expression memberExp = exp.member.exp;
5412 Identifier memberID = exp.member.member;
5415 ComputeExpression(exp.member.exp);
5416 type = exp.member.exp.expType;
5419 Class _class = (exp.member.member && exp.member.member.classSym) ? exp.member.member.classSym.registered : (((type.kind == classType || type.kind == subClassType) && type._class) ? type._class.registered : null);
5420 Property prop = null;
5421 DataMember member = null;
5422 Class convertTo = null;
5423 if(type.kind == subClassType && exp.member.exp.type == classExp)
5424 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5431 PrintTypeNoConst(type, string, false, true);
5432 classSym = FindClass(string);
5433 _class = classSym ? classSym.registered : null;
5436 if(exp.member.member)
5438 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5440 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5442 if(!prop && !member && _class && exp.member.member)
5444 Symbol classSym = FindClass(exp.member.member.string);
5446 _class = classSym ? classSym.registered : null;
5447 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5454 Type type = prop.dataType;
5455 // TODO: Assuming same base type for units...
5456 if(_class.type == unitClass)
5458 if(type.kind == classType)
5460 Class _class = type._class.registered;
5461 if(_class.type == unitClass)
5463 if(!_class.dataType)
5464 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5465 type = _class.dataType;
5473 float (*Get)(float) = (void *)prop.Get;
5474 GetFloat(exp.member.exp, &value);
5475 exp.constant = PrintFloat(Get ? Get(value) : value);
5476 exp.type = constantExp;
5482 double (*Get)(double);
5483 GetDouble(exp.member.exp, &value);
5486 Get = (void *)prop.Set;
5488 Get = (void *)prop.Get;
5489 exp.constant = PrintDouble(Get ? Get(value) : value);
5490 exp.type = constantExp;
5499 Expression value = exp.member.exp;
5502 ProcessPropertyType(prop);
5504 type = prop.dataType;
5507 // printf("Investigate this\n");
5509 else if(_class.type == structClass)
5515 Class propertyClass = type._class.registered;
5516 if(propertyClass.type == structClass && value.type == instanceExp)
5518 void (*Set)(void *, void *) = (void *)prop.Set;
5519 exp.instance = Instantiation { };
5520 exp.instance.data = new0 byte[_class.structSize];
5521 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5522 exp.instance.loc = exp.loc;
5523 exp.type = instanceExp;
5524 Set(exp.instance.data, value.instance.data);
5525 PopulateInstance(exp.instance);
5532 void (*Set)(void *, int) = (void *)prop.Set;
5534 exp.instance = Instantiation { };
5535 exp.instance.data = new0 byte[_class.structSize];
5536 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5537 exp.instance.loc = exp.loc;
5538 exp.type = instanceExp;
5540 GetInt(value, &intValue);
5542 Set(exp.instance.data, intValue);
5543 PopulateInstance(exp.instance);
5549 void (*Set)(void *, int64) = (void *)prop.Set;
5551 exp.instance = Instantiation { };
5552 exp.instance.data = new0 byte[_class.structSize];
5553 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5554 exp.instance.loc = exp.loc;
5555 exp.type = instanceExp;
5557 GetInt64(value, &intValue);
5559 Set(exp.instance.data, intValue);
5560 PopulateInstance(exp.instance);
5567 void (*Set)(void *, intptr) = (void *)prop.Set;
5569 exp.instance = Instantiation { };
5570 exp.instance.data = new0 byte[_class.structSize];
5571 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5572 exp.instance.loc = exp.loc;
5573 exp.type = instanceExp;
5575 GetIntPtr(value, &intValue);
5577 Set(exp.instance.data, intValue);
5578 PopulateInstance(exp.instance);
5585 void (*Set)(void *, intsize) = (void *)prop.Set;
5587 exp.instance = Instantiation { };
5588 exp.instance.data = new0 byte[_class.structSize];
5589 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5590 exp.instance.loc = exp.loc;
5591 exp.type = instanceExp;
5593 GetIntSize(value, &intValue);
5595 Set(exp.instance.data, intValue);
5596 PopulateInstance(exp.instance);
5602 void (*Set)(void *, double) = (void *)prop.Set;
5604 exp.instance = Instantiation { };
5605 exp.instance.data = new0 byte[_class.structSize];
5606 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5607 exp.instance.loc = exp.loc;
5608 exp.type = instanceExp;
5610 GetDouble(value, &doubleValue);
5612 Set(exp.instance.data, doubleValue);
5613 PopulateInstance(exp.instance);
5618 else if(_class.type == bitClass)
5624 Class propertyClass = type._class.registered;
5625 if(propertyClass.type == structClass && value.instance.data)
5627 unsigned int (*Set)(void *) = (void *)prop.Set;
5628 unsigned int bits = Set(value.instance.data);
5629 exp.constant = PrintHexUInt(bits);
5630 exp.type = constantExp;
5633 else if(_class.type == bitClass)
5636 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5639 GetUInt(exp.member.exp, &value);
5641 exp.constant = PrintHexUInt(bits);
5642 exp.type = constantExp;
5650 if(_class.type == bitClass)
5653 GetUInt(exp.member.exp, &value);
5659 Class _class = type._class.registered;
5660 if(_class.type == structClass)
5662 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5664 exp.instance = Instantiation { };
5665 exp.instance.data = new0 byte[_class.structSize];
5666 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5667 exp.instance.loc = exp.loc;
5668 //exp.instance.fullSet = true;
5669 exp.type = instanceExp;
5670 Get(value, exp.instance.data);
5671 PopulateInstance(exp.instance);
5673 else if(_class.type == bitClass)
5675 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5676 uint64 bits = Get(value);
5677 exp.constant = PrintHexUInt64(bits);
5678 exp.type = constantExp;
5684 else if(_class.type == structClass)
5686 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5691 Class _class = type._class.registered;
5692 if(_class.type == structClass && value)
5694 void (*Get)(void *, void *) = (void *)prop.Get;
5696 exp.instance = Instantiation { };
5697 exp.instance.data = new0 byte[_class.structSize];
5698 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5699 exp.instance.loc = exp.loc;
5700 //exp.instance.fullSet = true;
5701 exp.type = instanceExp;
5702 Get(value, exp.instance.data);
5703 PopulateInstance(exp.instance);
5711 char * value = exp.member.exp.instance.data;
5716 Class _class = type._class.registered;
5717 if(_class.type == normalClass)
5719 void *(*Get)(void *) = (void *)prop.Get;
5721 exp.instance = Instantiation { };
5722 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
5723 exp.type = instanceExp;
5724 exp.instance.data = Get(value, exp.instance.data);
5736 exp.isConstant = false;
5744 if(exp.type != ExpressionType::memberExp)
5746 FreeExpression(memberExp);
5747 FreeIdentifier(memberID);
5753 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
5754 FreeExpContents(exp);
5755 exp.constant = PrintUInt(ComputeTypeSize(type));
5756 exp.type = constantExp;
5762 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
5763 if(classSym && classSym.registered)
5765 if(classSym.registered.fixed)
5767 FreeSpecifier(exp._class);
5768 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
5769 exp.type = constantExp;
5773 char className[1024];
5774 strcpy(className, "__ecereClass_");
5775 FullClassNameCat(className, classSym.string, true);
5776 MangleClassName(className);
5778 DeclareClass(classSym, className);
5780 FreeExpContents(exp);
5781 exp.type = pointerExp;
5782 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
5783 exp.member.member = MkIdentifier("structSize");
5793 if(exp.type == castExp)
5796 ComputeExpression(exp.cast.exp);
5799 if(e && exp.expType)
5802 type = exp.destType;
5805 if(type.kind == classType)
5807 Class _class = type._class.registered;
5808 if(_class && (_class.type == unitClass || _class.type == bitClass))
5810 if(!_class.dataType)
5811 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5812 type = _class.dataType;
5824 FreeExpContents(exp);
5825 exp.constant = PrintChar(value);
5826 exp.type = constantExp;
5830 unsigned char value;
5831 GetUChar(e, &value);
5832 FreeExpContents(exp);
5833 exp.constant = PrintUChar(value);
5834 exp.type = constantExp;
5841 GetShort(e, &value);
5842 FreeExpContents(exp);
5843 exp.constant = PrintShort(value);
5844 exp.type = constantExp;
5848 unsigned short value;
5849 GetUShort(e, &value);
5850 FreeExpContents(exp);
5851 exp.constant = PrintUShort(value);
5852 exp.type = constantExp;
5860 FreeExpContents(exp);
5861 exp.constant = PrintInt(value);
5862 exp.type = constantExp;
5868 FreeExpContents(exp);
5869 exp.constant = PrintUInt(value);
5870 exp.type = constantExp;
5877 GetInt64(e, &value);
5878 FreeExpContents(exp);
5879 exp.constant = PrintInt64(value);
5880 exp.type = constantExp;
5885 GetUInt64(e, &value);
5886 FreeExpContents(exp);
5887 exp.constant = PrintUInt64(value);
5888 exp.type = constantExp;
5895 GetIntPtr(e, &value);
5896 FreeExpContents(exp);
5897 exp.constant = PrintInt64((int64)value);
5898 exp.type = constantExp;
5903 GetUIntPtr(e, &value);
5904 FreeExpContents(exp);
5905 exp.constant = PrintUInt64((uint64)value);
5906 exp.type = constantExp;
5913 GetIntSize(e, &value);
5914 FreeExpContents(exp);
5915 exp.constant = PrintInt64((int64)value);
5916 exp.type = constantExp;
5921 GetUIntSize(e, &value);
5922 FreeExpContents(exp);
5923 exp.constant = PrintUInt64((uint64)value);
5924 exp.type = constantExp;
5930 GetFloat(e, &value);
5931 FreeExpContents(exp);
5932 exp.constant = PrintFloat(value);
5933 exp.type = constantExp;
5939 GetDouble(e, &value);
5940 FreeExpContents(exp);
5941 exp.constant = PrintDouble(value);
5942 exp.type = constantExp;
5956 // Caring only about last expression for now...
5957 ComputeExpression(exp.cond.exp->last);
5958 if(exp.cond.elseExp)
5959 ComputeExpression(exp.cond.elseExp);
5961 ComputeExpression(exp.cond.cond);
5963 op1 = GetOperand(exp.cond.cond);
5964 if(op1.type) op1.type.refCount++;
5965 op2 = GetOperand(exp.cond.exp->last);
5966 if(op2.type) op2.type.refCount++;
5967 op3 = GetOperand(exp.cond.elseExp);
5968 if(op3.type) op3.type.refCount++;
5970 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
5971 if(op1.type) FreeType(op1.type);
5972 if(op2.type) FreeType(op2.type);
5973 if(op3.type) FreeType(op3.type);
5979 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
5984 OldList converts { };
5987 if(destType.kind == voidType)
5990 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
5994 // for(convert = converts.last; convert; convert = convert.prev)
5995 for(convert = converts.first; convert; convert = convert.next)
5997 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6000 Expression newExp { };
6001 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6003 // TODO: Check this...
6005 newExp.destType = null;
6010 exp.type = memberExp;
6011 exp.addedThis = true;
6012 exp.member.exp = newExp;
6013 FreeType(exp.member.exp.expType);
6015 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6016 exp.member.exp.expType.classObjectType = objectType;
6017 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6018 exp.member.memberType = propertyMember;
6019 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6020 // TESTING THIS... for (int)degrees
6021 exp.needCast = true;
6022 if(exp.expType) exp.expType.refCount++;
6023 ApplyAnyObjectLogic(exp.member.exp);
6028 /*if(exp.isConstant)
6030 // Color { ColorRGB = [exp] };
6031 exp.type = instanceExp;
6032 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6033 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6034 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6038 // If not constant, don't turn it yet into an instantiation
6039 // (Go through the deep members system first)
6040 exp.type = memberExp;
6041 exp.addedThis = true;
6042 exp.member.exp = newExp;
6044 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6045 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6046 newExp.expType._class.registered.type == noHeadClass)
6048 newExp.byReference = true;
6051 FreeType(exp.member.exp.expType);
6052 /*exp.member.exp.expType = convert.convert.dataType;
6053 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6054 exp.member.exp.expType = null;
6055 if(convert.convert.dataType)
6057 exp.member.exp.expType = { };
6058 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6059 exp.member.exp.expType.refCount = 1;
6060 exp.member.exp.expType.classObjectType = objectType;
6061 ApplyAnyObjectLogic(exp.member.exp);
6064 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6065 exp.member.memberType = reverseConversionMember;
6066 exp.expType = convert.resultType ? convert.resultType :
6067 MkClassType(convert.convert._class.fullName);
6068 exp.needCast = true;
6069 if(convert.resultType) convert.resultType.refCount++;
6075 FreeType(exp.expType);
6078 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6079 exp.needCast = true;
6080 if(exp.expType) exp.expType.refCount++;
6084 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6085 exp.needCast = true;
6086 if(convert.resultType)
6087 convert.resultType.refCount++;
6091 if(exp.isConstant && inCompiler)
6092 ComputeExpression(exp);
6094 converts.Free(FreeConvert);
6097 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6099 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6101 if(!result && exp.expType && exp.destType)
6103 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6104 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6105 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6106 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6110 // if(result) CheckTemplateTypes(exp);
6114 void CheckTemplateTypes(Expression exp)
6116 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6118 Expression newExp { };
6122 if(exp.destType) exp.destType.refCount++;
6123 if(exp.expType) exp.expType.refCount++;
6127 switch(exp.expType.kind)
6130 if(exp.destType.classObjectType)
6132 // We need to pass the address, just pass it along (Undo what was done above)
6133 if(exp.destType) exp.destType.refCount--;
6134 if(exp.expType) exp.expType.refCount--;
6139 // If we're looking for value:
6140 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6142 OldList * unionDefs = MkList();
6143 OldList * statements = MkList();
6144 context = PushContext();
6145 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6146 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6147 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6148 exp.type = extensionCompoundExp;
6149 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6150 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6151 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6152 exp.compound.compound.context = context;
6153 PopContext(context);
6158 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6159 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6163 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6165 Expression newExp { };
6169 if(exp.destType) exp.destType.refCount++;
6170 if(exp.expType) exp.expType.refCount++;
6174 switch(exp.expType.kind)
6177 if(exp.destType.classObjectType)
6179 // We need to pass the address, just pass it along (Undo what was done above)
6180 if(exp.destType) exp.destType.refCount--;
6181 if(exp.expType) exp.expType.refCount--;
6186 // If we're looking for value:
6187 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6189 OldList * unionDefs = MkList();
6190 OldList * statements = MkList();
6191 context = PushContext();
6192 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6193 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6194 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6195 exp.type = extensionCompoundExp;
6196 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6197 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6198 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6199 exp.compound.compound.context = context;
6200 PopContext(context);
6205 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6207 exp.type = bracketsExp;
6208 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6209 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6210 ProcessExpressionType(exp.list->first);
6215 exp.type = bracketsExp;
6216 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6217 newExp.needCast = true;
6218 ProcessExpressionType(exp.list->first);
6224 if(exp.expType.kind == templateType)
6226 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6229 FreeType(exp.destType);
6230 FreeType(exp.expType);
6235 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6240 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6241 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6245 char typeString[1024];
6247 OldList * specs = MkList();
6248 typeString[0] = '\0';
6249 PrintType(exp.expType, typeString, false, false);
6250 decl = SpecDeclFromString(typeString, specs, null);
6253 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6254 exp.cast.typeName = MkTypeName(specs, decl);
6255 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6256 exp.cast.exp.needCast = true;
6263 // TODO: The Symbol tree should be reorganized by namespaces
6265 // - Tree of all symbols within (stored without namespace)
6266 // - Tree of sub-namespaces
6268 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6270 int nsLen = strlen(nameSpace);
6272 // Start at the name space prefix
6273 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6275 char * s = symbol.string;
6276 if(!strncmp(s, nameSpace, nsLen))
6278 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6281 for(c = strlen(s)-1; c >= 0; c--)
6286 if(!strcmp(namePart, name))
6288 // TODO: Error on ambiguity
6298 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6301 char nameSpace[1024];
6303 bool gotColon = false;
6305 nameSpace[0] = '\0';
6306 for(c = strlen(name)-1; c >= 0; c--)
6313 namePart = name+c+1;
6314 while(c >= 0 && name[c] == ':') c--;
6317 // Try an exact match first
6318 Symbol symbol = (Symbol)tree.FindString(name);
6322 // Namespace specified
6323 memcpy(nameSpace, name, c + 1);
6326 return ScanWithNameSpace(tree, nameSpace, namePart);
6330 // Looking for a global symbol, e.g. ::Sleep()
6331 Symbol symbol = (Symbol)tree.FindString(namePart);
6336 // Name only (no namespace specified)
6337 Symbol symbol = (Symbol)tree.FindString(namePart);
6340 return ScanWithNameSpace(tree, "", namePart);
6345 static void ProcessDeclaration(Declaration decl);
6347 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6350 //Time startTime = GetTime();
6352 // Optimize this later? Do this before/less?
6354 Symbol symbol = null;
6355 // First, check if the identifier is declared inside the function
6356 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6358 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6360 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6366 strcpy(curName, thisNameSpace);
6367 strcat(curName, "::");
6368 strcat(curName, name);
6369 // Try to resolve in current namespace first
6370 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6373 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6376 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6378 if(symbol || ctx == endContext) break;
6380 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6382 if(symbol.pointerExternal.type == functionExternal)
6384 FunctionDefinition function = symbol.pointerExternal.function;
6386 // Modified this recently...
6387 Context tmpContext = curContext;
6389 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6390 curContext = tmpContext;
6392 symbol.pointerExternal.symbol = symbol;
6395 DeclareType(symbol.type, true, true);
6397 ast->Insert(curExternal.prev, symbol.pointerExternal);
6399 symbol.id = curExternal.symbol.idCode;
6402 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6404 ast->Move(symbol.pointerExternal, curExternal.prev);
6405 symbol.id = curExternal.symbol.idCode;
6409 //findSymbolTotalTime += GetTime() - startTime;
6414 static void GetTypeSpecs(Type type, OldList * specs)
6416 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6421 if(type._class.registered)
6423 if(!type._class.registered.dataType)
6424 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6425 GetTypeSpecs(type._class.registered.dataType, specs);
6429 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6430 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6431 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6432 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6433 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6434 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6435 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6436 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6439 ListAdd(specs, MkSpecifier(INT)); break;
6443 static void PrintArraySize(Type arrayType, char * string)
6448 if(arrayType.enumClass)
6449 strcat(size, arrayType.enumClass.string);
6450 else if(arrayType.arraySizeExp)
6451 PrintExpression(arrayType.arraySizeExp, size);
6453 strcat(string, size);
6456 // WARNING : This function expects a null terminated string since it recursively concatenate...
6457 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6461 if(printConst && type.constant)
6462 strcat(string, "const ");
6467 Symbol c = type._class;
6468 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6469 // look into merging with thisclass ?
6470 if(type.classObjectType == typedObject)
6471 strcat(string, "typed_object");
6472 else if(type.classObjectType == anyObject)
6473 strcat(string, "any_object");
6477 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6479 if(type.byReference)
6480 strcat(string, " &");
6483 case voidType: strcat(string, "void"); break;
6484 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6485 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6486 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6487 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6488 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6489 case _BoolType: strcat(string, "_Bool"); break;
6490 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6491 case floatType: strcat(string, "float"); break;
6492 case doubleType: strcat(string, "double"); break;
6496 strcat(string, "struct ");
6497 strcat(string, type.enumName);
6499 else if(type.typeName)
6500 strcat(string, type.typeName);
6504 strcat(string, "struct { ");
6505 for(member = type.members.first; member; member = member.next)
6507 PrintType(member, string, true, fullName);
6508 strcat(string,"; ");
6516 strcat(string, "union ");
6517 strcat(string, type.enumName);
6519 else if(type.typeName)
6520 strcat(string, type.typeName);
6523 strcat(string, "union ");
6524 strcat(string,"(unnamed)");
6530 strcat(string, "enum ");
6531 strcat(string, type.enumName);
6533 else if(type.typeName)
6534 strcat(string, type.typeName);
6536 strcat(string, "int"); // "enum");
6539 strcat(string, "...");
6542 strcat(string, "subclass(");
6543 strcat(string, type._class ? type._class.string : "int");
6544 strcat(string, ")");
6547 strcat(string, type.templateParameter.identifier.string);
6550 strcat(string, "thisclass");
6553 strcat(string, "__builtin_va_list");
6559 static void PrintName(Type type, char * string, bool fullName)
6561 if(type.name && type.name[0])
6564 strcat(string, type.name);
6567 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6568 if(name) name += 2; else name = type.name;
6569 strcat(string, name);
6574 static void PrintAttribs(Type type, char * string)
6578 if(type.dllExport) strcat(string, "dllexport ");
6579 if(type.attrStdcall) strcat(string, "stdcall ");
6583 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
6585 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6587 Type attrType = null;
6588 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
6589 PrintAttribs(type, string);
6590 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
6591 strcat(string, " const");
6592 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
6593 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6594 strcat(string, " (");
6595 if(type.kind == pointerType)
6597 if(type.type.kind == functionType || type.type.kind == methodType)
6598 PrintAttribs(type.type, string);
6600 if(type.kind == pointerType)
6602 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
6603 strcat(string, "*");
6605 strcat(string, " *");
6607 if(printConst && type.constant && type.kind == pointerType)
6608 strcat(string, " const");
6611 PrintTypeSpecs(type, string, fullName, printConst);
6614 static void PostPrintType(Type type, char * string, bool fullName)
6616 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6617 strcat(string, ")");
6618 if(type.kind == arrayType)
6619 PrintArraySize(type, string);
6620 else if(type.kind == functionType)
6623 strcat(string, "(");
6624 for(param = type.params.first; param; param = param.next)
6626 PrintType(param, string, true, fullName);
6627 if(param.next) strcat(string, ", ");
6629 strcat(string, ")");
6631 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6632 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
6636 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6638 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
6640 PrePrintType(type, string, fullName, null, printConst);
6642 if(type.thisClass || (printName && type.name && type.name[0]))
6643 strcat(string, " ");
6644 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
6646 Symbol _class = type.thisClass;
6647 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
6649 if(type.classObjectType == classPointer)
6650 strcat(string, "class");
6652 strcat(string, type.byReference ? "typed_object&" : "typed_object");
6654 else if(_class && _class.string)
6656 String s = _class.string;
6661 char * name = RSearchString(s, "::", strlen(s), true, false);
6662 if(name) name += 2; else name = s;
6663 strcat(string, name);
6666 strcat(string, "::");
6669 if(printName && type.name)
6670 PrintName(type, string, fullName);
6671 PostPrintType(type, string, fullName);
6672 if(type.bitFieldCount)
6675 sprintf(count, ":%d", type.bitFieldCount);
6676 strcat(string, count);
6680 void PrintType(Type type, char * string, bool printName, bool fullName)
6682 _PrintType(type, string, printName, fullName, true);
6685 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
6687 _PrintType(type, string, printName, fullName, false);
6690 static Type FindMember(Type type, char * string)
6693 for(memberType = type.members.first; memberType; memberType = memberType.next)
6695 if(!memberType.name)
6697 Type subType = FindMember(memberType, string);
6701 else if(!strcmp(memberType.name, string))
6707 Type FindMemberAndOffset(Type type, char * string, uint * offset)
6710 for(memberType = type.members.first; memberType; memberType = memberType.next)
6712 if(!memberType.name)
6714 Type subType = FindMember(memberType, string);
6717 *offset += memberType.offset;
6721 else if(!strcmp(memberType.name, string))
6723 *offset += memberType.offset;
6730 public bool GetParseError() { return parseError; }
6732 Expression ParseExpressionString(char * expression)
6736 fileInput = TempFile { };
6737 fileInput.Write(expression, 1, strlen(expression));
6738 fileInput.Seek(0, start);
6741 parsedExpression = null;
6743 expression_yyparse();
6746 return parsedExpression;
6749 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
6751 Identifier id = exp.identifier;
6752 Method method = null;
6753 Property prop = null;
6754 DataMember member = null;
6755 ClassProperty classProp = null;
6757 if(_class && _class.type == enumClass)
6759 NamedLink value = null;
6760 Class enumClass = eSystem_FindClass(privateModule, "enum");
6764 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
6766 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
6767 for(value = e.values.first; value; value = value.next)
6769 if(!strcmp(value.name, id.string))
6776 FreeExpContents(exp);
6778 exp.type = constantExp;
6779 exp.isConstant = true;
6780 if(!strcmp(baseClass.dataTypeString, "int"))
6781 sprintf(constant, "%d",(int)value.data);
6783 sprintf(constant, "0x%X",(int)value.data);
6784 exp.constant = CopyString(constant);
6785 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
6786 exp.expType = MkClassType(baseClass.fullName);
6794 if((method = eClass_FindMethod(_class, id.string, privateModule)))
6796 ProcessMethodType(method);
6803 // TOCHECK: Put it back to what it was...
6804 // methodClass = _class;
6805 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
6810 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
6813 ProcessPropertyType(prop);
6814 exp.expType = prop.dataType;
6815 if(prop.dataType) prop.dataType.refCount++;
6818 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
6820 if(!member.dataType)
6821 member.dataType = ProcessTypeString(member.dataTypeString, false);
6822 exp.expType = member.dataType;
6823 if(member.dataType) member.dataType.refCount++;
6826 else if((classProp = eClass_FindClassProperty(_class, id.string)))
6828 if(!classProp.dataType)
6829 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
6831 if(classProp.constant)
6833 FreeExpContents(exp);
6835 exp.isConstant = true;
6836 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
6838 //char constant[256];
6839 exp.type = stringExp;
6840 exp.constant = QMkString((char *)classProp.Get(_class));
6845 exp.type = constantExp;
6846 sprintf(constant, "%d", (int)classProp.Get(_class));
6847 exp.constant = CopyString(constant);
6855 exp.expType = classProp.dataType;
6856 if(classProp.dataType) classProp.dataType.refCount++;
6862 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
6864 BinaryTree * tree = &nameSpace.functions;
6865 GlobalData data = (GlobalData)tree->FindString(name);
6869 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
6871 data = ScanGlobalData(child, name);
6879 static GlobalData FindGlobalData(char * name)
6882 NameSpace * nameSpace;
6883 nameSpace = globalData;
6884 for(c = 0; name[c]; c++)
6886 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
6888 NameSpace * newSpace;
6889 char * spaceName = new char[c - start + 1];
6890 strncpy(spaceName, name + start, c - start);
6891 spaceName[c-start] = '\0';
6892 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
6896 nameSpace = newSpace;
6897 if(name[c] == ':') c++;
6903 return ScanGlobalData(nameSpace, name + start);
6908 static int definedExpStackPos;
6909 static void * definedExpStack[512];
6911 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
6912 void ReplaceExpContents(Expression checkedExp, Expression newExp)
6914 Expression prev = checkedExp.prev, next = checkedExp.next;
6916 FreeExpContents(checkedExp);
6917 FreeType(checkedExp.expType);
6918 FreeType(checkedExp.destType);
6920 *checkedExp = *newExp;
6924 checkedExp.prev = prev;
6925 checkedExp.next = next;
6928 void ApplyAnyObjectLogic(Expression e)
6930 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
6932 char debugExpString[4096];
6933 debugExpString[0] = '\0';
6934 PrintExpression(e, debugExpString);
6937 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
6939 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
6940 //ellipsisDestType = destType;
6943 Type type = e.expType;
6944 Class _class = null;
6945 //Type destType = e.destType;
6947 if(type.kind == classType && type._class && type._class.registered)
6949 _class = type._class.registered;
6951 else if(type.kind == subClassType)
6953 _class = FindClass("ecere::com::Class").registered;
6957 char string[1024] = "";
6960 PrintTypeNoConst(type, string, false, true);
6961 classSym = FindClass(string);
6962 if(classSym) _class = classSym.registered;
6965 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...
6966 (!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))) ||
6967 destType.byReference)))
6969 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
6971 Expression checkedExp = e, newExp;
6973 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
6975 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
6977 if(checkedExp.type == extensionCompoundExp)
6979 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
6982 checkedExp = checkedExp.list->last;
6984 else if(checkedExp.type == castExp)
6985 checkedExp = checkedExp.cast.exp;
6988 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
6990 newExp = checkedExp.op.exp2;
6991 checkedExp.op.exp2 = null;
6992 FreeExpContents(checkedExp);
6994 if(e.expType && e.expType.passAsTemplate)
6997 ComputeTypeSize(e.expType);
6998 sprintf(size, "%d", e.expType.size);
6999 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7000 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7001 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7004 ReplaceExpContents(checkedExp, newExp);
7005 e.byReference = true;
7007 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7009 Expression checkedExp, newExp;
7012 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7014 e.type == identifierExp ||
7015 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7016 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7017 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7020 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7022 Context context = PushContext();
7024 OldList * specs = MkList();
7025 char typeString[1024];
7026 Expression newExp { };
7028 typeString[0] = '\0';
7031 //if(e.destType) e.destType.refCount++;
7032 // if(exp.expType) exp.expType.refCount++;
7035 newExp.expType = null;
7037 PrintTypeNoConst(e.expType, typeString, false, true);
7038 decl = SpecDeclFromString(typeString, specs, null);
7039 newExp.destType = ProcessType(specs, decl);
7041 curContext = context;
7043 // We need a current compound for this
7047 OldList * stmts = MkList();
7048 e.type = extensionCompoundExp;
7049 sprintf(name, "__internalValue%03X", internalValueCounter++);
7050 if(!curCompound.compound.declarations)
7051 curCompound.compound.declarations = MkList();
7052 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7053 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7054 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7055 e.compound = MkCompoundStmt(null, stmts);
7058 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7061 e.compound = MkCompoundStmt(
7062 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7063 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7065 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7069 Type type = e.destType;
7071 CopyTypeInto(e.destType, type);
7072 e.destType.refCount = 1;
7073 e.destType.classObjectType = none;
7077 e.compound.compound.context = context;
7078 PopContext(context);
7079 curContext = context.parent;
7083 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7085 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7087 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7089 if(checkedExp.type == extensionCompoundExp)
7091 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7094 checkedExp = checkedExp.list->last;
7096 else if(checkedExp.type == castExp)
7097 checkedExp = checkedExp.cast.exp;
7100 Expression operand { };
7101 operand = *checkedExp;
7102 checkedExp.destType = null;
7103 checkedExp.expType = null;
7105 checkedExp.type = opExp;
7106 checkedExp.op.op = '&';
7107 checkedExp.op.exp1 = null;
7108 checkedExp.op.exp2 = operand;
7110 //newExp = MkExpOp(null, '&', checkedExp);
7112 //ReplaceExpContents(checkedExp, newExp);
7119 // If expression type is a simple class, make it an address
7120 // FixReference(e, true);
7123 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7124 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7125 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7127 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"))
7129 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7133 Expression thisExp { };
7136 thisExp.prev = null;
7137 thisExp.next = null;
7140 e.type = bracketsExp;
7141 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7142 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7143 ((Expression)e.list->first).byReference = true;
7145 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7147 e.expType = thisExp.expType;
7148 e.expType.refCount++;
7153 CopyTypeInto(e.expType, thisExp.expType);
7154 e.expType.byReference = false;
7155 e.expType.refCount = 1;
7157 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7158 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7160 e.expType.classObjectType = none;
7165 // TOFIX: Try this for a nice IDE crash!
7167 // The other way around
7170 if(destType && e.expType &&
7171 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7172 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7173 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7175 if(destType.kind == ellipsisType)
7177 Compiler_Error($"Unspecified type\n");
7179 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7181 bool byReference = e.expType.byReference;
7182 Expression thisExp { };
7184 OldList * specs = MkList();
7185 char typeString[1024]; // Watch buffer overruns
7187 ClassObjectType backupClassObjectType;
7188 bool backupByReference;
7190 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7195 backupClassObjectType = type.classObjectType;
7196 backupByReference = type.byReference;
7198 type.classObjectType = none;
7199 type.byReference = false;
7201 typeString[0] = '\0';
7202 PrintType(type, typeString, false, true);
7203 decl = SpecDeclFromString(typeString, specs, null);
7205 type.classObjectType = backupClassObjectType;
7206 type.byReference = backupByReference;
7209 thisExp.prev = null;
7210 thisExp.next = null;
7213 if( ( type.kind == classType && type._class && type._class.registered &&
7214 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7215 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7216 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7217 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7222 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7225 CopyTypeInto(e.expType, type);
7226 e.expType.byReference = false;
7227 e.expType.refCount = 1;
7232 e.cast.typeName = MkTypeName(specs, decl);
7233 e.cast.exp = thisExp;
7234 e.byReference = true;
7238 e.destType = destType;
7239 destType.refCount++;
7244 void ProcessExpressionType(Expression exp)
7246 bool unresolved = false;
7247 Location oldyylloc = yylloc;
7248 bool notByReference = false;
7250 char debugExpString[4096];
7251 debugExpString[0] = '\0';
7252 PrintExpression(exp, debugExpString);
7254 if(!exp || exp.expType)
7257 //eSystem_Logf("%s\n", expString);
7259 // Testing this here
7265 Identifier id = exp.identifier;
7266 if(!id || !topContext) return;
7268 // DOING THIS LATER NOW...
7269 if(id._class && id._class.name)
7271 id.classSym = id._class.symbol; // FindClass(id._class.name);
7272 /* TODO: Name Space Fix ups
7274 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7278 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7280 exp.expType = ProcessTypeString("Module", true);
7283 else */if(strstr(id.string, "__ecereClass") == id.string)
7285 exp.expType = ProcessTypeString("ecere::com::Class", true);
7288 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7290 // Added this here as well
7291 ReplaceClassMembers(exp, thisClass);
7292 if(exp.type != identifierExp)
7294 ProcessExpressionType(exp);
7298 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7303 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7304 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7305 if(!symbol/* && exp.destType*/)
7307 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7313 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7314 if(exp.type != identifierExp)
7316 ProcessExpressionType(exp);
7320 // Static methods called from inside the _class
7321 else if(currentClass && !id._class)
7323 if(ResolveIdWithClass(exp, currentClass, true))
7326 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7330 // If we manage to resolve this symbol
7333 Type type = symbol.type;
7334 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7336 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7338 Context context = SetupTemplatesContext(_class);
7339 type = ReplaceThisClassType(_class);
7340 FinishTemplatesContext(context);
7341 if(type) type.refCount = 0; // We'll be incrementing it right below...
7344 FreeSpecifier(id._class);
7347 id.string = CopyString(symbol.string);
7353 if(type && (type.kind == enumType || (_class && _class.type == enumClass)))
7354 // Add missing cases here... enum Classes...
7355 exp.isConstant = true;
7357 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7358 if(symbol.isParam || !strcmp(id.string, "this"))
7360 if(_class && _class.type == structClass && !type.declaredWithStruct)
7361 exp.byReference = true;
7363 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7364 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7365 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7366 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7368 Identifier id = exp.identifier;
7369 exp.type = bracketsExp;
7370 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7374 if(symbol.isIterator)
7376 if(symbol.isIterator == 3)
7378 exp.type = bracketsExp;
7379 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7380 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7382 ProcessExpressionType(exp);
7384 else if(symbol.isIterator != 4)
7386 exp.type = memberExp;
7387 exp.member.exp = MkExpIdentifier(exp.identifier);
7388 exp.member.exp.expType = exp.expType;
7389 /*if(symbol.isIterator == 6)
7390 exp.member.member = MkIdentifier("key");
7392 exp.member.member = MkIdentifier("data");
7394 ProcessExpressionType(exp);
7401 DefinedExpression definedExp = null;
7402 if(thisNameSpace && !(id._class && !id._class.name))
7405 strcpy(name, thisNameSpace);
7407 strcat(name, id.string);
7408 definedExp = eSystem_FindDefine(privateModule, name);
7411 definedExp = eSystem_FindDefine(privateModule, id.string);
7415 for(c = 0; c<definedExpStackPos; c++)
7416 if(definedExpStack[c] == definedExp)
7418 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7420 Location backupYylloc = yylloc;
7421 File backInput = fileInput;
7422 definedExpStack[definedExpStackPos++] = definedExp;
7424 fileInput = TempFile { };
7425 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7426 fileInput.Seek(0, start);
7429 parsedExpression = null;
7431 expression_yyparse();
7434 fileInput = backInput;
7436 yylloc = backupYylloc;
7438 if(parsedExpression)
7441 exp.type = bracketsExp;
7442 exp.list = MkListOne(parsedExpression);
7443 parsedExpression.loc = yylloc;
7444 ProcessExpressionType(exp);
7445 definedExpStackPos--;
7448 definedExpStackPos--;
7454 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7460 GlobalData data = null;
7461 if(thisNameSpace && !(id._class && !id._class.name))
7464 strcpy(name, thisNameSpace);
7466 strcat(name, id.string);
7467 data = FindGlobalData(name);
7470 data = FindGlobalData(id.string);
7473 DeclareGlobalData(data);
7474 exp.expType = data.dataType;
7475 if(data.dataType) data.dataType.refCount++;
7478 id.string = CopyString(data.fullName);
7479 FreeSpecifier(id._class);
7486 GlobalFunction function = null;
7487 if(thisNameSpace && !(id._class && !id._class.name))
7490 strcpy(name, thisNameSpace);
7492 strcat(name, id.string);
7493 function = eSystem_FindFunction(privateModule, name);
7496 function = eSystem_FindFunction(privateModule, id.string);
7501 id.string = CopyString(function.name);
7504 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7505 strcpy(name, "__ecereFunction_");
7506 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7507 if(DeclareFunction(function, name))
7510 id.string = CopyString(name);
7512 exp.expType = function.dataType;
7513 if(function.dataType) function.dataType.refCount++;
7515 FreeSpecifier(id._class);
7532 if(!exp.instance._class)
7534 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7536 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7540 //classSym = FindClass(exp.instance._class.fullName);
7541 //_class = classSym ? classSym.registered : null;
7543 ProcessInstantiationType(exp.instance);
7544 exp.isConstant = exp.instance.isConstant;
7547 if(_class.type == unitClass && _class.base.type != systemClass)
7550 Type destType = exp.destType;
7552 exp.destType = MkClassType(_class.base.fullName);
7553 exp.expType = MkClassType(_class.fullName);
7554 CheckExpressionType(exp, exp.destType, true);
7556 exp.destType = destType;
7558 exp.expType = MkClassType(_class.fullName);
7561 if(exp.instance._class)
7563 exp.expType = MkClassType(exp.instance._class.name);
7564 /*if(exp.expType._class && exp.expType._class.registered &&
7565 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7566 exp.expType.byReference = true;*/
7574 char * constant = exp.constant;
7582 if(constant[0] == '\'')
7584 if((int)((byte *)constant)[1] > 127)
7587 unichar ch = UTF8GetChar(constant + 1, &nb);
7588 if(nb < 2) ch = constant[1];
7590 exp.constant = PrintUInt(ch);
7591 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7592 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7593 type._class = FindClass("unichar");
7595 type.isSigned = false;
7599 type.kind = charType;
7600 type.isSigned = true;
7605 char * dot = strchr(constant, '.');
7606 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
7610 exponent = strchr(constant, 'p');
7611 if(!exponent) exponent = strchr(constant, 'P');
7615 exponent = strchr(constant, 'e');
7616 if(!exponent) exponent = strchr(constant, 'E');
7621 if(strchr(constant, 'f') || strchr(constant, 'F'))
7622 type.kind = floatType;
7624 type.kind = doubleType;
7625 type.isSigned = true;
7629 bool isSigned = constant[0] == '-';
7630 int64 i64 = strtoll(constant, null, 0);
7631 uint64 ui64 = strtoull(constant, null, 0);
7632 bool is64Bit = false;
7645 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
7649 else if(constant[0] != '0' || !constant[1])
7652 type.kind = is64Bit ? int64Type : intType;
7653 type.isSigned = isSigned;
7656 exp.isConstant = true;
7657 if(exp.destType && exp.destType.kind == doubleType)
7658 type.kind = doubleType;
7659 else if(exp.destType && exp.destType.kind == floatType)
7660 type.kind = floatType;
7661 else if(exp.destType && exp.destType.kind == int64Type)
7662 type.kind = int64Type;
7668 exp.isConstant = true; // Why wasn't this constant?
7685 ProcessExpressionType(exp._new.size);
7690 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
7692 DeclareType(exp.expType.type, false, false);
7696 ProcessExpressionType(exp._renew.size);
7697 ProcessExpressionType(exp._renew.exp);
7702 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
7704 DeclareType(exp.expType.type, false, false);
7708 bool assign = false, boolResult = false, boolOps = false;
7709 Type type1 = null, type2 = null;
7710 bool useDestType = false, useSideType = false;
7711 Location oldyylloc = yylloc;
7712 bool useSideUnit = false;
7714 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
7723 // Assignment Operators
7737 // boolean Operators
7739 // Expect boolean operators
7741 //boolResult = true;
7745 // Expect boolean operands
7756 // Gives boolean result
7764 // Just added these... testing
7769 // DANGER: Verify units
7774 if(exp.op.op != '*' || exp.op.exp1)
7781 /*// Implement speed etc.
7787 if(exp.op.op == '&')
7789 // Added this here earlier for Iterator address as key
7790 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
7792 Identifier id = exp.op.exp2.identifier;
7793 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
7794 if(symbol && symbol.isIterator == 2)
7796 exp.type = memberExp;
7797 exp.member.exp = exp.op.exp2;
7798 exp.member.member = MkIdentifier("key");
7800 exp.op.exp2.expType = symbol.type;
7801 symbol.type.refCount++;
7802 ProcessExpressionType(exp);
7806 // exp.op.exp2.usage.usageRef = true;
7810 //dummy.kind = TypeDummy;
7814 if(exp.destType && exp.destType.kind == classType &&
7815 exp.destType._class && exp.destType._class.registered && useDestType &&
7817 ((exp.destType._class.registered.type == unitClass && useSideUnit) ||
7818 exp.destType._class.registered.type == enumClass ||
7819 exp.destType._class.registered.type == bitClass
7822 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
7824 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7825 exp.op.exp1.destType = exp.destType;
7827 exp.destType.refCount++;
7831 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
7832 exp.op.exp1.destType = dummy;
7836 // TESTING THIS HERE...
7837 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
7838 ProcessExpressionType(exp.op.exp1);
7839 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
7841 if(exp.op.exp1.destType == dummy)
7844 exp.op.exp1.destType = null;
7846 type1 = exp.op.exp1.expType;
7851 char expString[10240];
7852 expString[0] = '\0';
7853 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
7857 exp.op.exp2.destType = exp.op.exp1.expType;
7858 if(exp.op.exp1.expType)
7859 exp.op.exp1.expType.refCount++;
7863 exp.op.exp2.destType = exp.destType;
7865 exp.destType.refCount++;
7868 if(type1) type1.refCount++;
7869 exp.expType = type1;
7874 PrintExpression(exp.op.exp2, expString);
7876 if(type1 && type1.kind == pointerType)
7878 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 ||
7879 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
7880 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
7881 else if(exp.op.op == '=')
7883 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7884 exp.op.exp2.destType = type1;
7891 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
7892 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/* ||
7893 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
7896 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7897 exp.op.exp2.destType = type1;
7902 if(type1) type1.refCount++;
7903 exp.expType = type1;
7905 else if(exp.destType && exp.destType.kind == classType &&
7906 exp.destType._class && exp.destType._class.registered &&
7908 ((exp.destType._class.registered.type == unitClass && useDestType && useSideUnit) ||
7909 (exp.destType._class.registered.type == enumClass && useDestType))
7912 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7913 exp.op.exp2.destType = exp.destType;
7915 exp.destType.refCount++;
7919 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
7920 exp.op.exp2.destType = dummy;
7924 // TESTING THIS HERE... (DANGEROUS)
7925 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
7926 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
7928 FreeType(exp.op.exp2.destType);
7929 exp.op.exp2.destType = type1;
7932 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
7933 ProcessExpressionType(exp.op.exp2);
7934 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
7936 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
7938 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)
7940 if(exp.op.op != '=' && type1.type.kind == voidType)
7941 Compiler_Error($"void *: unknown size\n");
7943 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||
7944 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
7945 (exp.op.exp2.expType._class.registered.type == normalClass ||
7946 exp.op.exp2.expType._class.registered.type == structClass ||
7947 exp.op.exp2.expType._class.registered.type == noHeadClass)))
7949 if(exp.op.op == ADD_ASSIGN)
7950 Compiler_Error($"cannot add two pointers\n");
7952 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
7953 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
7955 if(exp.op.op == ADD_ASSIGN)
7956 Compiler_Error($"cannot add two pointers\n");
7960 char type1String[1024];
7961 char type2String[1024];
7962 type1String[0] = '\0';
7963 type2String[0] = '\0';
7965 PrintType(exp.op.exp2.expType, type1String, false, true);
7966 PrintType(type1, type2String, false, true);
7967 ChangeCh(expString, '\n', ' ');
7968 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
7972 if(exp.op.exp2.destType == dummy)
7975 exp.op.exp2.destType = null;
7978 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
7982 CopyTypeInto(type2, exp.op.exp2.expType);
7983 type2.isSigned = true;
7985 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
7987 type2 = { kind = intType };
7989 type2.isSigned = true;
7993 type2 = exp.op.exp2.expType;
7994 if(type2) type2.refCount++;
7998 dummy.kind = voidType;
8000 if(exp.op.op == SIZEOF)
8007 exp.isConstant = true;
8009 // Get type of dereferenced pointer
8010 else if(exp.op.op == '*' && !exp.op.exp1)
8012 exp.expType = Dereference(type2);
8013 if(type2 && type2.kind == classType)
8014 notByReference = true;
8016 else if(exp.op.op == '&' && !exp.op.exp1)
8017 exp.expType = Reference(type2);
8024 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8025 exp.op.exp1.destType = MkClassType("bool");
8026 exp.op.exp1.destType.truth = true;
8027 if(!exp.op.exp1.expType)
8028 ProcessExpressionType(exp.op.exp1);
8030 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8031 FreeType(exp.op.exp1.expType);
8032 exp.op.exp1.expType = MkClassType("bool");
8033 exp.op.exp1.expType.truth = true;
8037 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8038 exp.op.exp2.destType = MkClassType("bool");
8039 exp.op.exp2.destType.truth = true;
8040 if(!exp.op.exp2.expType)
8041 ProcessExpressionType(exp.op.exp2);
8043 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8044 FreeType(exp.op.exp2.expType);
8045 exp.op.exp2.expType = MkClassType("bool");
8046 exp.op.exp2.expType.truth = true;
8049 else if(exp.op.exp1 && exp.op.exp2 &&
8052 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8053 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8054 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8055 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8057 if(type1 && type2 &&
8058 // If either both are class or both are not class
8059 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8061 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8062 exp.op.exp2.destType = type1;
8064 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8065 exp.op.exp1.destType = type2;
8067 // Warning here for adding Radians + Degrees with no destination type
8068 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8069 type1._class.registered && type1._class.registered.type == unitClass &&
8070 type2._class.registered && type2._class.registered.type == unitClass &&
8071 type1._class.registered != type2._class.registered)
8072 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8073 type1._class.string, type2._class.string, type1._class.string);
8075 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8077 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8080 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8082 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8083 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8086 ProcessExpressionType(exp.op.exp1);
8088 if(type2.kind != pointerType)
8090 ProcessExpressionType(classExp);
8092 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8093 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8094 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8096 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8099 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8100 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8101 MkPointer(null, null), null)))),
8102 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8104 if(!exp.op.exp2.expType)
8108 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8112 ProcessExpressionType(exp.op.exp2);
8117 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)))
8119 if(type1.kind != classType && type1.type.kind == voidType)
8120 Compiler_Error($"void *: unknown size\n");
8121 exp.expType = type1;
8122 if(type1) type1.refCount++;
8124 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)))
8126 if(type2.kind != classType && type2.type.kind == voidType)
8127 Compiler_Error($"void *: unknown size\n");
8128 exp.expType = type2;
8129 if(type2) type2.refCount++;
8131 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8132 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8134 Compiler_Warning($"different levels of indirection\n");
8138 bool success = false;
8139 if(type1.kind == pointerType && type2.kind == pointerType)
8141 if(exp.op.op == '+')
8142 Compiler_Error($"cannot add two pointers\n");
8143 else if(exp.op.op == '-')
8145 // Pointer Subtraction gives integer
8146 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8155 if(type1.type.kind == templateType)
8157 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8160 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8162 ProcessExpressionType(classExp);
8164 exp.type = bracketsExp;
8165 exp.list = MkListOne(MkExpOp(
8166 MkExpBrackets(MkListOne(MkExpOp(
8167 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8169 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8171 //MkExpMember(classExp, MkIdentifier("typeSize"))
8173 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8174 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8176 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8179 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8180 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8181 MkPointer(null, null), null)))),
8182 MkExpMember(classExp, MkIdentifier("typeSize")))))
8187 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8196 if(!success && exp.op.exp1.type == constantExp)
8198 // If first expression is constant, try to match that first
8199 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8201 if(exp.expType) FreeType(exp.expType);
8202 exp.expType = exp.op.exp1.destType;
8203 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8206 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8208 if(exp.expType) FreeType(exp.expType);
8209 exp.expType = exp.op.exp2.destType;
8210 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8216 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8218 if(exp.expType) FreeType(exp.expType);
8219 exp.expType = exp.op.exp2.destType;
8220 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8223 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8225 if(exp.expType) FreeType(exp.expType);
8226 exp.expType = exp.op.exp1.destType;
8227 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8233 char expString1[10240];
8234 char expString2[10240];
8237 expString1[0] = '\0';
8238 expString2[0] = '\0';
8243 PrintExpression(exp.op.exp1, expString1);
8244 ChangeCh(expString1, '\n', ' ');
8245 PrintExpression(exp.op.exp2, expString2);
8246 ChangeCh(expString2, '\n', ' ');
8247 PrintType(exp.op.exp1.expType, type1, false, true);
8248 PrintType(exp.op.exp2.expType, type2, false, true);
8251 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8255 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8256 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8258 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8259 // Convert e.g. / 4 into / 4.0
8260 exp.op.exp1.destType = type2._class.registered.dataType;
8261 if(type2._class.registered.dataType)
8262 type2._class.registered.dataType.refCount++;
8263 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8264 exp.expType = type2;
8265 if(type2) type2.refCount++;
8267 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8269 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8270 // Convert e.g. / 4 into / 4.0
8271 exp.op.exp2.destType = type1._class.registered.dataType;
8272 if(type1._class.registered.dataType)
8273 type1._class.registered.dataType.refCount++;
8274 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8275 exp.expType = type1;
8276 if(type1) type1.refCount++;
8282 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8284 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8286 if(!type1._class.registered.dataType)
8287 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8288 exp.op.exp2.destType = type1._class.registered.dataType;
8289 exp.op.exp2.destType.refCount++;
8291 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8294 type2 = exp.op.exp2.destType;
8295 if(type2) type2.refCount++;
8297 exp.expType = type2;
8301 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8303 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8305 if(!type2._class.registered.dataType)
8306 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8307 exp.op.exp1.destType = type2._class.registered.dataType;
8308 exp.op.exp1.destType.refCount++;
8310 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8311 type1 = exp.op.exp1.destType;
8312 exp.expType = type1;
8316 // TESTING THIS NEW CODE
8317 if(!boolResult || exp.op.op == '>' || exp.op.op == '<')
8319 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass && exp.op.exp2.expType)
8321 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8323 if(exp.expType) FreeType(exp.expType);
8324 exp.expType = exp.op.exp1.expType;
8325 if(exp.op.exp2.expType) exp.op.exp1.expType.refCount++;
8330 else if(type2 && (type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass && exp.op.exp1.expType))
8332 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8334 if(exp.expType) FreeType(exp.expType);
8335 exp.expType = exp.op.exp2.expType;
8336 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8344 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8345 exp.op.exp2.destType = type1;
8349 // Maybe this was meant to be an enum...
8350 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8352 Type oldType = exp.op.exp2.expType;
8353 exp.op.exp2.expType = null;
8354 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8357 exp.op.exp2.expType = oldType;
8362 // TESTING THIS HERE... LATEST ADDITION
8363 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8365 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8366 exp.op.exp2.destType = type2._class.registered.dataType;
8367 if(type2._class.registered.dataType)
8368 type2._class.registered.dataType.refCount++;
8369 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8371 //exp.expType = type2._class.registered.dataType; //type2;
8372 //if(type2) type2.refCount++;
8375 // TESTING THIS HERE... LATEST ADDITION
8376 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8378 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8379 exp.op.exp1.destType = type1._class.registered.dataType;
8380 if(type1._class.registered.dataType)
8381 type1._class.registered.dataType.refCount++;
8382 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8383 exp.expType = type1._class.registered.dataType; //type1;
8384 if(type1) type1.refCount++;
8388 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8390 if(exp.expType) FreeType(exp.expType);
8391 exp.expType = exp.op.exp2.destType;
8392 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8394 else if(type1 && type2)
8396 char expString1[10240];
8397 char expString2[10240];
8398 char type1String[1024];
8399 char type2String[1024];
8400 expString1[0] = '\0';
8401 expString2[0] = '\0';
8402 type1String[0] = '\0';
8403 type2String[0] = '\0';
8406 PrintExpression(exp.op.exp1, expString1);
8407 ChangeCh(expString1, '\n', ' ');
8408 PrintExpression(exp.op.exp2, expString2);
8409 ChangeCh(expString2, '\n', ' ');
8410 PrintType(exp.op.exp1.expType, type1String, false, true);
8411 PrintType(exp.op.exp2.expType, type2String, false, true);
8414 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8416 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8418 exp.expType = exp.op.exp1.expType;
8419 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8421 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8423 exp.expType = exp.op.exp2.expType;
8424 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8431 // Maybe this was meant to be an enum...
8432 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8434 Type oldType = exp.op.exp1.expType;
8435 exp.op.exp1.expType = null;
8436 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8439 exp.op.exp1.expType = oldType;
8442 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8443 exp.op.exp1.destType = type2;
8446 // TESTING THIS HERE... LATEST ADDITION
8447 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8449 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8450 exp.op.exp1.destType = type1._class.registered.dataType;
8451 if(type1._class.registered.dataType)
8452 type1._class.registered.dataType.refCount++;
8455 // TESTING THIS HERE... LATEST ADDITION
8456 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8458 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8459 exp.op.exp2.destType = type2._class.registered.dataType;
8460 if(type2._class.registered.dataType)
8461 type2._class.registered.dataType.refCount++;
8465 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8467 if(exp.expType) FreeType(exp.expType);
8468 exp.expType = exp.op.exp1.destType;
8469 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8473 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8475 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8477 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8478 // Convert e.g. / 4 into / 4.0
8479 exp.op.exp1.destType = type2._class.registered.dataType;
8480 if(type2._class.registered.dataType)
8481 type2._class.registered.dataType.refCount++;
8482 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8484 if(exp.op.op == '!')
8486 exp.expType = MkClassType("bool");
8487 exp.expType.truth = true;
8491 exp.expType = type2;
8492 if(type2) type2.refCount++;
8495 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8497 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8499 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8500 // Convert e.g. / 4 into / 4.0
8501 exp.op.exp2.destType = type1._class.registered.dataType;
8502 if(type1._class.registered.dataType)
8503 type1._class.registered.dataType.refCount++;
8504 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8506 exp.expType = type1;
8507 if(type1) type1.refCount++;
8512 if(exp.op.exp1 && !exp.op.exp1.expType)
8514 char expString[10000];
8515 expString[0] = '\0';
8518 PrintExpression(exp.op.exp1, expString);
8519 ChangeCh(expString, '\n', ' ');
8522 Compiler_Error($"couldn't determine type of %s\n", expString);
8524 if(exp.op.exp2 && !exp.op.exp2.expType)
8526 char expString[10240];
8527 expString[0] = '\0';
8530 PrintExpression(exp.op.exp2, expString);
8531 ChangeCh(expString, '\n', ' ');
8534 Compiler_Error($"couldn't determine type of %s\n", expString);
8539 FreeType(exp.expType);
8540 exp.expType = MkClassType("bool");
8541 exp.expType.truth = true;
8544 if(exp.op.op != SIZEOF)
8545 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8546 (!exp.op.exp2 || exp.op.exp2.isConstant);
8548 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8550 DeclareType(exp.op.exp2.expType, false, false);
8561 case extensionExpressionExp:
8564 exp.isConstant = true;
8565 for(e = exp.list->first; e; e = e.next)
8570 FreeType(e.destType);
8571 e.destType = exp.destType;
8572 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
8574 ProcessExpressionType(e);
8576 exp.destType.count--;
8577 if(!exp.expType && !e.next)
8579 exp.expType = e.expType;
8580 if(e.expType) e.expType.refCount++;
8583 exp.isConstant = false;
8586 // In case a cast became a member...
8587 e = exp.list->first;
8588 if(!e.next && e.type == memberExp)
8590 // Preserve prev, next
8591 Expression next = exp.next, prev = exp.prev;
8594 FreeType(exp.expType);
8595 FreeType(exp.destType);
8605 ProcessExpressionType(exp);
8612 exp.isConstant = true;
8614 ProcessExpressionType(exp.index.exp);
8615 if(!exp.index.exp.isConstant)
8616 exp.isConstant = false;
8618 if(exp.index.exp.expType)
8620 Type source = exp.index.exp.expType;
8621 if(source.kind == classType && source._class && source._class.registered)
8623 Class _class = source._class.registered;
8624 Class c = _class.templateClass ? _class.templateClass : _class;
8625 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
8627 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
8629 if(exp.index.index && exp.index.index->last)
8631 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
8637 for(e = exp.index.index->first; e; e = e.next)
8639 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
8641 if(e.destType) FreeType(e.destType);
8642 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
8644 ProcessExpressionType(e);
8647 // Check if this type is int
8650 exp.isConstant = false;
8654 exp.expType = Dereference(exp.index.exp.expType);
8656 DeclareType(exp.expType, false, false);
8663 Type methodType = null;
8669 PrintExpression(exp.call.exp, name);
8670 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
8672 //exp.call.exp.expType = null;
8673 PrintExpression(exp.call.exp, name);
8676 if(exp.call.exp.type == identifierExp)
8678 Expression idExp = exp.call.exp;
8679 Identifier id = idExp.identifier;
8680 if(!strcmp(id.string, "__builtin_frame_address"))
8682 exp.expType = ProcessTypeString("void *", true);
8683 if(exp.call.arguments && exp.call.arguments->first)
8684 ProcessExpressionType(exp.call.arguments->first);
8687 else if(!strcmp(id.string, "__ENDIAN_PAD"))
8689 exp.expType = ProcessTypeString("int", true);
8690 if(exp.call.arguments && exp.call.arguments->first)
8691 ProcessExpressionType(exp.call.arguments->first);
8694 else if(!strcmp(id.string, "Max") ||
8695 !strcmp(id.string, "Min") ||
8696 !strcmp(id.string, "Sgn") ||
8697 !strcmp(id.string, "Abs"))
8699 Expression a = null;
8700 Expression b = null;
8701 Expression tempExp1 = null, tempExp2 = null;
8702 if((!strcmp(id.string, "Max") ||
8703 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
8705 a = exp.call.arguments->first;
8706 b = exp.call.arguments->last;
8710 else if(exp.call.arguments->count == 1)
8712 a = exp.call.arguments->first;
8718 exp.call.arguments->Clear();
8719 idExp.identifier = null;
8721 FreeExpContents(exp);
8723 ProcessExpressionType(a);
8725 ProcessExpressionType(b);
8727 exp.type = bracketsExp;
8728 exp.list = MkList();
8730 if(a.expType && (!b || b.expType))
8732 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
8734 // Use the simpleStruct name/ids for now...
8737 OldList * specs = MkList();
8738 OldList * decls = MkList();
8740 char temp1[1024], temp2[1024];
8742 GetTypeSpecs(a.expType, specs);
8744 if(a && !a.isConstant && a.type != identifierExp)
8746 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
8747 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
8748 tempExp1 = QMkExpId(temp1);
8749 tempExp1.expType = a.expType;
8751 a.expType.refCount++;
8752 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
8754 if(b && !b.isConstant && b.type != identifierExp)
8756 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
8757 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
8758 tempExp2 = QMkExpId(temp2);
8759 tempExp2.expType = b.expType;
8761 b.expType.refCount++;
8762 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
8765 decl = MkDeclaration(specs, decls);
8766 if(!curCompound.compound.declarations)
8767 curCompound.compound.declarations = MkList();
8768 curCompound.compound.declarations->Insert(null, decl);
8773 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
8775 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
8777 MkExpCondition(MkExpBrackets(MkListOne(
8778 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
8779 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
8780 exp.expType = a.expType;
8782 a.expType.refCount++;
8784 else if(!strcmp(id.string, "Abs"))
8787 MkExpCondition(MkExpBrackets(MkListOne(
8788 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8789 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
8790 exp.expType = a.expType;
8792 a.expType.refCount++;
8794 else if(!strcmp(id.string, "Sgn"))
8796 // ((!(a))?(0):(((a)<0)?(-1):(1)))
8798 MkExpCondition(MkExpBrackets(MkListOne(
8799 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
8800 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
8801 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
8802 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
8803 exp.expType = ProcessTypeString("int", false);
8806 FreeExpression(tempExp1);
8807 if(tempExp2) FreeExpression(tempExp2);
8821 if(!exp.call.exp.destType)
8823 exp.call.exp.destType = dummy;
8826 ProcessExpressionType(exp.call.exp);
8827 if(exp.call.exp.destType == dummy)
8830 exp.call.exp.destType = null;
8835 // Check argument types against parameter types
8836 functionType = exp.call.exp.expType;
8838 if(functionType && functionType.kind == TypeKind::methodType)
8840 methodType = functionType;
8841 functionType = methodType.method.dataType;
8843 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
8844 // TOCHECK: Instead of doing this here could this be done per param?
8845 if(exp.call.exp.expType.usedClass)
8847 char typeString[1024];
8848 typeString[0] = '\0';
8850 Symbol back = functionType.thisClass;
8851 // Do not output class specifier here (thisclass was added to this)
8852 functionType.thisClass = null;
8853 PrintType(functionType, typeString, true, true);
8854 functionType.thisClass = back;
8856 if(strstr(typeString, "thisclass"))
8858 OldList * specs = MkList();
8861 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
8863 decl = SpecDeclFromString(typeString, specs, null);
8865 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
8866 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
8867 exp.call.exp.expType.usedClass))
8868 thisClassParams = false;
8870 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
8872 Class backupThisClass = thisClass;
8873 thisClass = exp.call.exp.expType.usedClass;
8874 ProcessDeclarator(decl);
8875 thisClass = backupThisClass;
8878 thisClassParams = true;
8880 functionType = ProcessType(specs, decl);
8881 functionType.refCount = 0;
8882 FinishTemplatesContext(context);
8885 FreeList(specs, FreeSpecifier);
8886 FreeDeclarator(decl);
8890 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
8892 Type type = functionType.type;
8893 if(!functionType.refCount)
8895 functionType.type = null;
8896 FreeType(functionType);
8898 //methodType = functionType;
8899 functionType = type;
8901 if(functionType && functionType.kind != TypeKind::functionType)
8903 Compiler_Error($"called object %s is not a function\n", name);
8905 else if(functionType)
8907 bool emptyParams = false, noParams = false;
8908 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
8909 Type type = functionType.params.first;
8910 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
8912 Location oldyylloc = yylloc;
8914 if(!type) emptyParams = true;
8917 if(functionType.extraParam && e && functionType.thisClass)
8919 e.destType = MkClassType(functionType.thisClass.string);
8923 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
8924 // Fixed #141 by adding '&& !functionType.extraParam'
8925 if(!functionType.staticMethod && !functionType.extraParam)
8927 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
8928 memberExp.member.exp.expType._class)
8930 type = MkClassType(memberExp.member.exp.expType._class.string);
8935 type = functionType.params.first;
8940 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
8942 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
8943 type.byReference = functionType.byReference;
8944 type.typedByReference = functionType.typedByReference;
8947 // Allow manually passing a class for typed object
8948 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
8952 type = functionType.params.first;
8960 if(type && type.kind == voidType)
8963 if(!type.refCount) FreeType(type);
8967 for( ; e; e = e.next)
8969 if(!type && !emptyParams)
8972 if(methodType && methodType.methodClass)
8973 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
8974 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
8975 noParams ? 0 : functionType.params.count);
8977 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
8978 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
8979 noParams ? 0 : functionType.params.count);
8983 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
8985 Type templatedType = null;
8986 Class _class = methodType.usedClass;
8987 ClassTemplateParameter curParam = null;
8989 if(_class && _class.templateArgs /*&& _class.templateClass*/)
8992 for(sClass = _class; sClass; sClass = sClass.base)
8994 if(sClass.templateClass) sClass = sClass.templateClass;
8996 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
8998 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9001 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9003 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9004 id += nextClass.templateParams.count;
9013 if(curParam && _class.templateArgs[id].dataTypeString)
9015 ClassTemplateArgument arg = _class.templateArgs[id];
9017 Context context = SetupTemplatesContext(_class);
9020 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9021 templatedType = ProcessTypeString(arg.dataTypeString, false);
9022 FinishTemplatesContext(context);
9024 e.destType = templatedType;
9027 templatedType.passAsTemplate = true;
9028 // templatedType.refCount++;
9034 if(type) type.refCount++;
9039 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9041 e.destType = type.prev;
9042 e.destType.refCount++;
9047 if(type) type.refCount++;
9050 // Don't reach the end for the ellipsis
9051 if(type && type.kind != ellipsisType)
9053 Type next = type.next;
9054 if(!type.refCount) FreeType(type);
9059 if(type && type.kind != ellipsisType)
9061 if(methodType && methodType.methodClass)
9062 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9063 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9064 functionType.params.count + extra);
9066 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9067 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9068 functionType.params.count + extra);
9071 if(type && !type.refCount) FreeType(type);
9078 kind = TypeKind::functionType;
9081 if(exp.call.exp.type == identifierExp)
9083 char * string = exp.call.exp.identifier.string;
9087 Location oldyylloc = yylloc;
9089 yylloc = exp.call.exp.identifier.loc;
9090 if(strstr(string, "__builtin_") == string)
9094 functionType.returnType = exp.destType;
9095 exp.destType.refCount++;
9099 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9100 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9101 globalContext.symbols.Add((BTNode)symbol);
9102 if(strstr(symbol.string, "::"))
9103 globalContext.hasNameSpace = true;
9108 else if(exp.call.exp.type == memberExp)
9110 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9111 exp.call.exp.member.member.string);*/
9114 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9116 if(!functionType.returnType)
9118 functionType.returnType = Type
9125 if(functionType && functionType.kind == TypeKind::functionType)
9127 exp.expType = functionType.returnType;
9129 if(functionType.returnType)
9130 functionType.returnType.refCount++;
9132 if(!functionType.refCount)
9133 FreeType(functionType);
9136 if(exp.call.arguments)
9138 for(e = exp.call.arguments->first; e; e = e.next)
9140 Type destType = e.destType;
9141 ProcessExpressionType(e);
9149 Location oldyylloc = yylloc;
9151 Expression checkExp = exp.member.exp;
9154 if(checkExp.type == castExp)
9155 checkExp = checkExp.cast.exp;
9156 else if(checkExp.type == bracketsExp)
9157 checkExp = checkExp.list ? checkExp.list->first : null;
9162 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9163 exp.thisPtr = thisPtr;
9165 // DOING THIS LATER NOW...
9166 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9168 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9169 /* TODO: Name Space Fix ups
9170 if(!exp.member.member.classSym)
9171 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9175 ProcessExpressionType(exp.member.exp);
9176 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9177 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9179 exp.isConstant = false;
9182 exp.isConstant = exp.member.exp.isConstant;
9183 type = exp.member.exp.expType;
9187 if(type && (type.kind == templateType))
9189 Class _class = thisClass ? thisClass : currentClass;
9190 ClassTemplateParameter param = null;
9193 for(param = _class.templateParams.first; param; param = param.next)
9195 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9199 if(param && param.defaultArg.member)
9201 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9204 Expression expMember = exp.member.exp;
9206 OldList * specs = MkList();
9207 char thisClassTypeString[1024];
9209 FreeIdentifier(exp.member.member);
9211 ProcessExpressionType(argExp);
9214 char * colon = strstr(param.defaultArg.memberString, "::");
9217 char className[1024];
9220 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9221 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9224 strcpy(thisClassTypeString, _class.fullName);
9227 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9229 exp.expType = ProcessType(specs, decl);
9230 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9232 Class expClass = exp.expType._class.registered;
9233 Class cClass = null;
9238 char templateString[1024];
9239 ClassTemplateParameter param;
9240 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9241 for(cClass = expClass; cClass; cClass = cClass.base)
9244 for(param = cClass.templateParams.first; param; param = param.next)
9248 ClassTemplateArgument arg;
9249 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9250 arg = expClass.templateArgs[id];
9252 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9254 ClassTemplateParameter cParam;
9255 //int p = numParams - sClass.templateParams.count;
9258 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9260 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9262 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9264 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9266 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9267 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9279 strcat(argument, arg.name.string);
9280 strcat(argument, " = ");
9286 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9287 char expString[1024];
9288 OldList * specs = MkList();
9289 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9291 char * string = PrintHexUInt64(arg.expression.ui64);
9292 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9295 ProcessExpressionType(exp);
9296 ComputeExpression(exp);
9297 expString[0] = '\0';
9298 PrintExpression(exp, expString);
9299 strcat(argument, expString);
9301 FreeExpression(exp);
9306 strcat(argument, arg.member.name);
9309 case TemplateParameterType::type:
9311 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9313 if(!strcmp(arg.dataTypeString, "thisclass"))
9314 strcat(argument, thisClassTypeString);
9316 strcat(argument, arg.dataTypeString);
9323 if(paramCount) strcat(templateString, ", ");
9324 if(lastParam != p - 1)
9326 strcat(templateString, param.name);
9327 strcat(templateString, " = ");
9329 strcat(templateString, argument);
9338 int len = strlen(templateString);
9339 if(templateString[len-1] == '>') templateString[len++] = ' ';
9340 templateString[len++] = '>';
9341 templateString[len++] = '\0';
9344 Context context = SetupTemplatesContext(_class);
9345 FreeType(exp.expType);
9346 exp.expType = ProcessTypeString(templateString, false);
9347 FinishTemplatesContext(context);
9351 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9352 exp.type = bracketsExp;
9353 exp.list = MkListOne(MkExpOp(null, '*',
9358 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9359 MkExpBrackets(MkListOne(
9360 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9362 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9364 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9369 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9370 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9372 type = ProcessTemplateParameterType(type.templateParameter);
9375 // TODO: *** This seems to be where we should add method support for all basic types ***
9376 if(type && (type.kind == templateType));
9377 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9378 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
9379 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9380 (type.kind == pointerType && type.type.kind == charType)))
9382 Identifier id = exp.member.member;
9383 TypeKind typeKind = type.kind;
9384 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9385 if(typeKind == subClassType && exp.member.exp.type == classExp)
9387 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9388 typeKind = classType;
9393 if(typeKind == intType || typeKind == enumType)
9394 _class = eSystem_FindClass(privateModule, "int");
9397 if(type.kind == classType && type._class && type._class.registered)
9399 _class = type._class.registered;
9401 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
9403 _class = FindClass("char *").registered;
9405 else if(type.kind == pointerType)
9407 _class = eSystem_FindClass(privateModule, "uintptr");
9408 FreeType(exp.expType);
9409 exp.expType = ProcessTypeString("uintptr", false);
9410 exp.byReference = true;
9414 char string[1024] = "";
9416 PrintTypeNoConst(type, string, false, true);
9417 classSym = FindClass(string);
9418 if(classSym) _class = classSym.registered;
9426 (exp.member.exp.type == identifierExp &&
9427 !strcmp(exp.member.exp.identifier.string, "this"));*/
9428 Property prop = null;
9429 Method method = null;
9430 DataMember member = null;
9431 Property revConvert = null;
9432 ClassProperty classProp = null;
9434 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9435 exp.member.memberType = propertyMember;
9437 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9438 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9440 if(typeKind != subClassType)
9442 // Prioritize data members over properties for "this"
9443 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9445 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9446 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9448 prop = eClass_FindProperty(_class, id.string, privateModule);
9452 if(!member && !prop)
9453 prop = eClass_FindProperty(_class, id.string, privateModule);
9454 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9455 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9456 exp.member.thisPtr = true;
9458 // Prioritize properties over data members otherwise
9461 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9464 prop = eClass_FindProperty(_class, id.string, null);
9465 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9466 member = eClass_FindDataMember(_class, id.string, null, null, null);
9469 if(!prop && !member)
9471 method = eClass_FindMethod(_class, id.string, null);
9474 prop = eClass_FindProperty(_class, id.string, privateModule);
9475 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9476 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9482 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9489 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
9490 method = eClass_FindMethod(_class, id.string, privateModule);
9491 if(!prop && !member && !method)
9493 if(typeKind == subClassType)
9495 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9498 exp.member.memberType = classPropertyMember;
9499 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9503 // Assume this is a class_data member
9504 char structName[1024];
9505 Identifier id = exp.member.member;
9506 Expression classExp = exp.member.exp;
9509 FreeType(classExp.expType);
9510 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9512 strcpy(structName, "__ecereClassData_");
9513 FullClassNameCat(structName, type._class.string, false);
9514 exp.type = pointerExp;
9515 exp.member.member = id;
9517 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9518 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9519 MkExpBrackets(MkListOne(MkExpOp(
9520 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9521 MkExpMember(classExp, MkIdentifier("data"))), '+',
9522 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9527 ProcessExpressionType(exp);
9533 // Check for reverse conversion
9534 // (Convert in an instantiation later, so that we can use
9535 // deep properties system)
9536 Symbol classSym = FindClass(id.string);
9539 Class convertClass = classSym.registered;
9541 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9548 exp.member.memberType = propertyMember;
9550 ProcessPropertyType(prop);
9551 exp.expType = prop.dataType;
9552 if(prop.dataType) prop.dataType.refCount++;
9556 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9558 FreeExpContents(exp);
9559 exp.type = identifierExp;
9560 exp.identifier = MkIdentifier("class");
9561 ProcessExpressionType(exp);
9565 exp.member.memberType = dataMember;
9566 DeclareStruct(_class.fullName, false);
9567 if(!member.dataType)
9569 Context context = SetupTemplatesContext(_class);
9570 member.dataType = ProcessTypeString(member.dataTypeString, false);
9571 FinishTemplatesContext(context);
9573 exp.expType = member.dataType;
9574 if(member.dataType) member.dataType.refCount++;
9578 exp.member.memberType = reverseConversionMember;
9579 exp.expType = MkClassType(revConvert._class.fullName);
9587 exp.type = identifierExp;
9588 exp.identifier = exp.member.member;
9591 exp.member.memberType = methodMember;
9593 if(!method.dataType)
9594 ProcessMethodType(method);
9602 // Tricky spot here... To use instance versus class virtual table
9603 // Put it back to what it was... What did we break?
9605 // Had to put it back for overriding Main of Thread global instance
9607 //exp.expType.methodClass = _class;
9608 exp.expType.methodClass = (id && id._class) ? _class : null;
9610 // Need the actual class used for templated classes
9611 exp.expType.usedClass = _class;
9615 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9617 FreeExpContents(exp);
9618 exp.type = identifierExp;
9619 exp.identifier = MkIdentifier("class");
9620 ProcessExpressionType(exp);
9623 yylloc = exp.member.member.loc;
9624 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
9626 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
9629 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
9634 while(tClass && !tClass.templateClass) tClass = tClass.base;
9636 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
9639 ClassTemplateParameter curParam = null;
9642 for(sClass = tClass; sClass; sClass = sClass.base)
9645 if(sClass.templateClass) sClass = sClass.templateClass;
9646 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9648 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
9650 for(sClass = sClass.base; sClass; sClass = sClass.base)
9651 id += sClass.templateParams.count;
9659 if(curParam && tClass.templateArgs[id].dataTypeString)
9661 ClassTemplateArgument arg = tClass.templateArgs[id];
9662 Context context = SetupTemplatesContext(tClass);
9664 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9665 FreeType(exp.expType);
9666 exp.expType = ProcessTypeString(arg.dataTypeString, false);
9669 if(exp.expType.kind == thisClassType)
9671 FreeType(exp.expType);
9672 exp.expType = ReplaceThisClassType(_class);
9675 if(tClass.templateClass)
9676 exp.expType.passAsTemplate = true;
9677 //exp.expType.refCount++;
9680 exp.destType = ProcessTypeString(arg.dataTypeString, false);
9681 //exp.destType.refCount++;
9683 if(exp.destType.kind == thisClassType)
9685 FreeType(exp.destType);
9686 exp.destType = ReplaceThisClassType(_class);
9690 FinishTemplatesContext(context);
9693 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
9694 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
9697 ClassTemplateParameter curParam = null;
9700 for(sClass = tClass; sClass; sClass = sClass.base)
9703 if(sClass.templateClass) sClass = sClass.templateClass;
9704 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9706 if(curParam.type == TemplateParameterType::type &&
9707 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
9709 for(sClass = sClass.base; sClass; sClass = sClass.base)
9710 id += sClass.templateParams.count;
9720 ClassTemplateArgument arg = tClass.templateArgs[id];
9721 Context context = SetupTemplatesContext(tClass);
9724 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9726 basicType = ProcessTypeString(arg.dataTypeString, false);
9729 if(basicType.kind == thisClassType)
9731 FreeType(basicType);
9732 basicType = ReplaceThisClassType(_class);
9735 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
9736 if(tClass.templateClass)
9737 basicType.passAsTemplate = true;
9740 FreeType(exp.expType);
9742 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
9743 //exp.expType.refCount++;
9746 exp.destType = exp.expType;
9747 exp.destType.refCount++;
9751 Expression newExp { };
9752 OldList * specs = MkList();
9754 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
9756 if(exp.destType) exp.destType.refCount++;
9757 if(exp.expType) exp.expType.refCount++;
9759 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
9760 exp.cast.exp = newExp;
9761 //FreeType(exp.expType);
9762 //exp.expType = null;
9763 //ProcessExpressionType(sourceExp);
9766 FinishTemplatesContext(context);
9769 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
9771 Class expClass = exp.expType._class.registered;
9774 Class cClass = null;
9779 char templateString[1024];
9780 ClassTemplateParameter param;
9781 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9782 while(cClass != expClass)
9785 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
9788 for(param = cClass.templateParams.first; param; param = param.next)
9790 Class cClassCur = null;
9793 ClassTemplateParameter paramCur = null;
9794 ClassTemplateArgument arg;
9795 while(cClassCur != tClass && !paramCur)
9798 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
9799 cClassCur = sClassCur;
9801 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
9803 if(!strcmp(paramCur.name, param.name))
9811 if(paramCur && paramCur.type == TemplateParameterType::type)
9812 arg = tClass.templateArgs[cp];
9814 arg = expClass.templateArgs[p];
9821 strcat(argument, arg.name.string);
9822 strcat(argument, " = ");
9828 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9829 char expString[1024];
9830 OldList * specs = MkList();
9831 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9833 char * string = PrintHexUInt64(arg.expression.ui64);
9834 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9837 ProcessExpressionType(exp);
9838 ComputeExpression(exp);
9839 expString[0] = '\0';
9840 PrintExpression(exp, expString);
9841 strcat(argument, expString);
9843 FreeExpression(exp);
9848 strcat(argument, arg.member.name);
9851 case TemplateParameterType::type:
9853 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9854 strcat(argument, arg.dataTypeString);
9860 if(paramCount) strcat(templateString, ", ");
9861 if(lastParam != p - 1)
9863 strcat(templateString, param.name);
9864 strcat(templateString, " = ");
9866 strcat(templateString, argument);
9875 int len = strlen(templateString);
9876 if(templateString[len-1] == '>') templateString[len++] = ' ';
9877 templateString[len++] = '>';
9878 templateString[len++] = '\0';
9881 FreeType(exp.expType);
9883 Context context = SetupTemplatesContext(tClass);
9884 exp.expType = ProcessTypeString(templateString, false);
9885 FinishTemplatesContext(context);
9892 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
9894 else if(type && (type.kind == structType || type.kind == unionType))
9896 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
9899 exp.expType = memberType;
9901 memberType.refCount++;
9906 char expString[10240];
9907 expString[0] = '\0';
9908 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
9909 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
9912 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
9914 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
9916 Identifier id = exp.member.member;
9917 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9920 FreeType(exp.expType);
9921 exp.expType = ReplaceThisClassType(_class);
9928 // Convert x->y into (*x).y
9931 Type destType = exp.destType;
9933 // DOING THIS LATER NOW...
9934 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9936 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9937 /* TODO: Name Space Fix ups
9938 if(!exp.member.member.classSym)
9939 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
9943 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
9944 exp.type = memberExp;
9947 ProcessExpressionType(exp);
9954 //ComputeExpression(exp);
9956 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
9957 if(classSym && classSym.registered)
9959 if(classSym.registered.type == noHeadClass)
9963 DeclareStruct(classSym.string, false);
9964 FreeSpecifier(exp._class);
9965 exp.type = typeSizeExp;
9966 FullClassNameCat(name, classSym.string, false);
9967 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
9971 if(classSym.registered.fixed)
9973 FreeSpecifier(exp._class);
9974 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
9975 exp.type = constantExp;
9979 char className[1024];
9980 strcpy(className, "__ecereClass_");
9981 FullClassNameCat(className, classSym.string, true);
9982 MangleClassName(className);
9984 DeclareClass(classSym, className);
9986 FreeExpContents(exp);
9987 exp.type = pointerExp;
9988 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
9989 exp.member.member = MkIdentifier("structSize");
9999 // exp.isConstant = true;
10004 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10011 exp.isConstant = true;
10013 DeclareType(type, false, false);
10019 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10021 FreeType(exp.cast.exp.destType);
10022 exp.cast.exp.destType = type;
10024 ProcessExpressionType(exp.cast.exp);
10026 exp.expType = type;
10029 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10030 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10032 void * prev = exp.prev, * next = exp.next;
10033 Type expType = exp.cast.exp.destType;
10034 Expression castExp = exp.cast.exp;
10035 Type destType = exp.destType;
10037 if(expType) expType.refCount++;
10039 //FreeType(exp.destType);
10040 FreeType(exp.expType);
10041 FreeTypeName(exp.cast.typeName);
10044 FreeType(exp.expType);
10045 FreeType(exp.destType);
10047 exp.expType = expType;
10048 exp.destType = destType;
10058 exp.isConstant = exp.cast.exp.isConstant;
10063 case extensionInitializerExp:
10065 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10066 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10067 // ProcessInitializer(exp.initializer.initializer, type);
10068 exp.expType = type;
10073 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10074 ProcessExpressionType(exp.vaArg.exp);
10075 exp.expType = type;
10081 exp.isConstant = true;
10083 FreeType(exp.cond.cond.destType);
10084 exp.cond.cond.destType = MkClassType("bool");
10085 exp.cond.cond.destType.truth = true;
10086 ProcessExpressionType(exp.cond.cond);
10087 if(!exp.cond.cond.isConstant)
10088 exp.isConstant = false;
10089 for(e = exp.cond.exp->first; e; e = e.next)
10093 FreeType(e.destType);
10094 e.destType = exp.destType;
10095 if(e.destType) e.destType.refCount++;
10097 ProcessExpressionType(e);
10100 exp.expType = e.expType;
10101 if(e.expType) e.expType.refCount++;
10104 exp.isConstant = false;
10107 FreeType(exp.cond.elseExp.destType);
10108 // Added this check if we failed to find an expType
10109 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10112 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10114 if(exp.cond.elseExp.destType)
10115 exp.cond.elseExp.destType.refCount++;
10116 ProcessExpressionType(exp.cond.elseExp);
10118 // FIXED THIS: Was done before calling process on elseExp
10119 if(!exp.cond.elseExp.isConstant)
10120 exp.isConstant = false;
10123 case extensionCompoundExp:
10125 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10127 Statement last = exp.compound.compound.statements->last;
10128 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10130 ((Expression)last.expressions->last).destType = exp.destType;
10132 exp.destType.refCount++;
10134 ProcessStatement(exp.compound);
10135 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10137 exp.expType.refCount++;
10143 Specifier spec = exp._classExp.specifiers->first;
10144 if(spec && spec.type == nameSpecifier)
10146 exp.expType = MkClassType(spec.name);
10147 exp.expType.kind = subClassType;
10148 exp.byReference = true;
10152 exp.expType = MkClassType("ecere::com::Class");
10153 exp.byReference = true;
10159 Class _class = thisClass ? thisClass : currentClass;
10162 Identifier id = exp.classData.id;
10163 char structName[1024];
10164 Expression classExp;
10165 strcpy(structName, "__ecereClassData_");
10166 FullClassNameCat(structName, _class.fullName, false);
10167 exp.type = pointerExp;
10168 exp.member.member = id;
10169 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10170 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10172 classExp = MkExpIdentifier(MkIdentifier("class"));
10174 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10175 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10176 MkExpBrackets(MkListOne(MkExpOp(
10177 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10178 MkExpMember(classExp, MkIdentifier("data"))), '+',
10179 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10182 ProcessExpressionType(exp);
10190 char * typeString = null;
10191 char typeStringBuf[1024];
10192 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10193 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10195 Class templateClass = exp.destType._class.registered;
10196 typeString = templateClass.templateArgs[2].dataTypeString;
10200 // Guess type from expressions in the array
10202 for(e = exp.list->first; e; e = e.next)
10204 ProcessExpressionType(e);
10207 if(!type) { type = e.expType; type.refCount++; }
10210 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10211 if(!MatchTypeExpression(e, type, null, false))
10217 e = exp.list->first;
10218 ProcessExpressionType(e);
10221 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10222 if(!MatchTypeExpression(e, type, null, false))
10224 FreeType(e.expType);
10235 FreeType(e.expType);
10242 typeStringBuf[0] = '\0';
10243 PrintTypeNoConst(type, typeStringBuf, false, true);
10244 typeString = typeStringBuf;
10252 (Container)& (struct BuiltInContainer)
10254 ._vTbl = class(BuiltInContainer)._vTbl,
10255 ._class = class(BuiltInContainer),
10257 .data = (int[]){ 1, 7, 3, 4, 5 },
10259 .type = class(int),
10262 char templateString[1024];
10263 OldList * initializers = MkList();
10264 OldList * structInitializers = MkList();
10265 OldList * specs = MkList();
10267 Declarator decl = SpecDeclFromString(typeString, specs, null);
10268 sprintf(templateString, "Container<%s>", typeString);
10273 type = ProcessTypeString(typeString, false);
10274 while(e = exp.list->first)
10276 exp.list->Remove(e);
10279 ProcessExpressionType(e);
10280 ListAdd(initializers, MkInitializerAssignment(e));
10286 DeclareStruct("ecere::com::BuiltInContainer", false);
10288 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10289 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10290 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10291 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10292 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10293 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10294 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10295 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10296 MkInitializerList(initializers))));
10297 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10298 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10299 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10300 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10301 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10302 exp.expType = ProcessTypeString(templateString, false);
10303 exp.type = bracketsExp;
10304 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10306 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10307 MkInitializerList(structInitializers)))));
10308 ProcessExpressionType(expExt);
10312 exp.expType = ProcessTypeString("Container", false);
10313 Compiler_Error($"Couldn't determine type of array elements\n");
10319 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10321 FreeType(exp.expType);
10322 exp.expType = ReplaceThisClassType(thisClass);
10325 // Resolve structures here
10326 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10328 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10329 // TODO: Fix members reference...
10332 if(exp.expType.kind != enumType)
10335 String enumName = CopyString(exp.expType.enumName);
10337 // Fixed a memory leak on self-referencing C structs typedefs
10338 // by instantiating a new type rather than simply copying members
10339 // into exp.expType
10340 FreeType(exp.expType);
10341 exp.expType = Type { };
10342 exp.expType.kind = symbol.type.kind;
10343 exp.expType.refCount++;
10344 exp.expType.enumName = enumName;
10346 exp.expType.members = symbol.type.members;
10347 for(member = symbol.type.members.first; member; member = member.next)
10353 for(member = symbol.type.members.first; member; member = member.next)
10355 NamedLink value { name = CopyString(member.name) };
10356 exp.expType.members.Add(value);
10363 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10364 else if(exp.destType && !exp.destType.keepCast)
10366 if(!CheckExpressionType(exp, exp.destType, false))
10368 if(!exp.destType.count || unresolved)
10373 if(exp.destType.kind != ellipsisType)
10379 char expString[10240];
10380 expString[0] = '\0';
10382 PrintType(exp.destType, type2, false, true);
10384 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10386 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10387 else if(exp.type != dummyExp)
10388 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10393 char expString[10240] ;
10394 expString[0] = '\0';
10395 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10398 Compiler_Error($"unresolved identifier %s\n", expString);
10399 else if(exp.type != dummyExp)
10400 Compiler_Error($"couldn't determine type of %s\n", expString);
10411 PrintType(exp.expType, type1, false, true);
10412 PrintType(exp.destType, type2, false, true);
10415 //CheckExpressionType(exp, exp.destType, false);
10417 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10418 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10419 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10422 char expString[10240];
10423 expString[0] = '\0';
10424 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10427 CheckExpressionType(exp, exp.destType, false);
10429 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10430 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10431 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10433 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10434 FreeType(exp.expType);
10435 exp.destType.refCount++;
10436 exp.expType = exp.destType;
10441 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10443 Expression newExp { };
10444 char typeString[1024];
10445 OldList * specs = MkList();
10448 typeString[0] = '\0';
10452 if(exp.expType) exp.expType.refCount++;
10453 if(exp.expType) exp.expType.refCount++;
10454 exp.type = castExp;
10455 newExp.destType = exp.expType;
10457 PrintType(exp.expType, typeString, false, false);
10458 decl = SpecDeclFromString(typeString, specs, null);
10460 exp.cast.typeName = MkTypeName(specs, decl);
10461 exp.cast.exp = newExp;
10464 else if(unresolved)
10466 if(exp.identifier._class && exp.identifier._class.name)
10467 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10468 else if(exp.identifier.string && exp.identifier.string[0])
10469 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10471 else if(!exp.expType && exp.type != dummyExp)
10473 char expString[10240];
10474 expString[0] = '\0';
10475 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10476 Compiler_Error($"couldn't determine type of %s\n", expString);
10479 // Let's try to support any_object & typed_object here:
10481 ApplyAnyObjectLogic(exp);
10483 // Mark nohead classes as by reference, unless we're casting them to an integral type
10484 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10485 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
10486 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
10487 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
10489 exp.byReference = true;
10491 yylloc = oldyylloc;
10494 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10496 // THIS CODE WILL FIND NEXT MEMBER...
10499 *curMember = (*curMember).next;
10501 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10503 *curMember = subMemberStack[--(*subMemberStackPos)];
10504 *curMember = (*curMember).next;
10507 // SKIP ALL PROPERTIES HERE...
10508 while((*curMember) && (*curMember).isProperty)
10509 *curMember = (*curMember).next;
10511 if(subMemberStackPos)
10513 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10515 subMemberStack[(*subMemberStackPos)++] = *curMember;
10517 *curMember = (*curMember).members.first;
10518 while(*curMember && (*curMember).isProperty)
10519 *curMember = (*curMember).next;
10527 if(subMemberStackPos && *subMemberStackPos)
10529 *curMember = subMemberStack[--(*subMemberStackPos)];
10530 *curMember = (*curMember).next;
10534 Class lastCurClass = *curClass;
10536 if(*curClass == _class) break; // REACHED THE END
10538 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10539 *curMember = (*curClass).membersAndProperties.first;
10542 while((*curMember) && (*curMember).isProperty)
10543 *curMember = (*curMember).next;
10544 if(subMemberStackPos)
10546 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10548 subMemberStack[(*subMemberStackPos)++] = *curMember;
10550 *curMember = (*curMember).members.first;
10551 while(*curMember && (*curMember).isProperty)
10552 *curMember = (*curMember).next;
10560 static void ProcessInitializer(Initializer init, Type type)
10564 case expInitializer:
10565 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
10567 // TESTING THIS FOR SHUTTING = 0 WARNING
10568 if(init.exp && !init.exp.destType)
10570 FreeType(init.exp.destType);
10571 init.exp.destType = type;
10572 if(type) type.refCount++;
10576 ProcessExpressionType(init.exp);
10577 init.isConstant = init.exp.isConstant;
10583 Expression exp = init.exp;
10584 Instantiation inst = exp.instance;
10585 MembersInit members;
10587 init.type = listInitializer;
10588 init.list = MkList();
10592 for(members = inst.members->first; members; members = members.next)
10594 if(members.type == dataMembersInit)
10597 for(member = members.dataMembers->first; member; member = member.next)
10599 ListAdd(init.list, member.initializer);
10600 member.initializer = null;
10603 // Discard all MembersInitMethod
10606 FreeExpression(exp);
10608 case listInitializer:
10611 Type initializerType = null;
10612 Class curClass = null;
10613 DataMember curMember = null;
10614 DataMember subMemberStack[256];
10615 int subMemberStackPos = 0;
10617 if(type && type.kind == arrayType)
10618 initializerType = Dereference(type);
10619 else if(type && (type.kind == structType || type.kind == unionType))
10620 initializerType = type.members.first;
10622 for(i = init.list->first; i; i = i.next)
10624 if(type && type.kind == classType && type._class && type._class.registered)
10626 // 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)
10627 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
10628 // TODO: Generate error on initializing a private data member this way from another module...
10631 if(!curMember.dataType)
10632 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
10633 initializerType = curMember.dataType;
10636 ProcessInitializer(i, initializerType);
10637 if(initializerType && type && (type.kind == structType || type.kind == unionType))
10638 initializerType = initializerType.next;
10640 init.isConstant = false;
10643 if(type && type.kind == arrayType)
10644 FreeType(initializerType);
10646 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
10648 Compiler_Error($"Assigning list initializer to non list\n");
10655 static void ProcessSpecifier(Specifier spec, bool declareStruct)
10659 case baseSpecifier:
10661 if(spec.specifier == THISCLASS)
10665 spec.type = nameSpecifier;
10666 spec.name = ReplaceThisClass(thisClass);
10667 spec.symbol = FindClass(spec.name);
10668 ProcessSpecifier(spec, declareStruct);
10673 case nameSpecifier:
10675 Symbol symbol = FindType(curContext, spec.name);
10677 DeclareType(symbol.type, true, true);
10678 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
10679 DeclareStruct(spec.name, false);
10682 case enumSpecifier:
10687 for(e = spec.list->first; e; e = e.next)
10690 ProcessExpressionType(e.exp);
10695 case structSpecifier:
10696 case unionSpecifier:
10698 if(spec.definitions)
10701 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
10703 ProcessClass(spec.definitions, symbol);
10706 for(def = spec.definitions->first; def; def = def.next)
10708 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
10709 ProcessDeclaration(def.decl);
10716 case classSpecifier:
10718 Symbol classSym = FindClass(spec.name);
10719 if(classSym && classSym.registered && classSym.registered.type == structClass)
10720 DeclareStruct(spec.name, false);
10728 static void ProcessDeclarator(Declarator decl)
10732 case identifierDeclarator:
10733 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
10735 FreeSpecifier(decl.identifier._class);
10736 decl.identifier._class = null;
10739 case arrayDeclarator:
10741 ProcessExpressionType(decl.array.exp);
10742 case structDeclarator:
10743 case bracketsDeclarator:
10744 case functionDeclarator:
10745 case pointerDeclarator:
10746 case extendedDeclarator:
10747 case extendedDeclaratorEnd:
10748 if(decl.declarator)
10749 ProcessDeclarator(decl.declarator);
10750 if(decl.type == functionDeclarator)
10752 Identifier id = GetDeclId(decl);
10753 if(id && id._class)
10757 qualifiers = MkListOne(id._class);
10760 if(!decl.function.parameters)
10761 decl.function.parameters = MkList();
10762 decl.function.parameters->Insert(null, param);
10765 if(decl.function.parameters)
10769 for(param = decl.function.parameters->first; param; param = param.next)
10771 if(param.qualifiers && param.qualifiers->first)
10773 Specifier spec = param.qualifiers->first;
10774 if(spec && spec.specifier == TYPED_OBJECT)
10776 Declarator d = param.declarator;
10779 qualifiers = MkListOne(MkSpecifier(VOID));
10780 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10783 FreeList(param.qualifiers, FreeSpecifier);
10785 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
10786 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
10788 decl.function.parameters->Insert(param, newParam);
10791 else if(spec && spec.specifier == ANY_OBJECT)
10793 Declarator d = param.declarator;
10795 FreeList(param.qualifiers, FreeSpecifier);
10797 param.qualifiers = MkListOne(MkSpecifier(VOID));
10798 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
10800 else if(spec.specifier == THISCLASS)
10804 spec.type = nameSpecifier;
10805 spec.name = ReplaceThisClass(thisClass);
10806 spec.symbol = FindClass(spec.name);
10807 ProcessSpecifier(spec, false);
10812 if(param.declarator)
10813 ProcessDeclarator(param.declarator);
10821 static void ProcessDeclaration(Declaration decl)
10826 case initDeclaration:
10828 bool declareStruct = false;
10830 lineNum = decl.pos.line;
10831 column = decl.pos.col;
10834 if(decl.declarators)
10838 for(d = decl.declarators->first; d; d = d.next)
10840 Type type, subType;
10841 ProcessDeclarator(d.declarator);
10843 type = ProcessType(decl.specifiers, d.declarator);
10847 ProcessInitializer(d.initializer, type);
10849 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
10851 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
10852 d.initializer.exp.type == instanceExp)
10854 if(type.kind == classType && type._class ==
10855 d.initializer.exp.expType._class)
10857 Instantiation inst = d.initializer.exp.instance;
10858 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
10860 d.initializer.exp.instance = null;
10861 if(decl.specifiers)
10862 FreeList(decl.specifiers, FreeSpecifier);
10863 FreeList(decl.declarators, FreeInitDeclarator);
10867 decl.type = instDeclaration;
10872 for(subType = type; subType;)
10874 if(subType.kind == classType)
10876 declareStruct = true;
10879 else if(subType.kind == pointerType)
10881 else if(subType.kind == arrayType)
10882 subType = subType.arrayType;
10892 if(decl.specifiers)
10895 for(s = decl.specifiers->first; s; s = s.next)
10897 ProcessSpecifier(s, declareStruct);
10902 case instDeclaration:
10904 ProcessInstantiationType(decl.inst);
10907 case structDeclaration:
10911 bool declareStruct = false;
10913 if(decl.declarators)
10915 for(d = decl.declarators->first; d; d = d.next)
10917 Type type = ProcessType(decl.specifiers, d.declarator);
10919 ProcessDeclarator(d);
10920 for(subType = type; subType;)
10922 if(subType.kind == classType)
10924 declareStruct = true;
10927 else if(subType.kind == pointerType)
10929 else if(subType.kind == arrayType)
10930 subType = subType.arrayType;
10937 if(decl.specifiers)
10939 for(spec = decl.specifiers->first; spec; spec = spec.next)
10940 ProcessSpecifier(spec, declareStruct);
10947 static FunctionDefinition curFunction;
10949 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
10951 char propName[1024], propNameM[1024];
10952 char getName[1024], setName[1024];
10955 DeclareProperty(prop, setName, getName);
10957 // eInstance_FireWatchers(object, prop);
10958 strcpy(propName, "__ecereProp_");
10959 FullClassNameCat(propName, prop._class.fullName, false);
10960 strcat(propName, "_");
10961 // strcat(propName, prop.name);
10962 FullClassNameCat(propName, prop.name, true);
10963 MangleClassName(propName);
10965 strcpy(propNameM, "__ecerePropM_");
10966 FullClassNameCat(propNameM, prop._class.fullName, false);
10967 strcat(propNameM, "_");
10968 // strcat(propNameM, prop.name);
10969 FullClassNameCat(propNameM, prop.name, true);
10970 MangleClassName(propNameM);
10972 if(prop.isWatchable)
10975 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10976 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10977 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10980 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10981 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10982 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
10988 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10989 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
10990 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10993 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
10994 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
10995 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
10998 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
10999 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11000 curFunction.propSet.fireWatchersDone = true;
11003 static void ProcessStatement(Statement stmt)
11007 lineNum = stmt.pos.line;
11008 column = stmt.pos.col;
11013 ProcessStatement(stmt.labeled.stmt);
11016 // This expression should be constant...
11017 if(stmt.caseStmt.exp)
11019 FreeType(stmt.caseStmt.exp.destType);
11020 stmt.caseStmt.exp.destType = curSwitchType;
11021 if(curSwitchType) curSwitchType.refCount++;
11022 ProcessExpressionType(stmt.caseStmt.exp);
11023 ComputeExpression(stmt.caseStmt.exp);
11025 if(stmt.caseStmt.stmt)
11026 ProcessStatement(stmt.caseStmt.stmt);
11030 if(stmt.compound.context)
11035 Statement prevCompound = curCompound;
11036 Context prevContext = curContext;
11038 if(!stmt.compound.isSwitch)
11039 curCompound = stmt;
11040 curContext = stmt.compound.context;
11042 if(stmt.compound.declarations)
11044 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11045 ProcessDeclaration(decl);
11047 if(stmt.compound.statements)
11049 for(s = stmt.compound.statements->first; s; s = s.next)
11050 ProcessStatement(s);
11053 curContext = prevContext;
11054 curCompound = prevCompound;
11058 case expressionStmt:
11061 if(stmt.expressions)
11063 for(exp = stmt.expressions->first; exp; exp = exp.next)
11064 ProcessExpressionType(exp);
11072 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11073 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11074 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11075 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11077 ProcessExpressionType(exp);
11079 if(stmt.ifStmt.stmt)
11080 ProcessStatement(stmt.ifStmt.stmt);
11081 if(stmt.ifStmt.elseStmt)
11082 ProcessStatement(stmt.ifStmt.elseStmt);
11087 Type oldSwitchType = curSwitchType;
11088 if(stmt.switchStmt.exp)
11091 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11101 e.exp.destType = destType;
11104 ProcessExpressionType(exp);
11107 curSwitchType = exp.expType;
11110 ProcessStatement(stmt.switchStmt.stmt);
11111 curSwitchType = oldSwitchType;
11116 if(stmt.whileStmt.exp)
11120 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11121 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11122 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11123 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11125 ProcessExpressionType(exp);
11128 if(stmt.whileStmt.stmt)
11129 ProcessStatement(stmt.whileStmt.stmt);
11134 if(stmt.doWhile.exp)
11138 if(stmt.doWhile.exp->last)
11140 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11141 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11142 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11144 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11146 ProcessExpressionType(exp);
11149 if(stmt.doWhile.stmt)
11150 ProcessStatement(stmt.doWhile.stmt);
11156 if(stmt.forStmt.init)
11157 ProcessStatement(stmt.forStmt.init);
11159 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11161 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11162 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11163 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11166 if(stmt.forStmt.check)
11167 ProcessStatement(stmt.forStmt.check);
11168 if(stmt.forStmt.increment)
11170 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11171 ProcessExpressionType(exp);
11174 if(stmt.forStmt.stmt)
11175 ProcessStatement(stmt.forStmt.stmt);
11180 Identifier id = stmt.forEachStmt.id;
11181 OldList * exp = stmt.forEachStmt.exp;
11182 OldList * filter = stmt.forEachStmt.filter;
11183 Statement block = stmt.forEachStmt.stmt;
11184 char iteratorType[1024];
11187 bool isBuiltin = exp && exp->last &&
11188 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11189 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11190 Expression arrayExp;
11191 char * typeString = null;
11192 int builtinCount = 0;
11194 for(e = exp ? exp->first : null; e; e = e.next)
11198 FreeType(e.destType);
11199 e.destType = ProcessTypeString("Container", false);
11201 if(!isBuiltin || e.next)
11202 ProcessExpressionType(e);
11205 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11206 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11207 eClass_IsDerived(source._class.registered, containerClass)))
11209 Class _class = source ? source._class.registered : null;
11211 Expression expIt = null;
11212 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
11213 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11214 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11215 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11216 stmt.type = compoundStmt;
11218 stmt.compound.context = Context { };
11219 stmt.compound.context.parent = curContext;
11220 curContext = stmt.compound.context;
11222 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11224 Class mapClass = eSystem_FindClass(privateModule, "Map");
11225 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11226 isCustomAVLTree = true;
11227 if(eClass_IsDerived(source._class.registered, avlTreeClass))
11229 else if(eClass_IsDerived(source._class.registered, mapClass))
11232 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11233 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11235 Class listClass = eSystem_FindClass(privateModule, "List");
11237 isList = eClass_IsDerived(source._class.registered, listClass);
11243 OldList * specs = MkList();
11244 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11245 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11246 stmt.compound.declarations = MkListOne(
11247 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11248 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11249 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11250 MkInitializerAssignment(MkExpBrackets(exp))))));
11255 char typeStringBuf[1024];
11257 // TODO: Merge this code?
11258 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11259 if(((Expression)exp->last).type == castExp)
11261 TypeName typeName = ((Expression)exp->last).cast.typeName;
11263 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11266 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11267 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11268 arrayExp.destType._class.registered.templateArgs)
11270 Class templateClass = arrayExp.destType._class.registered;
11271 typeString = templateClass.templateArgs[2].dataTypeString;
11273 else if(arrayExp.list)
11275 // Guess type from expressions in the array
11277 for(e = arrayExp.list->first; e; e = e.next)
11279 ProcessExpressionType(e);
11282 if(!type) { type = e.expType; type.refCount++; }
11285 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11286 if(!MatchTypeExpression(e, type, null, false))
11292 e = arrayExp.list->first;
11293 ProcessExpressionType(e);
11296 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11297 if(!MatchTypeExpression(e, type, null, false))
11299 FreeType(e.expType);
11310 FreeType(e.expType);
11317 typeStringBuf[0] = '\0';
11318 PrintType(type, typeStringBuf, false, true);
11319 typeString = typeStringBuf;
11325 OldList * initializers = MkList();
11327 OldList * specs = MkList();
11332 builtinCount = arrayExp.list->count;
11333 type = ProcessTypeString(typeString, false);
11334 while(e = arrayExp.list->first)
11336 arrayExp.list->Remove(e);
11339 ProcessExpressionType(e);
11340 ListAdd(initializers, MkInitializerAssignment(e));
11343 delete arrayExp.list;
11345 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11346 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11347 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11349 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
11351 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
11352 ), MkInitializerList(initializers)))));
11353 FreeList(exp, FreeExpression);
11357 arrayExp.expType = ProcessTypeString("Container", false);
11358 Compiler_Error($"Couldn't determine type of array elements\n");
11363 OldList * specs = MkList();
11365 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11366 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11367 stmt.compound.declarations = MkListOne(
11368 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11369 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11370 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11371 MkInitializerAssignment(MkExpBrackets(exp))))));
11374 else if(isLinkList && !isList)
11377 OldList * specs = MkList();
11378 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11379 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11380 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11381 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11382 MkInitializerAssignment(MkExpBrackets(exp))))));
11384 /*else if(isCustomAVLTree)
11387 OldList * specs = MkList();
11388 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11389 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11390 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11391 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11392 MkInitializerAssignment(MkExpBrackets(exp))))));
11394 else if(_class.templateArgs)
11397 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11399 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11401 stmt.compound.declarations = MkListOne(
11402 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11403 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11404 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11406 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11410 // Reparent sub-contexts in this statement
11414 if(block.compound.context)
11415 block.compound.context.parent = stmt.compound.context;
11418 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
11419 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
11420 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
11421 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
11424 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
11425 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
11428 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
11429 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
11432 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
11433 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
11436 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
11437 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
11440 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
11441 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
11443 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
11446 case expressionStmt:
11452 case badDeclarationStmt:
11453 case fireWatchersStmt:
11454 case stopWatchingStmt:
11461 block = MkIfStmt(filter, block, null);
11465 stmt.compound.statements = MkListOne(MkForStmt(
11466 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11467 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11468 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11469 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11471 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11472 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11473 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11478 //OldList * specs = MkList();
11479 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11481 sprintf(count, "%d", builtinCount);
11483 stmt.compound.statements = MkListOne(MkForStmt(
11484 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11485 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11486 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11487 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11491 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11492 stmt.compound.statements = MkListOne(MkForStmt(
11493 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11494 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11495 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11496 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11499 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11500 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11501 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11503 else if(isLinkList && !isList)
11505 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11506 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11507 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11508 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11510 stmt.compound.statements = MkListOne(MkForStmt(
11511 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11512 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11513 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11518 OldList * specs = MkList();
11519 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11520 stmt.compound.statements = MkListOne(MkForStmt(
11521 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11522 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11523 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11524 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11525 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11528 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11529 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11530 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11532 /*else if(isCustomAVLTree)
11534 stmt.compound.statements = MkListOne(MkForStmt(
11535 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11536 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11537 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11538 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11541 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11542 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11543 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11547 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11548 MkIdentifier("Next")), null)), block));
11550 ProcessExpressionType(expIt);
11551 if(stmt.compound.declarations->first)
11552 ProcessDeclaration(stmt.compound.declarations->first);
11555 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11557 ProcessStatement(stmt);
11558 curContext = stmt.compound.context.parent;
11563 Compiler_Error($"Expression is not a container\n");
11576 if(stmt.expressions)
11578 for(exp = stmt.expressions->first; exp; exp = exp.next)
11582 if(curFunction && !curFunction.type)
11583 curFunction.type = ProcessType(
11584 curFunction.specifiers, curFunction.declarator);
11585 FreeType(exp.destType);
11586 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
11587 if(exp.destType) exp.destType.refCount++;
11589 ProcessExpressionType(exp);
11594 case badDeclarationStmt:
11596 ProcessDeclaration(stmt.decl);
11602 if(stmt.asmStmt.inputFields)
11604 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
11605 if(field.expression)
11606 ProcessExpressionType(field.expression);
11608 if(stmt.asmStmt.outputFields)
11610 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
11611 if(field.expression)
11612 ProcessExpressionType(field.expression);
11614 if(stmt.asmStmt.clobberedFields)
11616 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
11618 if(field.expression)
11619 ProcessExpressionType(field.expression);
11626 PropertyWatch propWatch;
11627 OldList * watches = stmt._watch.watches;
11628 Expression object = stmt._watch.object;
11629 Expression watcher = stmt._watch.watcher;
11631 ProcessExpressionType(watcher);
11633 ProcessExpressionType(object);
11637 if(watcher || thisClass)
11639 External external = curExternal;
11640 Context context = curContext;
11642 stmt.type = expressionStmt;
11643 stmt.expressions = MkList();
11645 curExternal = external.prev;
11647 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11649 ClassFunction func;
11650 char watcherName[1024];
11651 Class watcherClass = watcher ?
11652 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
11653 External createdExternal;
11655 // Create a declaration above
11656 External externalDecl = MkExternalDeclaration(null);
11657 ast->Insert(curExternal.prev, externalDecl);
11659 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
11660 if(propWatch.deleteWatch)
11661 strcat(watcherName, "_delete");
11665 for(propID = propWatch.properties->first; propID; propID = propID.next)
11667 strcat(watcherName, "_");
11668 strcat(watcherName, propID.string);
11672 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
11674 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
11675 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
11676 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
11677 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
11678 ProcessClassFunctionBody(func, propWatch.compound);
11679 propWatch.compound = null;
11681 //afterExternal = afterExternal ? afterExternal : curExternal;
11683 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
11684 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
11686 createdExternal.symbol.idCode = external.symbol.idCode;
11688 curExternal = createdExternal;
11689 ProcessFunction(createdExternal.function);
11692 // Create a declaration above
11694 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
11695 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
11696 externalDecl.declaration = decl;
11697 if(decl.symbol && !decl.symbol.pointerExternal)
11698 decl.symbol.pointerExternal = externalDecl;
11701 if(propWatch.deleteWatch)
11703 OldList * args = MkList();
11704 ListAdd(args, CopyExpression(object));
11705 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11706 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11707 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
11711 Class _class = object.expType._class.registered;
11714 for(propID = propWatch.properties->first; propID; propID = propID.next)
11716 char propName[1024];
11717 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11720 char getName[1024], setName[1024];
11721 OldList * args = MkList();
11723 DeclareProperty(prop, setName, getName);
11725 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
11726 strcpy(propName, "__ecereProp_");
11727 FullClassNameCat(propName, prop._class.fullName, false);
11728 strcat(propName, "_");
11729 // strcat(propName, prop.name);
11730 FullClassNameCat(propName, prop.name, true);
11732 ListAdd(args, CopyExpression(object));
11733 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11734 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11735 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
11737 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
11740 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11745 Compiler_Error($"Invalid watched object\n");
11748 curExternal = external;
11749 curContext = context;
11752 FreeExpression(watcher);
11754 FreeExpression(object);
11755 FreeList(watches, FreePropertyWatch);
11758 Compiler_Error($"No observer specified and not inside a _class\n");
11762 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
11764 ProcessStatement(propWatch.compound);
11770 case fireWatchersStmt:
11772 OldList * watches = stmt._watch.watches;
11773 Expression object = stmt._watch.object;
11775 // DEBUGGER BUG: Why doesn't watches evaluate to null??
11776 // printf("%X\n", watches);
11777 // printf("%X\n", stmt._watch.watches);
11779 ProcessExpressionType(object);
11784 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
11790 stmt.type = expressionStmt;
11791 stmt.expressions = MkList();
11793 // Check if we're inside a property set
11794 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11796 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
11800 //Compiler_Error($"No property specified and not inside a property set\n");
11804 for(propID = watches->first; propID; propID = propID.next)
11806 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11809 CreateFireWatcher(prop, object, stmt);
11812 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
11817 // Fire all properties!
11820 for(base = _class; base; base = base.base)
11822 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
11824 if(prop.isProperty && prop.isWatchable)
11826 CreateFireWatcher(prop, object, stmt);
11833 FreeExpression(object);
11834 FreeList(watches, FreeIdentifier);
11837 Compiler_Error($"Invalid object specified and not inside a class\n");
11841 case stopWatchingStmt:
11843 OldList * watches = stmt._watch.watches;
11844 Expression object = stmt._watch.object;
11845 Expression watcher = stmt._watch.watcher;
11848 ProcessExpressionType(object);
11850 ProcessExpressionType(watcher);
11853 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
11855 if(watcher || thisClass)
11861 stmt.type = expressionStmt;
11862 stmt.expressions = MkList();
11867 // eInstance_StopWatching(object, null, watcher);
11869 ListAdd(args, CopyExpression(object));
11870 ListAdd(args, MkExpConstant("0"));
11871 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11872 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11876 for(propID = watches->first; propID; propID = propID.next)
11878 char propName[1024];
11879 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
11882 char getName[1024], setName[1024];
11883 OldList * args = MkList();
11885 DeclareProperty(prop, setName, getName);
11887 // eInstance_StopWatching(object, prop, watcher);
11888 strcpy(propName, "__ecereProp_");
11889 FullClassNameCat(propName, prop._class.fullName, false);
11890 strcat(propName, "_");
11891 // strcat(propName, prop.name);
11892 FullClassNameCat(propName, prop.name, true);
11893 MangleClassName(propName);
11895 ListAdd(args, CopyExpression(object));
11896 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11897 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
11898 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
11901 Compiler_Error($"Property %s not found in class %s\n", prop.name, _class.fullName);
11906 FreeExpression(object);
11908 FreeExpression(watcher);
11909 FreeList(watches, FreeIdentifier);
11912 Compiler_Error($"Invalid object specified and not inside a class\n");
11915 Compiler_Error($"No observer specified and not inside a class\n");
11922 static void ProcessFunction(FunctionDefinition function)
11924 Identifier id = GetDeclId(function.declarator);
11925 Symbol symbol = function.declarator ? function.declarator.symbol : null;
11926 Type type = symbol ? symbol.type : null;
11927 Class oldThisClass = thisClass;
11928 Context oldTopContext = topContext;
11930 yylloc = function.loc;
11931 // Process thisClass
11933 if(type && type.thisClass)
11935 Symbol classSym = type.thisClass;
11936 Class _class = type.thisClass.registered;
11937 char className[1024];
11938 char structName[1024];
11939 Declarator funcDecl;
11942 bool typedObject = false;
11944 if(_class && !_class.base)
11946 _class = currentClass;
11947 if(_class && !_class.symbol)
11948 _class.symbol = FindClass(_class.fullName);
11949 classSym = _class ? _class.symbol : null;
11950 typedObject = true;
11953 thisClass = _class;
11955 if(inCompiler && _class)
11957 if(type.kind == functionType)
11959 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
11961 //TypeName param = symbol.type.params.first;
11962 Type param = symbol.type.params.first;
11963 symbol.type.params.Remove(param);
11964 //FreeTypeName(param);
11967 if(type.classObjectType != classPointer)
11969 symbol.type.params.Insert(null, MkClassType(_class.fullName));
11970 symbol.type.staticMethod = true;
11971 symbol.type.thisClass = null;
11973 // HIGH DANGER: VERIFYING THIS...
11974 symbol.type.extraParam = false;
11978 strcpy(className, "__ecereClass_");
11979 FullClassNameCat(className, _class.fullName, true);
11981 MangleClassName(className);
11984 FullClassNameCat(structName, _class.fullName, false);
11989 funcDecl = GetFuncDecl(function.declarator);
11992 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
11994 TypeName param = funcDecl.function.parameters->first;
11995 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
11997 funcDecl.function.parameters->Remove(param);
11998 FreeTypeName(param);
12002 // DANGER: Watch for this... Check if it's a Conversion?
12003 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12005 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12006 if(!function.propertyNoThis)
12008 TypeName thisParam;
12010 if(type.classObjectType != classPointer)
12012 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12013 if(!funcDecl.function.parameters)
12014 funcDecl.function.parameters = MkList();
12015 funcDecl.function.parameters->Insert(null, thisParam);
12020 if(type.classObjectType != classPointer)
12022 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12023 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12026 thisParam = TypeName
12028 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12029 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12031 funcDecl.function.parameters->Insert(null, thisParam);
12036 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12038 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12039 funcDecl = GetFuncDecl(initDecl.declarator);
12042 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12044 TypeName param = funcDecl.function.parameters->first;
12045 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12047 funcDecl.function.parameters->Remove(param);
12048 FreeTypeName(param);
12052 if(type.classObjectType != classPointer)
12054 // DANGER: Watch for this... Check if it's a Conversion?
12055 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12057 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12059 if(!funcDecl.function.parameters)
12060 funcDecl.function.parameters = MkList();
12061 funcDecl.function.parameters->Insert(null, thisParam);
12068 // Add this to the context
12071 if(type.classObjectType != classPointer)
12073 thisSymbol = Symbol
12075 string = CopyString("this");
12076 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12078 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12080 if(typedObject && thisSymbol.type)
12082 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12083 thisSymbol.type.byReference = type.byReference;
12084 thisSymbol.type.typedByReference = type.byReference;
12086 thisSymbol = Symbol { string = CopyString("class") };
12087 function.body.compound.context.symbols.Add(thisSymbol);
12093 // Pointer to class data
12095 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12097 DataMember member = null;
12100 for(base = _class; base && base.type != systemClass; base = base.next)
12102 for(member = base.membersAndProperties.first; member; member = member.next)
12103 if(!member.isProperty)
12109 for(member = _class.membersAndProperties.first; member; member = member.next)
12110 if(!member.isProperty)
12114 char pointerName[1024];
12117 Initializer initializer;
12118 Expression exp, bytePtr;
12120 strcpy(pointerName, "__ecerePointer_");
12121 FullClassNameCat(pointerName, _class.fullName, false);
12123 char className[1024];
12124 strcpy(className, "__ecereClass_");
12125 FullClassNameCat(className, classSym.string, true);
12126 MangleClassName(className);
12129 DeclareClass(classSym, className);
12133 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12138 sprintf(string, "%d", _class.offset);
12139 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12143 // ([bytePtr] + [className]->offset)
12144 exp = QBrackets(MkExpOp(bytePtr, '+',
12145 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12148 // (this ? [exp] : 0)
12149 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12153 kind = pointerType;
12154 type = Type { refCount = 1, kind = voidType };
12159 yylloc = function.body.loc;
12160 // ([structName] *) [exp]
12161 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12162 initializer = MkInitializerAssignment(
12163 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12165 // [structName] * [pointerName] = [initializer];
12166 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12169 Context prevContext = curContext;
12170 curContext = function.body.compound.context;
12172 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12173 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12175 curContext = prevContext;
12179 decl.symbol = null;
12181 if(!function.body.compound.declarations)
12182 function.body.compound.declarations = MkList();
12183 function.body.compound.declarations->Insert(null, decl);
12189 // Loop through the function and replace undeclared identifiers
12190 // which are a member of the class (methods, properties or data)
12191 // by "this.[member]"
12198 FreeSpecifier(id._class);
12201 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12203 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12204 id = GetDeclId(initDecl.declarator);
12206 FreeSpecifier(id._class);
12211 topContext = function.body.compound.context;
12213 FunctionDefinition oldFunction = curFunction;
12214 curFunction = function;
12216 ProcessStatement(function.body);
12218 // If this is a property set and no firewatchers has been done yet, add one here
12219 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12221 Statement prevCompound = curCompound;
12222 Context prevContext = curContext;
12224 Statement fireWatchers = MkFireWatchersStmt(null, null);
12225 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12226 ListAdd(function.body.compound.statements, fireWatchers);
12228 curCompound = function.body;
12229 curContext = function.body.compound.context;
12231 ProcessStatement(fireWatchers);
12233 curContext = prevContext;
12234 curCompound = prevCompound;
12238 curFunction = oldFunction;
12241 if(function.declarator)
12243 ProcessDeclarator(function.declarator);
12246 topContext = oldTopContext;
12247 thisClass = oldThisClass;
12250 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12251 static void ProcessClass(OldList definitions, Symbol symbol)
12254 External external = curExternal;
12255 Class regClass = symbol ? symbol.registered : null;
12257 // Process all functions
12258 for(def = definitions.first; def; def = def.next)
12260 if(def.type == functionClassDef)
12262 if(def.function.declarator)
12263 curExternal = def.function.declarator.symbol.pointerExternal;
12265 curExternal = external;
12267 ProcessFunction((FunctionDefinition)def.function);
12269 else if(def.type == declarationClassDef)
12271 if(def.decl.type == instDeclaration)
12273 thisClass = regClass;
12274 ProcessInstantiationType(def.decl.inst);
12280 Class backThisClass = thisClass;
12281 if(regClass) thisClass = regClass;
12282 ProcessDeclaration(def.decl);
12283 thisClass = backThisClass;
12286 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12288 MemberInit defProperty;
12290 // Add this to the context
12291 Symbol thisSymbol = Symbol
12293 string = CopyString("this");
12294 type = regClass ? MkClassType(regClass.fullName) : null;
12296 globalContext.symbols.Add((BTNode)thisSymbol);
12298 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12300 thisClass = regClass;
12301 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12305 globalContext.symbols.Remove((BTNode)thisSymbol);
12306 FreeSymbol(thisSymbol);
12308 else if(def.type == propertyClassDef && def.propertyDef)
12310 PropertyDef prop = def.propertyDef;
12312 // Add this to the context
12314 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12315 globalContext.symbols.Add(thisSymbol);
12318 thisClass = regClass;
12325 string = CopyString("this");
12326 type = MkClassType(regClass.fullName);
12328 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12331 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12332 ProcessStatement(prop.setStmt);
12340 string = CopyString("this");
12341 type = MkClassType(regClass.fullName);
12343 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12346 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12347 ProcessStatement(prop.getStmt);
12355 string = CopyString("this");
12356 type = MkClassType(regClass.fullName);
12358 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12361 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12362 ProcessStatement(prop.issetStmt);
12368 globalContext.symbols.Remove(thisSymbol);
12369 FreeSymbol(thisSymbol);
12372 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12374 PropertyWatch propertyWatch = def.propertyWatch;
12376 thisClass = regClass;
12377 if(propertyWatch.compound)
12381 string = CopyString("this");
12382 type = regClass ? MkClassType(regClass.fullName) : null;
12385 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12387 curExternal = null;
12388 ProcessStatement(propertyWatch.compound);
12395 void DeclareFunctionUtil(String s)
12397 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12402 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12403 strcpy(name, "__ecereFunction_");
12404 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12405 DeclareFunction(function, name);
12409 void ComputeDataTypes()
12413 External after = null;
12415 currentClass = null;
12417 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12419 for(external = ast->first; external; external = external.next)
12421 if(external.type == declarationExternal)
12423 Declaration decl = external.declaration;
12426 OldList * decls = decl.declarators;
12429 InitDeclarator initDecl = decls->first;
12432 Declarator declarator = initDecl.declarator;
12433 if(declarator && declarator.type == identifierDeclarator)
12435 Identifier id = declarator.identifier;
12436 if(id && id.string)
12438 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12440 external.symbol.id = -1001, external.symbol.idCode = -1001;
12451 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12452 ast->Insert(after, temp);
12453 curExternal = temp;
12455 DeclareFunctionUtil("eSystem_New");
12456 DeclareFunctionUtil("eSystem_New0");
12457 DeclareFunctionUtil("eSystem_Renew");
12458 DeclareFunctionUtil("eSystem_Renew0");
12459 DeclareFunctionUtil("eSystem_Delete");
12460 DeclareFunctionUtil("eClass_GetProperty");
12461 DeclareFunctionUtil("eInstance_FireSelfWatchers");
12463 DeclareStruct("ecere::com::Class", false);
12464 DeclareStruct("ecere::com::Instance", false);
12465 DeclareStruct("ecere::com::Property", false);
12466 DeclareStruct("ecere::com::DataMember", false);
12467 DeclareStruct("ecere::com::Method", false);
12468 DeclareStruct("ecere::com::SerialBuffer", false);
12469 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12473 for(external = ast->first; external; external = external.next)
12475 afterExternal = curExternal = external;
12476 if(external.type == functionExternal)
12478 currentClass = external.function._class;
12479 ProcessFunction(external.function);
12481 // There shouldn't be any _class member access here anyways...
12482 else if(external.type == declarationExternal)
12484 currentClass = null;
12485 ProcessDeclaration(external.declaration);
12487 else if(external.type == classExternal)
12489 ClassDefinition _class = external._class;
12490 currentClass = external.symbol.registered;
12491 if(_class.definitions)
12493 ProcessClass(_class.definitions, _class.symbol);
12497 // Free class data...
12498 ast->Remove(external);
12502 else if(external.type == nameSpaceExternal)
12504 thisNameSpace = external.id.string;
12507 currentClass = null;
12508 thisNameSpace = null;
12510 delete temp.symbol;