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)
50 bool backOutputLineNumbers = outputLineNumbers;
51 outputLineNumbers = false;
54 OutputExpression(exp, f);
56 count = strlen(string);
57 count += f.Read(string + count, 1, 1023);
61 outputLineNumbers = backOutputLineNumbers;
65 Type ProcessTemplateParameterType(TemplateParameter param)
67 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
69 // TOFIX: Will need to free this Type
72 if(param.dataTypeString)
73 param.baseType = ProcessTypeString(param.dataTypeString, false);
75 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
77 return param.baseType;
82 bool NeedCast(Type type1, Type type2)
84 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
86 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
91 if(type1.kind == type2.kind)
102 if(type1.passAsTemplate && !type2.passAsTemplate)
104 return type1.isSigned != type2.isSigned;
106 return type1._class != type2._class;
108 return (type1.type && type2.type && type1.type.constant != type2.type.constant) || NeedCast(type1.type, type2.type);
110 return true; //false; ????
116 static void ReplaceClassMembers(Expression exp, Class _class)
118 if(exp.type == identifierExp && exp.identifier)
120 Identifier id = exp.identifier;
122 Symbol symbol = null;
123 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
125 // First, check if the identifier is declared inside the function
126 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
128 symbol = (Symbol)ctx.symbols.FindString(id.string);
133 // If it is not, check if it is a member of the _class
134 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
136 Property prop = eClass_FindProperty(_class, id.string, privateModule);
137 Method method = null;
138 DataMember member = null;
139 ClassProperty classProp = null;
142 method = eClass_FindMethod(_class, id.string, privateModule);
145 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
146 if(!prop && !method && !member)
148 classProp = eClass_FindClassProperty(_class, id.string);
150 if(prop || method || member || classProp)
152 // Replace by this.[member]
153 exp.type = memberExp;
154 exp.member.member = id;
155 exp.member.memberType = unresolvedMember;
156 exp.member.exp = QMkExpId("this");
157 //exp.member.exp.loc = exp.loc;
158 exp.addedThis = true;
160 else if(_class && _class.templateParams.first)
163 for(sClass = _class; sClass; sClass = sClass.base)
165 if(sClass.templateParams.first)
167 ClassTemplateParameter param;
168 for(param = sClass.templateParams.first; param; param = param.next)
170 if(param.type == expression && !strcmp(param.name, id.string))
172 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
177 OldList * specs = MkList();
179 FreeIdentifier(exp.member.member);
181 ProcessExpressionType(argExp);
183 decl = SpecDeclFromString(param.dataTypeString, specs, null);
185 exp.expType = ProcessType(specs, decl);
187 // *[expType] *[argExp]
188 exp.type = bracketsExp;
189 exp.list = MkListOne(MkExpOp(null, '*',
190 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
201 ////////////////////////////////////////////////////////////////////////
202 // PRINTING ////////////////////////////////////////////////////////////
203 ////////////////////////////////////////////////////////////////////////
205 public char * PrintInt(int64 result)
209 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
211 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
212 if(result > MAXINT || result < MININT)
214 return CopyString(temp);
217 public char * PrintUInt(uint64 result)
220 if(result > MAXDWORD)
221 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
222 else if(result > MAXINT)
223 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
225 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
226 return CopyString(temp);
229 public char * PrintInt64(int64 result)
232 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
233 return CopyString(temp);
236 public char * PrintUInt64(uint64 result)
239 if(result > MAXINT64)
240 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
242 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
243 return CopyString(temp);
246 public char * PrintHexUInt(uint64 result)
249 if(result > MAXDWORD)
250 sprintf(temp, FORMAT64HEX /*"0x%I64xLL"*/, result);
252 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
253 if(result > MAXDWORD)
255 return CopyString(temp);
258 public char * PrintHexUInt64(uint64 result)
261 if(result > MAXDWORD)
262 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
264 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
265 return CopyString(temp);
268 public char * PrintShort(short result)
271 sprintf(temp, "%d", (unsigned short)result);
272 return CopyString(temp);
275 public char * PrintUShort(unsigned short result)
279 sprintf(temp, "0x%X", (int)result);
281 sprintf(temp, "%d", (int)result);
282 return CopyString(temp);
285 public char * PrintChar(char result)
288 if(result > 0 && isprint(result))
289 sprintf(temp, "'%c'", result);
291 sprintf(temp, "%d", (int)result);
293 //sprintf(temp, "%#X", result);
294 sprintf(temp, "0x%X", (unsigned char)result);
295 return CopyString(temp);
298 public char * PrintUChar(unsigned char result)
301 sprintf(temp, "0x%X", result);
302 return CopyString(temp);
305 public char * PrintFloat(float result)
311 strcpy(temp, "-inf");
315 else if(result.isNan)
318 strcpy(temp, "-nan");
323 sprintf(temp, "%.16ff", result);
324 return CopyString(temp);
327 public char * PrintDouble(double result)
333 strcpy(temp, "-inf");
337 else if(result.isNan)
340 strcpy(temp, "-nan");
345 sprintf(temp, "%.16f", result);
346 return CopyString(temp);
349 ////////////////////////////////////////////////////////////////////////
350 ////////////////////////////////////////////////////////////////////////
352 //public Operand GetOperand(Expression exp);
354 #define GETVALUE(name, t) \
355 public bool GetOp##name(Operand op2, t * value2) \
357 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
358 else if(op2.kind == intType) *value2 = (t) op2.ui; \
359 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
360 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
361 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
362 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
363 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
364 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
365 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
366 else if(op2.kind == shortType) *value2 = (t) op2.us; \
367 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
368 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
369 else if(op2.kind == floatType) *value2 = (t) op2.f; \
370 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
371 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
376 public bool Get##name(Expression exp, t * value2) \
378 Operand op2 = GetOperand(exp); \
379 return GetOp##name(op2, value2); \
382 // To help the deubugger currently not preprocessing...
385 GETVALUE(Int, HELP(int));
386 GETVALUE(UInt, HELP(unsigned int));
387 GETVALUE(Int64, HELP(int64));
388 GETVALUE(UInt64, HELP(uint64));
389 GETVALUE(IntPtr, HELP(intptr));
390 GETVALUE(UIntPtr, HELP(uintptr));
391 GETVALUE(IntSize, HELP(intsize));
392 GETVALUE(UIntSize, HELP(uintsize));
393 GETVALUE(Short, HELP(short));
394 GETVALUE(UShort, HELP(unsigned short));
395 GETVALUE(Char, HELP(char));
396 GETVALUE(UChar, HELP(unsigned char));
397 GETVALUE(Float, HELP(float));
398 GETVALUE(Double, HELP(double));
400 void ComputeExpression(Expression exp);
402 void ComputeClassMembers(Class _class, bool isMember)
404 DataMember member = isMember ? (DataMember) _class : null;
405 Context context = isMember ? null : SetupTemplatesContext(_class);
406 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
407 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
409 int unionMemberOffset = 0;
413 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
414 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
419 member.memberOffset = 0;
420 if(targetBits < sizeof(void *) * 8)
421 member.structAlignment = 0;
423 else if(targetBits < sizeof(void *) * 8)
424 _class.structAlignment = 0;
426 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
427 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
428 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
430 if(!member && _class.destructionWatchOffset)
431 _class.memberOffset += sizeof(OldList);
433 // To avoid reentrancy...
434 //_class.structSize = -1;
437 DataMember dataMember;
438 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
440 if(!dataMember.isProperty)
442 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
444 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
445 /*if(!dataMember.dataType)
446 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
454 DataMember dataMember;
455 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
457 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
459 if(!isMember && _class.type == bitClass && dataMember.dataType)
461 BitMember bitMember = (BitMember) dataMember;
465 ComputeTypeSize(dataMember.dataType);
467 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
468 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
470 _class.memberOffset = bitMember.pos + bitMember.size;
471 for(d = 0; d<bitMember.size; d++)
477 bitMember.mask = mask << bitMember.pos;
479 else if(dataMember.type == normalMember && dataMember.dataType)
484 // Prevent infinite recursion
485 if(dataMember.dataType.kind != classType ||
486 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
487 _class.type != structClass)))
488 ComputeTypeSize(dataMember.dataType);
490 if(dataMember.dataType.bitFieldCount)
492 bitFields += dataMember.dataType.bitFieldCount;
499 int size = (bitFields + 7) / 8;
503 // TESTING THIS PADDING CODE
506 member.structAlignment = Max(member.structAlignment, alignment);
508 if(member.memberOffset % alignment)
509 member.memberOffset += alignment - (member.memberOffset % alignment);
512 dataMember.offset = member.memberOffset;
513 if(member.type == unionMember)
514 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
517 member.memberOffset += size;
522 // TESTING THIS PADDING CODE
525 _class.structAlignment = Max(_class.structAlignment, alignment);
527 if(_class.memberOffset % alignment)
528 _class.memberOffset += alignment - (_class.memberOffset % alignment);
531 dataMember.offset = _class.memberOffset;
532 _class.memberOffset += size;
536 size = dataMember.dataType.size;
537 alignment = dataMember.dataType.alignment;
542 // TESTING THIS PADDING CODE
545 member.structAlignment = Max(member.structAlignment, alignment);
547 if(member.memberOffset % alignment)
548 member.memberOffset += alignment - (member.memberOffset % alignment);
551 dataMember.offset = member.memberOffset;
552 if(member.type == unionMember)
553 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
556 member.memberOffset += size;
561 // TESTING THIS PADDING CODE
564 _class.structAlignment = Max(_class.structAlignment, alignment);
566 if(_class.memberOffset % alignment)
567 _class.memberOffset += alignment - (_class.memberOffset % alignment);
570 dataMember.offset = _class.memberOffset;
571 _class.memberOffset += size;
578 ComputeClassMembers((Class)dataMember, true);
579 alignment = dataMember.structAlignment;
585 if(member.memberOffset % alignment)
586 member.memberOffset += alignment - (member.memberOffset % alignment);
588 member.structAlignment = Max(member.structAlignment, alignment);
590 dataMember.offset = member.memberOffset;
591 if(member.type == unionMember)
592 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
594 member.memberOffset += dataMember.memberOffset;
600 if(_class.memberOffset % alignment)
601 _class.memberOffset += alignment - (_class.memberOffset % alignment);
602 _class.structAlignment = Max(_class.structAlignment, alignment);
604 dataMember.offset = _class.memberOffset;
605 _class.memberOffset += dataMember.memberOffset;
613 int size = (bitFields + 7) / 8;
617 // TESTING THIS PADDING CODE
620 member.structAlignment = Max(member.structAlignment, alignment);
622 if(member.memberOffset % alignment)
623 member.memberOffset += alignment - (member.memberOffset % alignment);
626 if(member.type == unionMember)
627 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
630 member.memberOffset += size;
635 // TESTING THIS PADDING CODE
638 _class.structAlignment = Max(_class.structAlignment, alignment);
640 if(_class.memberOffset % alignment)
641 _class.memberOffset += alignment - (_class.memberOffset % alignment);
643 _class.memberOffset += size;
648 if(member && member.type == unionMember)
650 member.memberOffset = unionMemberOffset;
655 /*if(_class.type == structClass)
656 _class.size = _class.memberOffset;
660 if(_class.type != bitClass)
663 if(_class.structAlignment)
665 if(_class.memberOffset % _class.structAlignment)
666 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
668 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
672 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
674 if(prop.isProperty && prop.isWatchable)
676 prop.watcherOffset = _class.structSize;
677 _class.structSize += sizeof(OldList);
685 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
687 Class deriv = derivative.data;
689 if(deriv.computeSize)
691 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
692 deriv.offset = /*_class.offset + */_class.structSize;
693 deriv.memberOffset = 0;
694 // ----------------------
696 deriv.structSize = deriv.offset;
698 ComputeClassMembers(deriv, false);
706 FinishTemplatesContext(context);
709 public void ComputeModuleClasses(Module module)
714 for(subModule = module.modules.first; subModule; subModule = subModule.next)
715 ComputeModuleClasses(subModule.data);
716 for(_class = module.classes.first; _class; _class = _class.next)
717 ComputeClassMembers(_class, false);
721 public int ComputeTypeSize(Type type)
723 uint size = type ? type.size : 0;
724 if(!size && type && !type.computing)
726 type.computing = true;
729 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
730 case charType: type.alignment = size = sizeof(char); break;
731 case intType: type.alignment = size = sizeof(int); break;
732 case int64Type: type.alignment = size = sizeof(int64); break;
733 case intPtrType: type.alignment = size = targetBits / 8; break;
734 case intSizeType: type.alignment = size = targetBits / 8; break;
735 case longType: type.alignment = size = sizeof(long); break;
736 case shortType: type.alignment = size = sizeof(short); break;
737 case floatType: type.alignment = size = sizeof(float); break;
738 case doubleType: type.alignment = size = sizeof(double); break;
741 Class _class = type._class ? type._class.registered : null;
743 if(_class && _class.type == structClass)
745 // Ensure all members are properly registered
746 ComputeClassMembers(_class, false);
747 type.alignment = _class.structAlignment;
748 size = _class.structSize;
749 if(type.alignment && size % type.alignment)
750 size += type.alignment - (size % type.alignment);
753 else if(_class && (_class.type == unitClass ||
754 _class.type == enumClass ||
755 _class.type == bitClass))
758 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
759 size = type.alignment = ComputeTypeSize(_class.dataType);
762 size = type.alignment = targetBits / 8; // sizeof(Instance *);
765 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
767 if(type.arraySizeExp)
769 ProcessExpressionType(type.arraySizeExp);
770 ComputeExpression(type.arraySizeExp);
771 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType &&
772 type.arraySizeExp.expType.kind != shortType &&
773 type.arraySizeExp.expType.kind != charType &&
774 type.arraySizeExp.expType.kind != longType &&
775 type.arraySizeExp.expType.kind != int64Type &&
776 type.arraySizeExp.expType.kind != intSizeType &&
777 type.arraySizeExp.expType.kind != intPtrType &&
778 type.arraySizeExp.expType.kind != enumType &&
779 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
781 Location oldLoc = yylloc;
782 // bool isConstant = type.arraySizeExp.isConstant;
783 char expression[10240];
784 expression[0] = '\0';
785 type.arraySizeExp.expType = null;
786 yylloc = type.arraySizeExp.loc;
788 PrintExpression(type.arraySizeExp, expression);
789 Compiler_Error($"Array size not constant int (%s)\n", expression);
792 GetInt(type.arraySizeExp, &type.arraySize);
794 else if(type.enumClass)
796 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
798 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
805 // Unimplemented auto size
809 size = ComputeTypeSize(type.type) * type.arraySize;
811 type.alignment = type.type.alignment;
817 for(member = type.members.first; member; member = member.next)
819 uint addSize = ComputeTypeSize(member);
821 member.offset = size;
822 if(member.alignment && size % member.alignment)
823 member.offset += member.alignment - (size % member.alignment);
824 size = member.offset;
826 type.alignment = Max(type.alignment, member.alignment);
829 if(type.alignment && size % type.alignment)
830 size += type.alignment - (size % type.alignment);
836 for(member = type.members.first; member; member = member.next)
838 uint addSize = ComputeTypeSize(member);
840 member.offset = size;
841 if(member.alignment && size % member.alignment)
842 member.offset += member.alignment - (size % member.alignment);
843 size = member.offset;
845 type.alignment = Max(type.alignment, member.alignment);
846 size = Max(size, addSize);
848 if(type.alignment && size % type.alignment)
849 size += type.alignment - (size % type.alignment);
854 TemplateParameter param = type.templateParameter;
855 Type baseType = ProcessTemplateParameterType(param);
858 size = ComputeTypeSize(baseType);
859 type.alignment = baseType.alignment;
862 type.alignment = size = sizeof(uint64);
867 type.alignment = size = sizeof(enum { test });
872 type.alignment = size = targetBits / 8; //sizeof(void *);
877 type.computing = false;
883 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
885 // This function is in need of a major review when implementing private members etc.
886 DataMember topMember = isMember ? (DataMember) _class : null;
893 Context context = isMember ? null : SetupTemplatesContext(_class);
895 *addedPadding = false;
897 if(!isMember && _class.base)
899 maxSize = _class.structSize;
900 //if(_class.base.type != systemClass) // Commented out with new Instance _class
902 // DANGER: Testing this noHeadClass here...
903 if(_class.type == structClass || _class.type == noHeadClass)
904 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
907 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
908 if(maxSize > baseSize)
916 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
918 if(!member.isProperty)
924 if(member.dataTypeString)
926 OldList * specs = MkList(), * decls = MkList();
929 decl = SpecDeclFromString(member.dataTypeString, specs,
930 MkDeclaratorIdentifier(MkIdentifier(member.name)));
931 ListAdd(decls, MkStructDeclarator(decl, null));
932 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
935 member.dataType = ProcessType(specs, decl);
937 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
940 Type type = ProcessType(specs, decl);
941 DeclareType(member.dataType, false, false);
945 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
946 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
947 DeclareStruct(member.dataType._class.string, false);
950 ComputeTypeSize(member.dataType);
951 size = member.dataType.size;
952 alignment = member.dataType.alignment;
956 if(totalSize % alignment)
957 totalSize += alignment - (totalSize % alignment);
966 OldList * specs = MkList(), * list = MkList();
968 sprintf(id, "__anon%d", anonID++);
971 AddMembers(list, (Class)member, true, &size, topClass, null);
973 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
974 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, MkListOne(MkDeclaratorIdentifier(MkIdentifier(id))),null)));
975 alignment = member.structAlignment;
979 if(totalSize % alignment)
980 totalSize += alignment - (totalSize % alignment);
990 if(topMember && topMember.type == unionMember)
991 *retSize = Max(*retSize, totalSize);
993 *retSize += totalSize;
995 else if(totalSize < maxSize && _class.type != systemClass)
998 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
999 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
1000 if(totalSize + autoPadding < maxSize)
1002 char sizeString[50];
1003 sprintf(sizeString, "%d", maxSize - totalSize);
1004 ListAdd(declarations,
1005 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1006 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1008 *addedPadding = true;
1012 FinishTemplatesContext(context);
1013 return topMember ? topMember.memberID : _class.memberID;
1016 static int DeclareMembers(Class _class, bool isMember)
1018 DataMember topMember = isMember ? (DataMember) _class : null;
1020 Context context = isMember ? null : SetupTemplatesContext(_class);
1022 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1023 DeclareMembers(_class.base, false);
1025 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1027 if(!member.isProperty)
1034 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1035 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1036 DeclareStruct(member.dataType._class.string, false);
1038 if(!member.dataType && member.dataTypeString)
1039 member.dataType = ProcessTypeString(member.dataTypeString, false);
1041 DeclareType(member.dataType, false, false);
1047 DeclareMembers((Class)member, true);
1054 FinishTemplatesContext(context);
1056 return topMember ? topMember.memberID : _class.memberID;
1059 static void IdentifyAnonStructs(OldList/*<ClassDef>*/ * definitions)
1063 for(def = definitions->first; def; def = def.next)
1065 if(def.type == declarationClassDef)
1067 Declaration decl = def.decl;
1068 if(decl && decl.specifiers)
1071 bool isStruct = false;
1072 for(spec = decl.specifiers->first; spec; spec = spec.next)
1074 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1076 if(spec.definitions)
1077 IdentifyAnonStructs(spec.definitions);
1083 Declarator d = null;
1084 if(decl.declarators)
1086 for(d = decl.declarators->first; d; d = d.next)
1088 Identifier idDecl = GetDeclId(d);
1096 sprintf(id, "__anon%d", anonID++);
1097 if(!decl.declarators)
1098 decl.declarators = MkList();
1099 ListAdd(decl.declarators, MkDeclaratorIdentifier(MkIdentifier(id)));
1107 void DeclareStruct(const char * name, bool skipNoHead)
1109 External external = null;
1110 Symbol classSym = FindClass(name);
1112 if(!inCompiler || !classSym) return;
1114 // We don't need any declaration for bit classes...
1115 if(classSym.registered &&
1116 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1119 /*if(classSym.registered.templateClass)
1120 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1123 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1125 // Add typedef struct
1127 OldList * specifiers, * declarators;
1128 OldList * declarations = null;
1129 char structName[1024];
1130 Specifier spec = null;
1131 external = (classSym.registered && classSym.registered.type == structClass) ?
1132 classSym.pointerExternal : classSym.structExternal;
1134 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1135 // Moved this one up because DeclareClass done later will need it
1137 classSym.declaring++;
1139 if(strchr(classSym.string, '<'))
1141 if(classSym.registered.templateClass)
1143 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1144 classSym.declaring--;
1150 DeclareMembers(classSym.registered, false);
1153 FullClassNameCat(structName, name, false);
1155 if(external && external.declaration && external.declaration.specifiers)
1157 for(spec = external.declaration.specifiers->first; spec; spec = spec.next)
1159 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1165 external = MkExternalDeclaration(null);*/
1167 if(!skipNoHead && (!spec || !spec.definitions))
1169 bool addedPadding = false;
1170 classSym.declaredStructSym = true;
1172 declarations = MkList();
1174 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1176 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1177 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1179 if(!declarations->count || (declarations->count == 1 && addedPadding))
1181 FreeList(declarations, FreeClassDef);
1182 declarations = null;
1185 if(skipNoHead || declarations)
1190 spec.definitions = declarations;
1192 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1195 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1198 if(classSym.structExternal)
1199 ast->Move(classSym.structExternal, curExternal.prev);
1200 ast->Move(classSym.pointerExternal, curExternal.prev);
1202 classSym.id = curExternal.symbol.idCode;
1203 classSym.idCode = curExternal.symbol.idCode;
1204 // external = classSym.pointerExternal;
1205 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1211 external = MkExternalDeclaration(null);
1213 specifiers = MkList();
1214 declarators = MkList();
1215 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1218 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1219 ListAdd(declarators, MkInitDeclarator(d, null));
1221 external.declaration = decl = MkDeclaration(specifiers, declarators);
1222 if(decl.symbol && !decl.symbol.pointerExternal)
1223 decl.symbol.pointerExternal = external;
1225 // For simple classes, keep the declaration as the external to move around
1226 if(classSym.registered && classSym.registered.type == structClass)
1228 char className[1024];
1229 strcpy(className, "__ecereClass_");
1230 FullClassNameCat(className, classSym.string, true);
1231 //MangleClassName(className);
1234 DeclareClass(classSym, className);
1236 external.symbol = classSym;
1237 classSym.pointerExternal = external;
1238 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1239 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1243 char className[1024];
1244 strcpy(className, "__ecereClass_");
1245 FullClassNameCat(className, classSym.string, true);
1246 //MangleClassName(className);
1248 // TOFIX: TESTING THIS...
1249 classSym.structExternal = external;
1250 DeclareClass(classSym, className);
1251 external.symbol = classSym;
1255 ast->Insert(curExternal ? curExternal.prev : null, external);
1259 classSym.declaring--;
1263 if(classSym.structExternal && classSym.structExternal.declaration && classSym.structExternal.declaration.specifiers)
1266 for(spec = classSym.structExternal.declaration.specifiers->first; spec; spec = spec.next)
1268 IdentifyAnonStructs(spec.definitions);
1272 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1274 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1275 // Moved this one up because DeclareClass done later will need it
1278 classSym.declaring++;
1282 if(classSym.registered)
1283 DeclareMembers(classSym.registered, false);
1286 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1289 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1292 if(classSym.structExternal)
1293 ast->Move(classSym.structExternal, curExternal.prev);
1294 ast->Move(classSym.pointerExternal, curExternal.prev);
1296 classSym.id = curExternal.symbol.idCode;
1297 classSym.idCode = curExternal.symbol.idCode;
1298 // external = classSym.pointerExternal;
1299 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1302 classSym.declaring--;
1308 void DeclareProperty(Property prop, char * setName, char * getName)
1310 Symbol symbol = prop.symbol;
1312 strcpy(setName, "__ecereProp_");
1313 FullClassNameCat(setName, prop._class.fullName, false);
1314 strcat(setName, "_Set_");
1315 // strcat(setName, prop.name);
1316 FullClassNameCat(setName, prop.name, true);
1317 //MangleClassName(setName);
1319 strcpy(getName, "__ecereProp_");
1320 FullClassNameCat(getName, prop._class.fullName, false);
1321 strcat(getName, "_Get_");
1322 FullClassNameCat(getName, prop.name, true);
1323 // strcat(getName, prop.name);
1325 // To support "char *" property
1326 //MangleClassName(getName);
1328 if(prop._class.type == structClass)
1329 DeclareStruct(prop._class.fullName, false);
1331 if(!symbol || curExternal.symbol.idCode < symbol.id)
1333 bool imported = false;
1334 bool dllImport = false;
1336 if(!symbol || symbol._import)
1341 if(!prop._class.symbol)
1342 prop._class.symbol = FindClass(prop._class.fullName);
1343 classSym = prop._class.symbol;
1344 if(classSym && !classSym._import)
1346 ModuleImport module;
1348 if(prop._class.module)
1349 module = FindModule(prop._class.module);
1351 module = mainModule;
1353 classSym._import = ClassImport
1355 name = CopyString(prop._class.fullName);
1356 isRemote = prop._class.isRemote;
1358 module.classes.Add(classSym._import);
1360 symbol = prop.symbol = Symbol { };
1361 symbol._import = (ClassImport)PropertyImport
1363 name = CopyString(prop.name);
1364 isVirtual = false; //prop.isVirtual;
1365 hasSet = prop.Set ? true : false;
1366 hasGet = prop.Get ? true : false;
1369 classSym._import.properties.Add(symbol._import);
1372 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1373 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1374 prop._class.module.importType != staticImport)
1380 Context context = SetupTemplatesContext(prop._class);
1381 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1382 FinishTemplatesContext(context);
1388 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1391 OldList * specifiers, * declarators;
1396 Declarator typeDecl;
1397 bool simple = false;
1399 specifiers = MkList();
1400 declarators = MkList();
1403 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1404 MkDeclaratorIdentifier(MkIdentifier("this"))));
1406 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1409 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1412 Context context = SetupTemplatesContext(prop._class);
1413 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1414 FinishTemplatesContext(context);
1417 // Make sure the simple _class's type is declared
1418 for(spec = specifiers->first; spec; spec = spec.next)
1420 if(spec.type == nameSpecifier /*SpecifierClass*/)
1422 if((!typeDecl || typeDecl.type == identifierDeclarator))
1424 Symbol classSym = spec.symbol; // FindClass(spec.name);
1425 symbol._class = classSym.registered;
1426 if(classSym.registered && classSym.registered.type == structClass)
1428 DeclareStruct(spec.name, false);
1436 d = PlugDeclarator(typeDecl, d);
1439 ListAdd(params, MkTypeName(specifiers,
1440 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1441 specifiers = MkList();
1444 d = MkDeclaratorFunction(d, params);
1448 specifiers->Insert(null, MkSpecifier(EXTERN));
1449 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1450 specifiers->Insert(null, MkSpecifier(STATIC));
1452 ListAdd(specifiers, MkSpecifier(VOID));
1454 ListAdd(declarators, MkInitDeclarator(d, null));
1456 decl = MkDeclaration(specifiers, declarators);
1458 external = MkExternalDeclaration(decl);
1459 ast->Insert(curExternal.prev, external);
1460 external.symbol = symbol;
1461 symbol.externalGet = external;
1463 ReplaceThisClassSpecifiers(specifiers, prop._class);
1466 FreeDeclarator(typeDecl);
1470 // Move declaration higher...
1471 ast->Move(symbol.externalGet, curExternal.prev);
1478 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1481 OldList * specifiers, * declarators;
1486 Declarator typeDecl;
1488 declarators = MkList();
1491 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1492 if(!prop.conversion || prop._class.type == structClass)
1494 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1495 MkDeclaratorIdentifier(MkIdentifier("this"))));
1498 specifiers = MkList();
1501 Context context = SetupTemplatesContext(prop._class);
1502 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1503 MkDeclaratorIdentifier(MkIdentifier("value")));
1504 FinishTemplatesContext(context);
1506 if(!strcmp(prop._class.base.fullName, "eda::Row") || !strcmp(prop._class.base.fullName, "eda::Id"))
1507 specifiers->Insert(null, MkSpecifier(CONST));
1509 ListAdd(params, MkTypeName(specifiers, d));
1511 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1514 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1515 d = MkDeclaratorFunction(d, params);
1517 // Make sure the simple _class's type is declared
1518 for(spec = specifiers->first; spec; spec = spec.next)
1520 if(spec.type == nameSpecifier /*SpecifierClass*/)
1522 if((!typeDecl || typeDecl.type == identifierDeclarator))
1524 Symbol classSym = spec.symbol; // FindClass(spec.name);
1525 symbol._class = classSym.registered;
1526 if(classSym.registered && classSym.registered.type == structClass)
1527 DeclareStruct(spec.name, false);
1532 ListAdd(declarators, MkInitDeclarator(d, null));
1534 specifiers = MkList();
1537 specifiers->Insert(null, MkSpecifier(EXTERN));
1538 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1539 specifiers->Insert(null, MkSpecifier(STATIC));
1541 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1542 if(!prop.conversion || prop._class.type == structClass)
1543 ListAdd(specifiers, MkSpecifier(VOID));
1545 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1547 decl = MkDeclaration(specifiers, declarators);
1549 external = MkExternalDeclaration(decl);
1550 ast->Insert(curExternal.prev, external);
1551 external.symbol = symbol;
1552 symbol.externalSet = external;
1554 ReplaceThisClassSpecifiers(specifiers, prop._class);
1558 // Move declaration higher...
1559 ast->Move(symbol.externalSet, curExternal.prev);
1563 // Property (for Watchers)
1564 if(!symbol.externalPtr)
1568 OldList * specifiers = MkList();
1569 char propName[1024];
1572 specifiers->Insert(null, MkSpecifier(EXTERN));
1574 specifiers->Insert(null, MkSpecifier(STATIC));
1576 ListAdd(specifiers, MkSpecifierName("Property"));
1578 strcpy(propName, "__ecereProp_");
1579 FullClassNameCat(propName, prop._class.fullName, false);
1580 strcat(propName, "_");
1581 FullClassNameCat(propName, prop.name, true);
1582 // strcat(propName, prop.name);
1583 //MangleClassName(propName);
1586 OldList * list = MkList();
1587 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1588 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1592 strcpy(propName, "__ecerePropM_");
1593 FullClassNameCat(propName, prop._class.fullName, false);
1594 strcat(propName, "_");
1595 // strcat(propName, prop.name);
1596 FullClassNameCat(propName, prop.name, true);
1598 //MangleClassName(propName);
1600 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1601 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1603 decl = MkDeclaration(specifiers, list);
1606 external = MkExternalDeclaration(decl);
1607 ast->Insert(curExternal.prev, external);
1608 external.symbol = symbol;
1609 symbol.externalPtr = external;
1613 // Move declaration higher...
1614 ast->Move(symbol.externalPtr, curExternal.prev);
1617 symbol.id = curExternal.symbol.idCode;
1621 // ***************** EXPRESSION PROCESSING ***************************
1622 public Type Dereference(Type source)
1627 if(source.kind == pointerType || source.kind == arrayType)
1630 source.type.refCount++;
1632 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1640 // Support dereferencing of no head classes for now...
1641 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1647 Compiler_Error($"cannot dereference type\n");
1652 static Type Reference(Type source)
1668 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1670 Identifier ident = member.identifiers ? member.identifiers->first : null;
1672 DataMember dataMember = null;
1673 Method method = null;
1674 bool freeType = false;
1676 yylloc = member.loc;
1682 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1686 dataMember = *curMember;
1692 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1693 DataMember _subMemberStack[256];
1694 int _subMemberStackPos = 0;
1696 // FILL MEMBER STACK
1698 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1701 dataMember = thisMember;
1702 if(curMember && thisMember.memberAccess == publicAccess)
1704 *curMember = thisMember;
1705 *curClass = thisMember._class;
1706 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1707 *subMemberStackPos = _subMemberStackPos;
1714 method = eClass_FindMethod(_class, ident.string, privateModule);
1715 if(method && method.type == virtualMethod)
1727 if(!dataMember.dataType && dataMember.dataTypeString)
1729 //Context context = SetupTemplatesContext(dataMember._class);
1730 Context context = SetupTemplatesContext(_class);
1731 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1732 FinishTemplatesContext(context);
1734 type = dataMember.dataType;
1738 // This is for destination type...
1739 if(!method.dataType)
1740 ProcessMethodType(method);
1741 //DeclareMethod(method);
1742 // method.dataType = ((Symbol)method.symbol)->type;
1743 type = method.dataType;
1746 if(ident && ident.next)
1748 for(ident = ident.next; ident && type; ident = ident.next)
1750 if(type.kind == classType)
1752 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1754 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1756 type = dataMember.dataType;
1758 else if(type.kind == structType || type.kind == unionType)
1761 for(memberType = type.members.first; memberType; memberType = memberType.next)
1763 if(!strcmp(memberType.name, ident.string))
1773 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1774 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1777 ClassTemplateParameter curParam = null;
1779 for(sClass = _class; sClass; sClass = sClass.base)
1782 if(sClass.templateClass) sClass = sClass.templateClass;
1783 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1785 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1787 for(sClass = sClass.base; sClass; sClass = sClass.base)
1789 if(sClass.templateClass) sClass = sClass.templateClass;
1790 id += sClass.templateParams.count;
1801 ClassTemplateArgument arg = _class.templateArgs[id];
1802 if(arg.dataTypeString)
1804 bool constant = type.constant;
1806 type = ProcessTypeString(arg.dataTypeString, false);
1807 if(type.kind == classType && constant) type.constant = true;
1808 else if(type.kind == pointerType)
1811 while(t.kind == pointerType) t = t.type;
1812 if(constant) t.constant = constant;
1815 if(type && _class.templateClass)
1816 type.passAsTemplate = true;
1822 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1823 exp.destType.refCount++;
1829 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1831 Class expClass = type._class.registered;
1832 Class cClass = null;
1836 char templateString[1024];
1837 ClassTemplateParameter param;
1838 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1839 for(cClass = expClass; cClass; cClass = cClass.base)
1842 if(cClass.templateClass) cClass = cClass.templateClass;
1843 for(param = cClass.templateParams.first; param; param = param.next)
1847 ClassTemplateArgument arg;
1848 for(sClass = cClass.base; sClass; sClass = sClass.base)
1850 if(sClass.templateClass) sClass = sClass.templateClass;
1851 id += sClass.templateParams.count;
1853 arg = expClass.templateArgs[id];
1855 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1857 ClassTemplateParameter cParam;
1858 //int p = numParams - sClass.templateParams.count;
1861 if(sClass.templateClass) sClass = sClass.templateClass;
1863 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1865 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1866 p += nextClass.templateParams.count;
1869 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1871 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1873 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1875 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1876 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1888 strcat(argument, arg.name.string);
1889 strcat(argument, " = ");
1895 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1896 char expString[1024];
1897 OldList * specs = MkList();
1898 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1900 char * string = PrintHexUInt64(arg.expression.ui64);
1901 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1904 ProcessExpressionType(exp);
1905 ComputeExpression(exp);
1906 expString[0] = '\0';
1907 PrintExpression(exp, expString);
1908 strcat(argument, expString);
1910 FreeExpression(exp);
1915 strcat(argument, arg.member.name);
1918 case TemplateParameterType::type:
1920 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1921 strcat(argument, arg.dataTypeString);
1927 if(paramCount) strcat(templateString, ", ");
1928 if(lastParam != p - 1)
1930 strcat(templateString, param.name);
1931 strcat(templateString, " = ");
1933 strcat(templateString, argument);
1942 int len = strlen(templateString);
1943 if(templateString[len-1] == '<')
1947 if(templateString[len-1] == '>')
1948 templateString[len++] = ' ';
1949 templateString[len++] = '>';
1951 templateString[len++] = '\0';
1954 Context context = SetupTemplatesContext(_class);
1955 if(freeType) FreeType(type);
1956 type = ProcessTypeString(templateString, false);
1958 FinishTemplatesContext(context);
1962 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1964 ProcessExpressionType(member.initializer.exp);
1965 if(!member.initializer.exp.expType)
1969 char expString[10240];
1970 expString[0] = '\0';
1971 PrintExpression(member.initializer.exp, expString);
1972 ChangeCh(expString, '\n', ' ');
1973 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1976 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1977 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
1979 Compiler_Error($"incompatible instance method %s\n", ident.string);
1982 else if(member.initializer)
1985 FreeType(member.exp.destType);
1986 member.exp.destType = type;
1987 if(member.exp.destType)
1988 member.exp.destType.refCount++;
1989 ProcessExpressionType(member.exp);
1992 ProcessInitializer(member.initializer, type);
1994 if(freeType) FreeType(type);
1998 if(_class && _class.type == unitClass)
2000 if(member.initializer)
2003 FreeType(member.exp.destType);
2004 member.exp.destType = MkClassType(_class.fullName);
2005 ProcessExpressionType(member.initializer, type);
2007 Type type = MkClassType(_class.fullName);
2008 ProcessInitializer(member.initializer, type);
2014 if(member.initializer)
2016 //ProcessExpressionType(member.exp);
2017 ProcessInitializer(member.initializer, null);
2023 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
2027 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
2029 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
2033 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
2038 void ProcessInstantiationType(Instantiation inst)
2043 MembersInit members;
2044 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
2047 /*if(!inst._class.symbol)
2048 inst._class.symbol = FindClass(inst._class.name);*/
2049 classSym = inst._class.symbol;
2050 _class = classSym ? classSym.registered : null;
2052 // DANGER: Patch for mutex not declaring its struct when not needed
2053 if(!_class || _class.type != noHeadClass)
2054 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
2056 afterExternal = afterExternal ? afterExternal : curExternal;
2059 ProcessExpressionType(inst.exp);
2061 inst.isConstant = true;
2064 DataMember curMember = null;
2065 Class curClass = null;
2066 DataMember subMemberStack[256];
2067 int subMemberStackPos = 0;
2069 for(members = inst.members->first; members; members = members.next)
2071 switch(members.type)
2073 case methodMembersInit:
2076 static uint instMethodID = 0;
2077 External external = curExternal;
2078 Context context = curContext;
2079 Declarator declarator = members.function.declarator;
2080 Identifier nameID = GetDeclId(declarator);
2081 char * unmangled = nameID ? nameID.string : null;
2083 External createdExternal = null;
2088 //members.function.dontMangle = true;
2089 strcpy(name, "__ecereInstMeth_");
2090 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2092 strcat(name, nameID.string);
2094 sprintf(number, "_%08d", instMethodID++);
2095 strcat(name, number);
2096 nameID.string = CopyString(name);
2099 // Do modifications here...
2102 Symbol symbol = declarator.symbol;
2103 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2105 if(method && method.type == virtualMethod)
2107 symbol.method = method;
2108 ProcessMethodType(method);
2110 if(!symbol.type.thisClass)
2112 if(method.dataType.thisClass && currentClass &&
2113 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2115 if(!currentClass.symbol)
2116 currentClass.symbol = FindClass(currentClass.fullName);
2117 symbol.type.thisClass = currentClass.symbol;
2122 _class.symbol = FindClass(_class.fullName);
2123 symbol.type.thisClass = _class.symbol;
2126 // TESTING THIS HERE:
2127 DeclareType(symbol.type, true, true);
2132 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2133 unmangled, classSym.string);
2137 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2138 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2142 FreeSpecifier(nameID._class);
2143 nameID._class = null;
2148 //Type type = declarator.symbol.type;
2149 External oldExternal = curExternal;
2151 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2152 // *** It was commented out for problems such as
2154 class VirtualDesktop : Window
2156 clientSize = Size { };
2167 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2169 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2172 if(strcmp(declarator.symbol.string, name))
2174 printf("TOCHECK: Look out for this\n");
2175 delete declarator.symbol.string;
2176 declarator.symbol.string = CopyString(name);
2179 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2181 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2182 excludedSymbols->Remove(declarator.symbol);
2183 globalContext.symbols.Add((BTNode)declarator.symbol);
2184 if(strstr(declarator.symbol.string), "::")
2185 globalContext.hasNameSpace = true;
2190 //curExternal = curExternal.prev;
2191 //afterExternal = afterExternal->next;
2193 //ProcessFunction(afterExternal->function);
2195 //curExternal = afterExternal;
2197 External externalDecl;
2198 externalDecl = MkExternalDeclaration(null);
2199 ast->Insert(oldExternal.prev, externalDecl);
2201 // Which function does this process?
2202 if(createdExternal.function)
2204 ProcessFunction(createdExternal.function);
2206 //curExternal = oldExternal;
2209 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2211 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2212 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2214 //externalDecl = MkExternalDeclaration(decl);
2216 //***** ast->Insert(external.prev, externalDecl);
2217 //ast->Insert(curExternal.prev, externalDecl);
2218 externalDecl.declaration = decl;
2219 if(decl.symbol && !decl.symbol.pointerExternal)
2220 decl.symbol.pointerExternal = externalDecl;
2222 // Trying this out...
2223 declarator.symbol.pointerExternal = externalDecl;
2230 curExternal = declarator.symbol.pointerExternal;
2231 ProcessFunction((FunctionDefinition)members.function);
2233 curExternal = external;
2234 curContext = context;
2238 FreeClassFunction(members.function);
2240 // In this pass, turn this into a MemberInitData
2241 exp = QMkExpId(name);
2242 members.type = dataMembersInit;
2243 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2249 case dataMembersInit:
2251 if(members.dataMembers && classSym)
2254 Location oldyyloc = yylloc;
2255 for(member = members.dataMembers->first; member; member = member.next)
2257 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2258 if(member.initializer && !member.initializer.isConstant)
2259 inst.isConstant = false;
2271 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2273 // OPTIMIZATIONS: TESTING THIS...
2276 if(type.kind == functionType)
2281 for(param = type.params.first; param; param = param.next)
2282 DeclareType(param, declarePointers, true);
2284 DeclareType(type.returnType, declarePointers, true);
2286 else if(type.kind == pointerType && declarePointers)
2287 DeclareType(type.type, declarePointers, false);
2288 else if(type.kind == classType)
2290 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2291 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2293 else if(type.kind == structType || type.kind == unionType)
2296 for(member = type.members.first; member; member = member.next)
2297 DeclareType(member, false, false);
2299 else if(type.kind == arrayType)
2300 DeclareType(type.arrayType, declarePointers, false);
2304 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2306 ClassTemplateArgument * arg = null;
2308 ClassTemplateParameter curParam = null;
2310 for(sClass = _class; sClass; sClass = sClass.base)
2313 if(sClass.templateClass) sClass = sClass.templateClass;
2314 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2316 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2318 for(sClass = sClass.base; sClass; sClass = sClass.base)
2320 if(sClass.templateClass) sClass = sClass.templateClass;
2321 id += sClass.templateParams.count;
2331 arg = &_class.templateArgs[id];
2332 if(arg && param.type == type)
2333 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2338 public Context SetupTemplatesContext(Class _class)
2340 Context context = PushContext();
2341 context.templateTypesOnly = true;
2342 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2344 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2345 for(; param; param = param.next)
2347 if(param.type == type && param.identifier)
2349 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2350 curContext.templateTypes.Add((BTNode)type);
2357 for(sClass = _class; sClass; sClass = sClass.base)
2359 ClassTemplateParameter p;
2360 for(p = sClass.templateParams.first; p; p = p.next)
2362 //OldList * specs = MkList();
2363 //Declarator decl = null;
2364 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2367 TemplateParameter param = p.param;
2371 // ADD DATA TYPE HERE...
2372 p.param = param = TemplateParameter
2374 identifier = MkIdentifier(p.name), type = p.type,
2375 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2378 type = TemplatedType { key = (uintptr)p.name, param = param };
2379 curContext.templateTypes.Add((BTNode)type);
2387 public void FinishTemplatesContext(Context context)
2389 PopContext(context);
2390 FreeContext(context);
2394 public void ProcessMethodType(Method method)
2396 if(!method.dataType)
2398 Context context = SetupTemplatesContext(method._class);
2400 method.dataType = ProcessTypeString(method.dataTypeString, false);
2402 FinishTemplatesContext(context);
2404 if(method.type != virtualMethod && method.dataType)
2406 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2408 if(!method._class.symbol)
2409 method._class.symbol = FindClass(method._class.fullName);
2410 method.dataType.thisClass = method._class.symbol;
2414 // Why was this commented out? Working fine without now...
2417 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2418 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2425 char * par = strstr(type, "(");
2426 char * classOp = null;
2431 for(c = par-type-1; c >= 0; c++)
2433 if(type[c] == ':' && type[c+1] == ':')
2435 classOp = type + c - 1;
2436 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2443 else if(!isspace(type[c]))
2450 int typeLen = strlen(type);
2451 memcpy(temp, classOp, classOpLen);
2452 temp[classOpLen] = '\0';
2454 _class = eSystem_FindClass(module, temp);
2457 method.dataTypeString = new char[typeLen - classOpLen + 1];
2458 memcpy(method.dataTypeString, type, classOp - type);
2459 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2462 method.dataTypeString = type;
2468 public void ProcessPropertyType(Property prop)
2472 Context context = SetupTemplatesContext(prop._class);
2473 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2474 FinishTemplatesContext(context);
2478 public void DeclareMethod(Method method, const char * name)
2480 Symbol symbol = method.symbol;
2481 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2483 //bool imported = false;
2484 bool dllImport = false;
2486 if(!method.dataType)
2487 method.dataType = ProcessTypeString(method.dataTypeString, false);
2489 if(!symbol || symbol._import || method.type == virtualMethod)
2491 if(!symbol || method.type == virtualMethod)
2494 if(!method._class.symbol)
2495 method._class.symbol = FindClass(method._class.fullName);
2496 classSym = method._class.symbol;
2497 if(!classSym._import)
2499 ModuleImport module;
2501 if(method._class.module && method._class.module.name)
2502 module = FindModule(method._class.module);
2504 module = mainModule;
2505 classSym._import = ClassImport
2507 name = CopyString(method._class.fullName);
2508 isRemote = method._class.isRemote;
2510 module.classes.Add(classSym._import);
2514 symbol = method.symbol = Symbol { };
2518 symbol._import = (ClassImport)MethodImport
2520 name = CopyString(method.name);
2521 isVirtual = method.type == virtualMethod;
2523 classSym._import.methods.Add(symbol._import);
2527 // Set the symbol type
2531 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2533 else if(type.thisClass == (void *)-1)
2535 type.thisClass = null;
2538 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2539 symbol.type = method.dataType;
2540 if(symbol.type) symbol.type.refCount++;
2543 if(!method.thisClass || strcmp(method.thisClass, "void"))
2544 symbol.type.params.Insert(null,
2545 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2548 if(!method.dataType.dllExport)
2551 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2557 if(!method.dataType)
2558 method.dataType = ((Symbol)method.symbol).type;
2559 //ProcessMethodType(method);
2562 if(method.type != virtualMethod && method.dataType)
2563 DeclareType(method.dataType, true, true);
2565 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2567 // We need a declaration here :)
2569 OldList * specifiers, * declarators;
2571 Declarator funcDecl;
2574 specifiers = MkList();
2575 declarators = MkList();
2579 ListAdd(specifiers, MkSpecifier(EXTERN));
2580 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2581 ListAdd(specifiers, MkSpecifier(STATIC));
2583 if(method.type == virtualMethod)
2585 ListAdd(specifiers, MkSpecifier(INT));
2586 d = MkDeclaratorIdentifier(MkIdentifier(name));
2590 d = MkDeclaratorIdentifier(MkIdentifier(name));
2593 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2595 Context context = SetupTemplatesContext(method._class);
2596 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2597 FinishTemplatesContext(context);
2599 funcDecl = GetFuncDecl(d);
2603 Specifier spec, next;
2604 for(spec = specifiers->first; spec; spec = next)
2607 if(spec.type == extendedSpecifier)
2609 specifiers->Remove(spec);
2610 FreeSpecifier(spec);
2615 // Add this parameter if not a static method
2616 if(method.dataType && !method.dataType.staticMethod)
2618 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2620 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2621 TypeName thisParam = MkTypeName(MkListOne(
2622 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2623 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2624 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2625 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2627 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2629 TypeName param = funcDecl.function.parameters->first;
2630 funcDecl.function.parameters->Remove(param);
2631 FreeTypeName(param);
2634 if(!funcDecl.function.parameters)
2635 funcDecl.function.parameters = MkList();
2636 funcDecl.function.parameters->Insert(null, thisParam);
2639 // Make sure we don't have empty parameter declarations for static methods...
2641 else if(!funcDecl.function.parameters)
2643 funcDecl.function.parameters = MkList();
2644 funcDecl.function.parameters->Insert(null,
2645 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2649 ProcessDeclarator(d);
2651 ListAdd(declarators, MkInitDeclarator(d, null));
2653 decl = MkDeclaration(specifiers, declarators);
2655 ReplaceThisClassSpecifiers(specifiers, method._class);
2657 // Keep a different symbol for the function definition than the declaration...
2658 if(symbol.pointerExternal)
2660 Symbol functionSymbol { };
2664 *functionSymbol = *symbol;
2665 functionSymbol.string = CopyString(symbol.string);
2666 if(functionSymbol.type)
2667 functionSymbol.type.refCount++;
2670 excludedSymbols->Add(functionSymbol);
2671 symbol.pointerExternal.symbol = functionSymbol;
2673 external = MkExternalDeclaration(decl);
2675 ast->Insert(curExternal ? curExternal.prev : null, external);
2676 external.symbol = symbol;
2677 symbol.pointerExternal = external;
2681 // Move declaration higher...
2682 ast->Move(symbol.pointerExternal, curExternal.prev);
2685 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2689 char * ReplaceThisClass(Class _class)
2691 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2695 ClassTemplateParameter param;
2698 char className[1024];
2699 strcpy(className, _class.fullName);
2700 for(param = _class.templateParams.first; param; param = param.next)
2702 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2704 if(first) strcat(className, "<");
2705 if(!first) strcat(className, ", ");
2706 if(lastParam + 1 != p)
2708 strcat(className, param.name);
2709 strcat(className, " = ");
2711 strcat(className, param.name);
2719 int len = strlen(className);
2720 if(className[len-1] == '>') className[len++] = ' ';
2721 className[len++] = '>';
2722 className[len++] = '\0';
2724 return CopyString(className);
2727 return CopyString(_class.fullName);
2730 Type ReplaceThisClassType(Class _class)
2733 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2737 ClassTemplateParameter param;
2739 char className[1024];
2740 strcpy(className, _class.fullName);
2742 for(param = _class.templateParams.first; param; param = param.next)
2744 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2746 if(first) strcat(className, "<");
2747 if(!first) strcat(className, ", ");
2748 if(lastParam + 1 != p)
2750 strcat(className, param.name);
2751 strcat(className, " = ");
2753 strcat(className, param.name);
2761 int len = strlen(className);
2762 if(className[len-1] == '>') className[len++] = ' ';
2763 className[len++] = '>';
2764 className[len++] = '\0';
2766 type = MkClassType(className);
2767 //type = ProcessTypeString(className, false);
2771 type = MkClassType(_class.fullName);
2772 //type = ProcessTypeString(_class.fullName, false);
2774 //type.wasThisClass = true;
2778 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2780 if(specs != null && _class)
2783 for(spec = specs.first; spec; spec = spec.next)
2785 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2787 spec.type = nameSpecifier;
2788 spec.name = ReplaceThisClass(_class);
2789 spec.symbol = FindClass(spec.name); //_class.symbol;
2795 // Returns imported or not
2796 bool DeclareFunction(GlobalFunction function, char * name)
2798 Symbol symbol = function.symbol;
2799 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2801 bool imported = false;
2802 bool dllImport = false;
2804 if(!function.dataType)
2806 function.dataType = ProcessTypeString(function.dataTypeString, false);
2807 if(!function.dataType.thisClass)
2808 function.dataType.staticMethod = true;
2815 ModuleImport module = FindModule(function.module);
2816 // WARNING: This is not added anywhere...
2817 symbol = function.symbol = Symbol { };
2821 if(!function.dataType.dllExport)
2823 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2824 module.functions.Add(symbol._import);
2827 // Set the symbol type
2829 symbol.type = ProcessTypeString(function.dataTypeString, false);
2830 if(!symbol.type.thisClass)
2831 symbol.type.staticMethod = true;
2834 imported = symbol._import ? true : false;
2835 if(imported && function.module != privateModule && function.module.importType != staticImport)
2839 DeclareType(function.dataType, true, true);
2843 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2845 // We need a declaration here :)
2847 OldList * specifiers, * declarators;
2849 Declarator funcDecl;
2852 specifiers = MkList();
2853 declarators = MkList();
2856 ListAdd(specifiers, MkSpecifier(EXTERN));
2859 ListAdd(specifiers, MkSpecifier(STATIC));
2862 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2865 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2867 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2868 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2869 if(function.module.importType == staticImport)
2872 for(spec = specifiers->first; spec; spec = spec.next)
2873 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2875 specifiers->Remove(spec);
2876 FreeSpecifier(spec);
2881 funcDecl = GetFuncDecl(d);
2883 // Make sure we don't have empty parameter declarations for static methods...
2884 if(funcDecl && !funcDecl.function.parameters)
2886 funcDecl.function.parameters = MkList();
2887 funcDecl.function.parameters->Insert(null,
2888 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2891 ListAdd(declarators, MkInitDeclarator(d, null));
2894 Context oldCtx = curContext;
2895 curContext = globalContext;
2896 decl = MkDeclaration(specifiers, declarators);
2897 curContext = oldCtx;
2900 // Keep a different symbol for the function definition than the declaration...
2901 if(symbol.pointerExternal)
2903 Symbol functionSymbol { };
2906 *functionSymbol = *symbol;
2907 functionSymbol.string = CopyString(symbol.string);
2908 if(functionSymbol.type)
2909 functionSymbol.type.refCount++;
2912 excludedSymbols->Add(functionSymbol);
2914 symbol.pointerExternal.symbol = functionSymbol;
2916 external = MkExternalDeclaration(decl);
2918 ast->Insert(curExternal.prev, external);
2919 external.symbol = symbol;
2920 symbol.pointerExternal = external;
2924 // Move declaration higher...
2925 ast->Move(symbol.pointerExternal, curExternal.prev);
2929 symbol.id = curExternal.symbol.idCode;
2932 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2935 void DeclareGlobalData(GlobalData data)
2937 Symbol symbol = data.symbol;
2938 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2943 symbol = data.symbol = Symbol { };
2946 data.dataType = ProcessTypeString(data.dataTypeString, false);
2947 DeclareType(data.dataType, true, true);
2950 if(!symbol.pointerExternal)
2952 // We need a declaration here :)
2954 OldList * specifiers, * declarators;
2958 specifiers = MkList();
2959 declarators = MkList();
2961 ListAdd(specifiers, MkSpecifier(EXTERN));
2962 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2963 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2965 ListAdd(declarators, MkInitDeclarator(d, null));
2967 decl = MkDeclaration(specifiers, declarators);
2968 external = MkExternalDeclaration(decl);
2970 ast->Insert(curExternal.prev, external);
2971 external.symbol = symbol;
2972 symbol.pointerExternal = external;
2976 // Move declaration higher...
2977 ast->Move(symbol.pointerExternal, curExternal.prev);
2981 symbol.id = curExternal.symbol.idCode;
2986 class Conversion : struct
2988 Conversion prev, next;
2994 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
2997 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
2998 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
3000 Class sourceClass = source.kind == classType ? source._class.registered : null;
3001 Class destClass = dest.kind == classType ? dest._class.registered : null;
3002 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
3003 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
3005 Type sourceType = source, destType = dest;
3006 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
3007 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
3008 if(!destType.constant && sourceType.constant)
3012 Compiler_Warning($"discarding const qualifier\n");
3019 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
3020 bool isConversionExploration, bool warnConst)
3025 CheckConstCompatibility(source, dest, true);
3026 // Property convert;
3028 if(source.kind == templateType && dest.kind != templateType)
3030 Type type = ProcessTemplateParameterType(source.templateParameter);
3031 if(type) source = type;
3034 if(dest.kind == templateType && source.kind != templateType)
3036 Type type = ProcessTemplateParameterType(dest.templateParameter);
3037 if(type) dest = type;
3040 if(dest.classObjectType == typedObject && dest.kind != functionType)
3042 if(source.classObjectType != anyObject)
3046 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
3047 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
3055 if(source.kind != functionType && source.classObjectType == anyObject)
3057 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
3061 if((dest.kind == structType && source.kind == structType) ||
3062 (dest.kind == unionType && source.kind == unionType))
3064 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
3065 (source.members.first && source.members.first == dest.members.first))
3069 if(dest.kind == ellipsisType && source.kind != voidType)
3072 if(dest.kind == pointerType && dest.type.kind == voidType &&
3073 ((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))
3074 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
3076 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
3078 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
3080 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
3081 ((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))
3082 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
3083 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
3085 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
3088 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
3090 if(source._class.registered && source._class.registered.type == unitClass)
3092 if(conversions != null)
3094 if(source._class.registered == dest._class.registered)
3099 Class sourceBase, destBase;
3100 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
3101 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
3102 if(sourceBase == destBase)
3106 // Don't match enum inheriting from other enum if resolving enumeration values
3107 // TESTING: !dest.classObjectType
3108 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
3110 (!source._class.registered || source._class.registered.type != enumClass) ||
3111 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
3115 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
3117 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
3118 ((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)
3120 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3128 // JUST ADDED THIS...
3129 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3134 // Just added this for Straight conversion of ColorAlpha => Color
3135 if(source.kind == classType)
3138 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3141 for(convert = _class.conversions.first; convert; convert = convert.next)
3143 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3145 Conversion after = (conversions != null) ? conversions.last : null;
3147 if(!convert.dataType)
3148 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3149 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3150 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3151 MatchTypes(convert.dataType, dest, conversions, null, null,
3152 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3153 convert.dataType.kind == classType, false, true, warnConst))
3155 if(!conversions && !convert.Get)
3157 else if(conversions != null)
3159 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3160 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3161 (dest.kind != classType || dest._class.registered != _class.base))
3165 Conversion conv { convert = convert, isGet = true };
3166 // conversions.Add(conv);
3167 conversions.Insert(after, conv);
3180 if(dest.kind == classType)
3183 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3186 for(convert = _class.conversions.first; convert; convert = convert.next)
3188 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3190 Type constType = null;
3191 bool success = false;
3192 // Conversion after = (conversions != null) ? conversions.last : null;
3194 if(!convert.dataType)
3195 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3197 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3200 constType = { kind = pointerType, refCount = 1, type = ptrType };
3201 CopyTypeInto(ptrType, convert.dataType.type);
3202 ptrType.constant = true;
3205 // Just added this equality check to prevent recursion.... Make it safer?
3206 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3207 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3209 if(!conversions && !convert.Set)
3211 else if(conversions != null)
3213 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3214 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3215 (source.kind != classType || source._class.registered != _class.base))
3219 // *** Testing this! ***
3220 Conversion conv { convert = convert };
3221 conversions.Add(conv);
3222 //conversions.Insert(after, conv);
3228 FreeType(constType);
3234 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3236 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3237 (source.kind != classType || source._class.registered.type != structClass))
3241 // TESTING THIS... IS THIS OK??
3242 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3244 if(!dest._class.registered.dataType)
3245 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3246 // Only support this for classes...
3247 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3248 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3250 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3259 if(source.kind == classType)
3262 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3265 for(convert = _class.conversions.first; convert; convert = convert.next)
3267 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3269 Conversion after = (conversions != null) ? conversions.last : null;
3271 if(!convert.dataType)
3272 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3273 if(convert.dataType != source &&
3274 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3275 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3277 if(!conversions && !convert.Get)
3279 else if(conversions != null)
3281 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3282 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3283 (dest.kind != classType || dest._class.registered != _class.base))
3287 Conversion conv { convert = convert, isGet = true };
3289 // conversions.Add(conv);
3290 conversions.Insert(after, conv);
3299 // TESTING THIS... IS THIS OK??
3300 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3302 if(!source._class.registered.dataType)
3303 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3304 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3306 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, source._class.registered.dataType.kind == classType, source._class.registered.dataType.kind == classType, false, false, warnConst))
3308 // For bool to be accepted by byte, short, etc.
3309 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3316 if(source.kind == classType || source.kind == subClassType)
3318 else if(dest.kind == source.kind &&
3319 (dest.kind != structType && dest.kind != unionType &&
3320 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3322 // RECENTLY ADDED THESE
3323 else if(dest.kind == doubleType && source.kind == floatType)
3325 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3327 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3329 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3331 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3333 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3335 else if(source.kind == enumType &&
3336 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3338 else if(dest.kind == enumType && !isConversionExploration &&
3339 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3341 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3342 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3344 Type paramSource, paramDest;
3346 if(dest.kind == methodType)
3347 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3348 if(source.kind == methodType)
3349 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3351 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3352 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3353 if(dest.kind == methodType)
3354 dest = dest.method.dataType;
3355 if(source.kind == methodType)
3356 source = source.method.dataType;
3358 paramSource = source.params.first;
3359 if(paramSource && paramSource.kind == voidType) paramSource = null;
3360 paramDest = dest.params.first;
3361 if(paramDest && paramDest.kind == voidType) paramDest = null;
3364 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3365 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3367 // Source thisClass must be derived from destination thisClass
3368 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3369 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3371 if(paramDest && paramDest.kind == classType)
3372 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3374 Compiler_Error($"method class should not take an object\n");
3377 paramDest = paramDest.next;
3379 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3381 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3385 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3387 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3393 // THIS WAS BACKWARDS:
3394 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3395 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3398 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3400 Compiler_Error($"overriding class expected to be derived from method class\n");
3404 paramSource = paramSource.next;
3410 // Source thisClass must be derived from destination thisClass
3411 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3413 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3419 // THIS WAS BACKWARDS TOO??
3420 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3421 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3424 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3426 //Compiler_Error($"overriding class expected to be derived from method class\n");
3434 // Source return type must be derived from destination return type
3435 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3437 Compiler_Warning($"incompatible return type for function\n");
3440 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3442 CheckConstCompatibility(dest.returnType, source.returnType, true);
3446 for(; paramDest; paramDest = paramDest.next)
3450 //Compiler_Warning($"not enough parameters\n");
3451 Compiler_Error($"not enough parameters\n");
3455 Type paramDestType = paramDest;
3456 Type paramSourceType = paramSource;
3457 Type type = paramDestType;
3459 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3460 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3461 paramSource.kind != templateType)
3464 ClassTemplateParameter curParam = null;
3466 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3469 if(sClass.templateClass) sClass = sClass.templateClass;
3470 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3472 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3474 for(sClass = sClass.base; sClass; sClass = sClass.base)
3476 if(sClass.templateClass) sClass = sClass.templateClass;
3477 id += sClass.templateParams.count;
3488 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3489 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3493 // paramDest must be derived from paramSource
3494 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3495 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3499 PrintType(paramDest, type, false, true);
3500 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3502 if(paramDestType != paramDest)
3503 FreeType(paramDestType);
3506 if(paramDestType != paramDest)
3507 FreeType(paramDestType);
3510 paramSource = paramSource.next;
3514 Compiler_Error($"too many parameters\n");
3519 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3523 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3524 (source.kind == arrayType || source.kind == pointerType))
3526 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3533 static void FreeConvert(Conversion convert)
3535 if(convert.resultType)
3536 FreeType(convert.resultType);
3539 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3540 char * string, OldList conversions)
3544 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3546 Class _class = link.data;
3547 if(_class.type == enumClass)
3549 OldList converts { };
3551 type.kind = classType;
3554 _class.symbol = FindClass(_class.fullName);
3555 type._class = _class.symbol;
3557 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false, false))
3560 Class enumClass = eSystem_FindClass(privateModule, "enum");
3564 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3566 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3567 for(value = e.values.first; value; value = value.next)
3569 if(!strcmp(value.name, string))
3574 FreeExpContents(sourceExp);
3575 FreeType(sourceExp.expType);
3577 sourceExp.isConstant = true;
3578 sourceExp.expType = MkClassType(baseClass.fullName);
3582 sourceExp.type = constantExp;
3583 if(!strcmp(baseClass.dataTypeString, "int"))
3584 sprintf(constant, "%d",(int)value.data);
3586 sprintf(constant, "0x%X",(int)value.data);
3587 sourceExp.constant = CopyString(constant);
3588 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3591 while(converts.first)
3593 Conversion convert = converts.first;
3594 converts.Remove(convert);
3595 conversions.Add(convert);
3604 converts.Free(FreeConvert);
3608 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3609 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3614 public bool ModuleVisibility(Module searchIn, Module searchFor)
3616 SubModule subModule;
3618 if(searchFor == searchIn)
3621 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3623 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3625 if(ModuleVisibility(subModule.module, searchFor))
3632 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3636 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3638 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3640 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3643 for(module = mainModule.application.allModules.first; module; module = module.next)
3645 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3651 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3654 Type realDest = dest;
3655 Type backupSourceExpType = null;
3656 Expression computedExp = sourceExp;
3659 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3660 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3662 computedExp = CopyExpression(sourceExp); // Keep the original expression, but compute for checking enum ranges
3663 ComputeExpression(computedExp /*sourceExp*/);
3666 source = sourceExp.expType;
3668 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3670 if(computedExp != sourceExp)
3672 FreeExpression(computedExp);
3673 computedExp = sourceExp;
3679 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3681 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3683 Class sourceBase, destBase;
3684 for(sourceBase = source._class.registered;
3685 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3686 sourceBase = sourceBase.base);
3687 for(destBase = dest._class.registered;
3688 destBase && destBase.base && destBase.base.type != systemClass;
3689 destBase = destBase.base);
3690 //if(source._class.registered == dest._class.registered)
3691 if(sourceBase == destBase)
3693 if(computedExp != sourceExp)
3695 FreeExpression(computedExp);
3696 computedExp = sourceExp;
3708 int64 value = MAXINT;
3712 if(computedExp.type == constantExp)
3715 value = strtoll(computedExp.constant, null, 0);
3717 value = strtoull(computedExp.constant, null, 0);
3719 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3722 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3724 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3726 if(computedExp != sourceExp)
3728 FreeExpression(computedExp);
3729 computedExp = sourceExp;
3732 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3733 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3736 source = Type { kind = intType, isSigned = false, refCount = 1 };
3739 if(dest.kind == classType)
3741 Class _class = dest._class ? dest._class.registered : null;
3743 if(_class && _class.type == unitClass)
3745 if(source.kind != classType)
3748 Type tempDest, tempSource;
3750 for(; _class.base.type != systemClass; _class = _class.base);
3752 tempDest = tempType;
3754 tempType.kind = classType;
3756 _class.symbol = FindClass(_class.fullName);
3758 tempType._class = _class.symbol;
3759 tempType.truth = dest.truth;
3761 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3763 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3764 backupSourceExpType = sourceExp.expType;
3765 sourceExp.expType = dest; dest.refCount++;
3766 //sourceExp.expType = MkClassType(_class.fullName);
3774 // Why wasn't there something like this?
3775 if(_class && _class.type == bitClass && source.kind != classType)
3777 if(!dest._class.registered.dataType)
3778 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3779 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3782 FreeType(sourceExp.expType);
3783 source = sourceExp.expType = MkClassType(dest._class.string);
3786 //source.kind = classType;
3787 //source._class = dest._class;
3791 // Adding two enumerations
3793 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3795 if(!source._class.registered.dataType)
3796 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3797 if(!dest._class.registered.dataType)
3798 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3800 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3803 source = sourceExp.expType = MkClassType(dest._class.string);
3806 //source.kind = classType;
3807 //source._class = dest._class;
3811 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3813 OldList * specs = MkList();
3817 ReadString(string, sourceExp.string);
3818 decl = SpecDeclFromString(string, specs, null);
3820 FreeExpContents(sourceExp);
3821 FreeType(sourceExp.expType);
3823 sourceExp.type = classExp;
3824 sourceExp._classExp.specifiers = specs;
3825 sourceExp._classExp.decl = decl;
3826 sourceExp.expType = dest;
3831 if(backupSourceExpType) FreeType(backupSourceExpType);
3835 else if(source.kind == classType)
3837 Class _class = source._class ? source._class.registered : null;
3839 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3842 if(dest.kind != classType)
3844 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3845 if(!source._class.registered.dataType)
3846 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3849 dest = MkClassType(source._class.string);
3850 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3851 // dest = MkClassType(source._class.string);
3855 if(dest.kind != classType)
3858 Type tempDest, tempSource;
3860 if(!source._class.registered.dataType)
3861 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3863 for(; _class.base.type != systemClass; _class = _class.base);
3865 tempSource = tempType;
3866 tempType.kind = classType;
3867 tempType._class = FindClass(_class.fullName);
3868 tempType.truth = source.truth;
3869 tempType.classObjectType = source.classObjectType;
3872 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3874 // PUT THIS BACK TESTING UNITS?
3875 if(conversions.last)
3877 ((Conversion)(conversions.last)).resultType = dest;
3881 FreeType(sourceExp.expType);
3882 sourceExp.expType = MkClassType(_class.fullName);
3883 sourceExp.expType.truth = source.truth;
3884 sourceExp.expType.classObjectType = source.classObjectType;
3886 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3888 if(!sourceExp.destType)
3890 FreeType(sourceExp.destType);
3891 sourceExp.destType = sourceExp.expType;
3892 if(sourceExp.expType)
3893 sourceExp.expType.refCount++;
3896 //source = _class.dataType;
3899 // TOCHECK: TESTING THIS NEW CODE
3900 if(!_class.dataType)
3901 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3903 dest = MkClassType(source._class.string);
3904 dest.truth = source.truth;
3905 dest.classObjectType = source.classObjectType;
3908 source = _class.dataType;
3918 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3928 if(source.kind == classType)
3930 Class _class = source._class.registered;
3931 if(_class.type == unitClass)
3933 if(!_class.dataType)
3934 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3935 source = _class.dataType;
3939 if(dest.kind == classType)
3941 Class _class = dest._class ? dest._class.registered : null;
3942 bool fittingValue = false;
3943 if(_class && _class.type == enumClass)
3945 Class enumClass = eSystem_FindClass(privateModule, "enum");
3946 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3947 if(c && value >= 0 && value <= c.largest)
3948 fittingValue = true;
3951 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3952 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3954 if(_class.type == normalClass || _class.type == noHeadClass)
3956 Expression newExp { };
3957 *newExp = *sourceExp;
3958 if(sourceExp.destType) sourceExp.destType.refCount++;
3959 if(sourceExp.expType) sourceExp.expType.refCount++;
3960 sourceExp.type = castExp;
3961 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3962 sourceExp.cast.exp = newExp;
3963 FreeType(sourceExp.expType);
3964 sourceExp.expType = null;
3965 ProcessExpressionType(sourceExp);
3967 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3970 FreeType(sourceExp.expType);
3971 sourceExp.expType = dest;
3975 if(inCompiler) FreeType(dest);
3977 if(backupSourceExpType) FreeType(backupSourceExpType);
3981 if(!_class.dataType)
3982 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3984 dest = _class.dataType;
3988 // Accept lower precision types for units, since we want to keep the unit type
3989 if(dest.kind == doubleType &&
3990 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3991 source.kind == charType || source.kind == _BoolType))
3993 specs = MkListOne(MkSpecifier(DOUBLE));
3995 else if(dest.kind == floatType &&
3996 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3997 source.kind == _BoolType || source.kind == doubleType))
3999 specs = MkListOne(MkSpecifier(FLOAT));
4001 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
4002 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4005 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4006 ListAdd(specs, MkSpecifier(INT64));
4008 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
4009 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4012 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4013 ListAdd(specs, MkSpecifier(INT));
4015 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
4016 source.kind == floatType || source.kind == doubleType))
4019 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4020 ListAdd(specs, MkSpecifier(SHORT));
4022 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
4023 source.kind == floatType || source.kind == doubleType))
4026 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4027 ListAdd(specs, MkSpecifier(CHAR));
4033 if(backupSourceExpType)
4035 // Failed to convert: revert previous exp type
4036 if(sourceExp.expType) FreeType(sourceExp.expType);
4037 sourceExp.expType = backupSourceExpType;
4042 else if(dest.kind == doubleType &&
4043 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
4044 source.kind == _BoolType || source.kind == charType))
4046 specs = MkListOne(MkSpecifier(DOUBLE));
4048 else if(dest.kind == floatType &&
4049 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4051 specs = MkListOne(MkSpecifier(FLOAT));
4053 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4054 (value == 1 || value == 0))
4057 ListAdd(specs, MkSpecifier(BOOL));
4059 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4060 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
4063 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4064 ListAdd(specs, MkSpecifier(CHAR));
4066 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
4067 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
4070 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4071 ListAdd(specs, MkSpecifier(SHORT));
4073 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
4076 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4077 ListAdd(specs, MkSpecifier(INT));
4079 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
4082 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4083 ListAdd(specs, MkSpecifier(INT64));
4085 else if(dest.kind == enumType &&
4086 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4088 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
4094 if(backupSourceExpType)
4096 // Failed to convert: revert previous exp type
4097 if(sourceExp.expType) FreeType(sourceExp.expType);
4098 sourceExp.expType = backupSourceExpType;
4103 if(!flag && !sourceExp.opDestType)
4105 Expression newExp { };
4106 *newExp = *sourceExp;
4109 if(sourceExp.destType) sourceExp.destType.refCount++;
4110 if(sourceExp.expType) sourceExp.expType.refCount++;
4112 sourceExp.type = castExp;
4113 if(realDest.kind == classType)
4115 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4116 FreeList(specs, FreeSpecifier);
4119 sourceExp.cast.typeName = MkTypeName(specs, null);
4120 if(newExp.type == opExp)
4122 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4125 sourceExp.cast.exp = newExp;
4127 FreeType(sourceExp.expType);
4128 sourceExp.expType = null;
4129 ProcessExpressionType(sourceExp);
4132 FreeList(specs, FreeSpecifier);
4136 if(backupSourceExpType) FreeType(backupSourceExpType);
4142 if(computedExp != sourceExp)
4144 FreeExpression(computedExp);
4145 computedExp = sourceExp;
4148 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4149 if(sourceExp.type == identifierExp)
4151 Identifier id = sourceExp.identifier;
4152 if(dest.kind == classType)
4154 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4156 Class _class = dest._class.registered;
4157 Class enumClass = eSystem_FindClass(privateModule, "enum");
4160 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4163 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4164 for(value = e.values.first; value; value = value.next)
4166 if(!strcmp(value.name, id.string))
4171 FreeExpContents(sourceExp);
4172 FreeType(sourceExp.expType);
4174 sourceExp.isConstant = true;
4175 sourceExp.expType = MkClassType(_class.fullName);
4179 sourceExp.type = constantExp;
4180 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
4181 sprintf(constant, "%d", (int) value.data);
4183 sprintf(constant, "0x%X", (int) value.data);
4184 sourceExp.constant = CopyString(constant);
4185 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4195 // Loop through all enum classes
4196 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4207 #define TERTIARY(o, name, m, t, p) \
4208 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4210 exp.type = constantExp; \
4211 exp.string = p(op1.m ? op2.m : op3.m); \
4213 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4217 #define BINARY(o, name, m, t, p) \
4218 static bool name(Expression exp, Operand op1, Operand op2) \
4221 exp.type = constantExp; \
4222 exp.string = p((t)(op1.m o value2)); \
4224 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4228 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4229 static bool name(Expression exp, Operand op1, Operand op2) \
4232 exp.type = constantExp; \
4233 exp.string = p(value2 ? (op1.m o value2) : 0); \
4235 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4239 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4240 static bool name(Expression exp, Operand op1, Operand op2) \
4243 exp.type = constantExp; \
4244 exp.string = p(op1.m o value2); \
4246 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4250 #define UNARY(o, name, m, t, p) \
4251 static bool name(Expression exp, Operand op1) \
4253 exp.type = constantExp; \
4254 exp.string = p((t)(o op1.m)); \
4256 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4260 #define OPERATOR_ALL(macro, o, name) \
4261 macro(o, Int##name, i, int, PrintInt) \
4262 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4263 macro(o, Int64##name, i64, int64, PrintInt64) \
4264 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4265 macro(o, Short##name, s, short, PrintShort) \
4266 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4267 macro(o, Char##name, c, char, PrintChar) \
4268 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4269 macro(o, Float##name, f, float, PrintFloat) \
4270 macro(o, Double##name, d, double, PrintDouble)
4272 #define OPERATOR_INTTYPES(macro, o, name) \
4273 macro(o, Int##name, i, int, PrintInt) \
4274 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4275 macro(o, Int64##name, i64, int64, PrintInt64) \
4276 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4277 macro(o, Short##name, s, short, PrintShort) \
4278 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4279 macro(o, Char##name, c, char, PrintChar) \
4280 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4282 #define OPERATOR_REALTYPES(macro, o, name) \
4283 macro(o, Float##name, f, float, PrintFloat) \
4284 macro(o, Double##name, d, double, PrintDouble)
4286 // binary arithmetic
4287 OPERATOR_ALL(BINARY, +, Add)
4288 OPERATOR_ALL(BINARY, -, Sub)
4289 OPERATOR_ALL(BINARY, *, Mul)
4290 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4291 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4292 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4295 OPERATOR_ALL(UNARY, -, Neg)
4297 // unary arithmetic increment and decrement
4298 OPERATOR_ALL(UNARY, ++, Inc)
4299 OPERATOR_ALL(UNARY, --, Dec)
4301 // binary arithmetic assignment
4302 OPERATOR_ALL(BINARY, =, Asign)
4303 OPERATOR_ALL(BINARY, +=, AddAsign)
4304 OPERATOR_ALL(BINARY, -=, SubAsign)
4305 OPERATOR_ALL(BINARY, *=, MulAsign)
4306 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4307 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4308 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4311 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4312 OPERATOR_INTTYPES(BINARY, |, BitOr)
4313 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4314 OPERATOR_INTTYPES(BINARY, <<, LShift)
4315 OPERATOR_INTTYPES(BINARY, >>, RShift)
4318 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4320 // binary bitwise assignment
4321 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4322 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4323 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4324 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4325 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4327 // unary logical negation
4328 OPERATOR_INTTYPES(UNARY, !, Not)
4330 // binary logical equality
4331 OPERATOR_ALL(BINARY, ==, Equ)
4332 OPERATOR_ALL(BINARY, !=, Nqu)
4335 OPERATOR_ALL(BINARY, &&, And)
4336 OPERATOR_ALL(BINARY, ||, Or)
4338 // binary logical relational
4339 OPERATOR_ALL(BINARY, >, Grt)
4340 OPERATOR_ALL(BINARY, <, Sma)
4341 OPERATOR_ALL(BINARY, >=, GrtEqu)
4342 OPERATOR_ALL(BINARY, <=, SmaEqu)
4344 // tertiary condition operator
4345 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4347 //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
4348 #define OPERATOR_TABLE_ALL(name, type) \
4349 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4351 type##Inc, type##Dec, \
4352 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4353 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4355 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4357 type##Equ, type##Nqu, \
4358 type##And, type##Or, \
4359 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4362 #define OPERATOR_TABLE_INTTYPES(name, type) \
4363 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4365 type##Inc, type##Dec, \
4366 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4367 null, null, null, null, null, \
4369 null, null, null, null, null, \
4371 type##Equ, type##Nqu, \
4372 type##And, type##Or, \
4373 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4376 OPERATOR_TABLE_ALL(int, Int)
4377 OPERATOR_TABLE_ALL(uint, UInt)
4378 OPERATOR_TABLE_ALL(int64, Int64)
4379 OPERATOR_TABLE_ALL(uint64, UInt64)
4380 OPERATOR_TABLE_ALL(short, Short)
4381 OPERATOR_TABLE_ALL(ushort, UShort)
4382 OPERATOR_TABLE_INTTYPES(float, Float)
4383 OPERATOR_TABLE_INTTYPES(double, Double)
4384 OPERATOR_TABLE_ALL(char, Char)
4385 OPERATOR_TABLE_ALL(uchar, UChar)
4387 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4388 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4389 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4390 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4391 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4392 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4393 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4394 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4396 public void ReadString(char * output, char * string)
4398 int len = strlen(string);
4400 bool quoted = false, escaped = false;
4401 for(c = 0; c<len; c++)
4403 char ch = string[c];
4408 case 'n': output[d] = '\n'; break;
4409 case 't': output[d] = '\t'; break;
4410 case 'a': output[d] = '\a'; break;
4411 case 'b': output[d] = '\b'; break;
4412 case 'f': output[d] = '\f'; break;
4413 case 'r': output[d] = '\r'; break;
4414 case 'v': output[d] = '\v'; break;
4415 case '\\': output[d] = '\\'; break;
4416 case '\"': output[d] = '\"'; break;
4417 case '\'': output[d] = '\''; break;
4418 default: output[d] = ch;
4439 // String Unescape Copy
4441 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4442 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4443 public int UnescapeString(char * d, char * s, int len)
4447 while(j < len && (ch = s[j]))
4452 switch((ch = s[++j]))
4454 case 'n': d[k] = '\n'; break;
4455 case 't': d[k] = '\t'; break;
4456 case 'a': d[k] = '\a'; break;
4457 case 'b': d[k] = '\b'; break;
4458 case 'f': d[k] = '\f'; break;
4459 case 'r': d[k] = '\r'; break;
4460 case 'v': d[k] = '\v'; break;
4461 case '\\': d[k] = '\\'; break;
4462 case '\"': d[k] = '\"'; break;
4463 case '\'': d[k] = '\''; break;
4464 default: d[k] = '\\'; d[k] = ch;
4476 public char * OffsetEscapedString(char * s, int len, int offset)
4480 while(j < len && k < offset && (ch = s[j]))
4485 return (k == offset) ? s + j : null;
4488 public Operand GetOperand(Expression exp)
4491 Type type = exp.expType;
4494 while(type.kind == classType &&
4495 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4497 if(!type._class.registered.dataType)
4498 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4499 type = type._class.registered.dataType;
4502 if(exp.type == stringExp && op.kind == pointerType)
4504 op.ui64 = (uint64)exp.string;
4505 op.kind = pointerType;
4508 else if(exp.isConstant && exp.type == constantExp)
4510 op.kind = type.kind;
4511 op.type = exp.expType;
4518 if(exp.constant[0] == '\'')
4520 op.c = exp.constant[1];
4523 else if(type.isSigned)
4525 op.c = (char)strtol(exp.constant, null, 0);
4530 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4538 op.s = (short)strtol(exp.constant, null, 0);
4543 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4551 op.i = (int)strtol(exp.constant, null, 0);
4556 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4564 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4569 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4572 op.kind = int64Type;
4577 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4582 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4585 op.kind = int64Type;
4590 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4595 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4598 op.kind = int64Type;
4601 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4602 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4603 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4604 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4606 op.f = (float)strtod(exp.constant, null);
4610 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4611 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4612 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4613 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4615 op.d = (double)strtod(exp.constant, null);
4618 //case classType: For when we have operator overloading...
4619 // Pointer additions
4620 //case functionType:
4624 op.ui64 = _strtoui64(exp.constant, null, 0);
4625 op.kind = pointerType;
4635 static __attribute__((unused)) void UnusedFunction()
4638 a.OnGetString(0,0,0);
4641 extern int __ecereVMethodID_class_OnGetString;
4644 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4646 DataMember dataMember;
4647 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4649 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4650 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4654 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4656 void * ptr = inst.data + dataMember.offset + offset;
4657 char * result = null;
4658 exp.loc = member.loc = inst.loc;
4659 ((Identifier)member.identifiers->first).loc = inst.loc;
4661 if(!dataMember.dataType)
4662 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4663 type = dataMember.dataType;
4664 if(type.kind == classType)
4666 Class _class = type._class.registered;
4667 if(_class.type == enumClass)
4669 Class enumClass = eSystem_FindClass(privateModule, "enum");
4672 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4674 for(item = e.values.first; item; item = item.next)
4676 if((int)item.data == *(int *)ptr)
4684 exp.identifier = MkIdentifier(result);
4685 exp.type = identifierExp;
4686 exp.destType = MkClassType(_class.fullName);
4687 ProcessExpressionType(exp);
4691 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4693 if(!_class.dataType)
4694 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4695 type = _class.dataType;
4704 FreeExpContents(exp);
4706 exp.constant = PrintFloat(*(float*)ptr);
4707 exp.type = constantExp;
4712 FreeExpContents(exp);
4714 exp.constant = PrintDouble(*(double*)ptr);
4715 exp.type = constantExp;
4720 FreeExpContents(exp);
4722 exp.constant = PrintInt(*(int*)ptr);
4723 exp.type = constantExp;
4728 FreeExpContents(exp);
4730 exp.constant = PrintInt64(*(int64*)ptr);
4731 exp.type = constantExp;
4736 FreeExpContents(exp);
4737 // TODO: This should probably use proper type
4738 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4739 exp.type = constantExp;
4744 FreeExpContents(exp);
4745 // TODO: This should probably use proper type
4746 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4747 exp.type = constantExp;
4751 Compiler_Error($"Unhandled type populating instance\n");
4754 ListAdd(memberList, member);
4757 if(parentDataMember.type == unionMember)
4762 void PopulateInstance(Instantiation inst)
4764 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4765 Class _class = classSym.registered;
4766 DataMember dataMember;
4767 OldList * memberList = MkList();
4768 // Added this check and ->Add to prevent memory leaks on bad code
4770 inst.members = MkListOne(MkMembersInitList(memberList));
4772 inst.members->Add(MkMembersInitList(memberList));
4773 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4775 if(!dataMember.isProperty)
4777 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4778 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4782 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4784 void * ptr = inst.data + dataMember.offset;
4785 char * result = null;
4787 exp.loc = member.loc = inst.loc;
4788 ((Identifier)member.identifiers->first).loc = inst.loc;
4790 if(!dataMember.dataType)
4791 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4792 type = dataMember.dataType;
4793 if(type.kind == classType)
4795 Class _class = type._class.registered;
4796 if(_class.type == enumClass)
4798 Class enumClass = eSystem_FindClass(privateModule, "enum");
4801 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4803 for(item = e.values.first; item; item = item.next)
4805 if((int)item.data == *(int *)ptr)
4814 exp.identifier = MkIdentifier(result);
4815 exp.type = identifierExp;
4816 exp.destType = MkClassType(_class.fullName);
4817 ProcessExpressionType(exp);
4820 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4822 if(!_class.dataType)
4823 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4824 type = _class.dataType;
4833 exp.constant = PrintFloat(*(float*)ptr);
4834 exp.type = constantExp;
4839 exp.constant = PrintDouble(*(double*)ptr);
4840 exp.type = constantExp;
4845 exp.constant = PrintInt(*(int*)ptr);
4846 exp.type = constantExp;
4851 exp.constant = PrintInt64(*(int64*)ptr);
4852 exp.type = constantExp;
4857 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4858 exp.type = constantExp;
4862 Compiler_Error($"Unhandled type populating instance\n");
4865 ListAdd(memberList, member);
4871 void ComputeInstantiation(Expression exp)
4873 Instantiation inst = exp.instance;
4874 MembersInit members;
4875 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4876 Class _class = classSym ? classSym.registered : null;
4877 DataMember curMember = null;
4878 Class curClass = null;
4879 DataMember subMemberStack[256];
4880 int subMemberStackPos = 0;
4883 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4885 // Don't recompute the instantiation...
4886 // Non Simple classes will have become constants by now
4890 if(_class.type == normalClass || _class.type == noHeadClass)
4892 inst.data = (byte *)eInstance_New(_class);
4893 if(_class.type == normalClass)
4894 ((Instance)inst.data)._refCount++;
4897 inst.data = new0 byte[_class.structSize];
4902 for(members = inst.members->first; members; members = members.next)
4904 switch(members.type)
4906 case dataMembersInit:
4908 if(members.dataMembers)
4911 for(member = members.dataMembers->first; member; member = member.next)
4913 Identifier ident = member.identifiers ? member.identifiers->first : null;
4916 Property prop = null;
4917 DataMember dataMember = null;
4918 uint dataMemberOffset;
4922 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4925 if(curMember.isProperty)
4926 prop = (Property)curMember;
4929 dataMember = curMember;
4931 // CHANGED THIS HERE
4932 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4934 // 2013/17/29 -- It seems that this was missing here!
4935 if(_class.type == normalClass)
4936 dataMemberOffset += _class.base.structSize;
4937 // dataMemberOffset = dataMember.offset;
4944 prop = eClass_FindProperty(_class, ident.string, privateModule);
4948 if(prop.memberAccess == publicAccess)
4950 curMember = (DataMember)prop;
4951 curClass = prop._class;
4956 DataMember _subMemberStack[256];
4957 int _subMemberStackPos = 0;
4959 // FILL MEMBER STACK
4960 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4965 if(dataMember.memberAccess == publicAccess)
4967 curMember = dataMember;
4968 curClass = dataMember._class;
4969 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4970 subMemberStackPos = _subMemberStackPos;
4976 if(found && member.initializer && member.initializer.type == expInitializer)
4978 Expression value = member.initializer.exp;
4980 bool deepMember = false;
4983 type = prop.dataType;
4987 if(!dataMember.dataType)
4988 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4990 type = dataMember.dataType;
4993 if(ident && ident.next)
4997 // for(; ident && type; ident = ident.next)
4998 for(ident = ident.next; ident && type; ident = ident.next)
5000 if(type.kind == classType)
5002 prop = eClass_FindProperty(type._class.registered,
5003 ident.string, privateModule);
5005 type = prop.dataType;
5008 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
5009 ident.string, &dataMemberOffset, privateModule, null, null);
5011 type = dataMember.dataType;
5014 else if(type.kind == structType || type.kind == unionType)
5017 for(memberType = type.members.first; memberType; memberType = memberType.next)
5019 if(!strcmp(memberType.name, ident.string))
5030 FreeType(value.destType);
5031 value.destType = type;
5032 if(type) type.refCount++;
5033 ComputeExpression(value);
5035 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
5037 if(type.kind == classType)
5039 Class _class = type._class.registered;
5040 if(_class.type == bitClass || _class.type == unitClass ||
5041 _class.type == enumClass)
5043 if(!_class.dataType)
5044 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5045 type = _class.dataType;
5051 void * ptr = inst.data + dataMemberOffset;
5053 if(value.type == constantExp)
5059 GetInt(value, (int*)ptr);
5064 GetInt64(value, (int64*)ptr);
5069 GetIntPtr(value, (intptr*)ptr);
5074 GetIntSize(value, (intsize*)ptr);
5079 GetFloat(value, (float*)ptr);
5084 GetDouble(value, (double *)ptr);
5089 else if(value.type == instanceExp)
5091 if(type.kind == classType)
5093 Class _class = type._class.registered;
5094 if(_class.type == structClass)
5096 ComputeTypeSize(type);
5097 if(value.instance.data)
5098 memcpy(ptr, value.instance.data, type.size);
5105 if(value.type == instanceExp && value.instance.data)
5107 if(type.kind == classType)
5109 Class _class = type._class.registered;
5110 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5112 void (*Set)(void *, void *) = (void *)prop.Set;
5113 Set(inst.data, value.instance.data);
5114 PopulateInstance(inst);
5118 else if(value.type == constantExp)
5124 void (*Set)(void *, double) = (void *)prop.Set;
5125 Set(inst.data, strtod(value.constant, null) );
5130 void (*Set)(void *, float) = (void *)prop.Set;
5131 Set(inst.data, (float)(strtod(value.constant, null)));
5136 void (*Set)(void *, int) = (void *)prop.Set;
5137 Set(inst.data, (int)strtol(value.constant, null, 0));
5142 void (*Set)(void *, int64) = (void *)prop.Set;
5143 Set(inst.data, _strtoi64(value.constant, null, 0));
5148 void (*Set)(void *, intptr) = (void *)prop.Set;
5149 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5154 void (*Set)(void *, intsize) = (void *)prop.Set;
5155 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5160 else if(value.type == stringExp)
5163 ReadString(temp, value.string);
5164 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5168 else if(!deepMember && type && _class.type == unitClass)
5172 // Only support converting units to units for now...
5173 if(value.type == constantExp)
5175 if(type.kind == classType)
5177 Class _class = type._class.registered;
5178 if(_class.type == unitClass)
5180 if(!_class.dataType)
5181 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5182 type = _class.dataType;
5185 // TODO: Assuming same base type for units...
5191 float (*Set)(float) = (void *)prop.Set;
5192 GetFloat(member.initializer.exp, &fValue);
5193 exp.constant = PrintFloat(Set(fValue));
5194 exp.type = constantExp;
5200 double (*Set)(double) = (void *)prop.Set;
5201 GetDouble(member.initializer.exp, &dValue);
5202 exp.constant = PrintDouble(Set(dValue));
5203 exp.type = constantExp;
5210 else if(!deepMember && type && _class.type == bitClass)
5214 if(value.type == instanceExp && value.instance.data)
5216 unsigned int (*Set)(void *) = (void *)prop.Set;
5217 bits = Set(value.instance.data);
5219 else if(value.type == constantExp)
5225 BitMember bitMember = (BitMember) dataMember;
5228 bits = (bits & ~bitMember.mask);
5229 if(!bitMember.dataType)
5230 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5231 type = bitMember.dataType;
5232 if(type.kind == classType && type._class && type._class.registered)
5234 if(!type._class.registered.dataType)
5235 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5236 type = type._class.registered.dataType;
5241 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5242 case shortType: { uint16 v; type.isSigned ? GetShort(value, (short *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5244 case longType: { uint v; type.isSigned ? GetInt(value, (int *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5245 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (int64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5246 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (intptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5247 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (intsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5249 bits |= part << bitMember.pos;
5255 if(_class && _class.type == unitClass)
5257 ComputeExpression(member.initializer.exp);
5258 exp.constant = member.initializer.exp.constant;
5259 exp.type = constantExp;
5261 member.initializer.exp.constant = null;
5271 if(_class && _class.type == bitClass)
5273 exp.constant = PrintHexUInt(bits);
5274 exp.type = constantExp;
5276 if(exp.type != instanceExp)
5282 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5284 bool result = false;
5288 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5289 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5293 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5294 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5297 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5298 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5299 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5302 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5303 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5304 result = GetOpFloat(op, &op.f);
5307 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5308 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5309 result = GetOpDouble(op, &op.d);
5312 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5313 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5314 result = GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5317 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5318 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5319 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5322 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5323 result = isSigned ? GetOpInt64 /*GetOpIntPtr*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5326 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5327 result = isSigned ? GetOpInt64 /*GetOpIntSize*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntSize*/(op, &op.ui64);
5333 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5335 if(exp.op.op == SIZEOF)
5337 FreeExpContents(exp);
5338 exp.type = constantExp;
5339 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5350 // Provide default unary +
5351 Expression exp2 = exp.op.exp2;
5353 FreeExpContents(exp);
5354 FreeType(exp.expType);
5355 FreeType(exp.destType);
5361 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5363 // unary arithmetic increment and decrement
5364 //OPERATOR_ALL(UNARY, ++, Inc)
5365 //OPERATOR_ALL(UNARY, --, Dec)
5368 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5370 // unary logical negation
5372 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5378 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5380 if(Promote(op2, op1.kind, op1.type.isSigned))
5381 op2.kind = op1.kind, op2.ops = op1.ops;
5382 else if(Promote(op1, op2.kind, op2.type.isSigned))
5383 op1.kind = op2.kind, op1.ops = op2.ops;
5387 // binary arithmetic
5389 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5392 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5395 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5398 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5401 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5403 // binary arithmetic assignment
5404 //OPERATOR_ALL(BINARY, =, Asign)
5405 //OPERATOR_ALL(BINARY, +=, AddAsign)
5406 //OPERATOR_ALL(BINARY, -=, SubAsign)
5407 //OPERATOR_ALL(BINARY, *=, MulAsign)
5408 //OPERATOR_ALL(BINARY, /=, DivAsign)
5409 //OPERATOR_ALL(BINARY, %=, ModAsign)
5414 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5418 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5421 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5424 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5427 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5429 // binary bitwise assignment
5430 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5431 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5432 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5433 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5434 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5435 // binary logical equality
5437 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5440 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5444 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5447 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5449 // binary logical relational
5451 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5454 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5457 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5460 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5467 void ComputeExpression(Expression exp)
5469 char expString[10240];
5470 expString[0] = '\0';
5472 PrintExpression(exp, expString);
5479 ComputeInstantiation(exp);
5488 Expression exp1, exp2 = null;
5492 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5495 Expression e = exp.op.exp2;
5497 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5499 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5501 if(e.type == extensionCompoundExp)
5502 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5507 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5509 if(e.type == stringExp && e.string)
5511 char * string = e.string;
5512 int len = strlen(string);
5513 char * tmp = new char[len-2+1];
5514 len = UnescapeString(tmp, string + 1, len - 2);
5516 FreeExpContents(exp);
5517 exp.type = constantExp;
5518 exp.constant = PrintUInt(len + 1);
5522 Type type = e.expType;
5524 FreeExpContents(exp);
5525 exp.type = constantExp;
5526 exp.constant = PrintUInt(ComputeTypeSize(type));
5532 ComputeExpression(exp.op.exp2);
5536 ComputeExpression(exp.op.exp1);
5539 op1 = GetOperand(exp1);
5540 if(op1.type) op1.type.refCount++;
5543 op2 = GetOperand(exp2);
5544 if(op2.type) op2.type.refCount++;
5550 op1 = GetOperand(exp1);
5551 if(op1.type) op1.type.refCount++;
5554 CallOperator(exp, exp1, exp2, op1, op2);
5561 if(exp.op.exp1 && exp.op.exp2)
5566 FreeExpContents(exp);
5567 op1.ops.BitAnd(exp, op1, op2);
5576 FreeExpContents(exp);
5577 op1.ops.Mul(exp, op1, op2);
5586 FreeExpContents(exp);
5587 op1.ops.Add(exp, op1, op2);
5592 // Provide default unary +
5593 Expression exp2 = exp.op.exp2;
5595 FreeExpContents(exp);
5596 FreeType(exp.expType);
5597 FreeType(exp.destType);
5608 FreeExpContents(exp);
5609 op1.ops.Sub(exp, op1, op2);
5616 FreeExpContents(exp);
5617 op1.ops.Neg(exp, op1);
5624 FreeExpContents(exp);
5625 op1.ops.BitNot(exp, op1);
5631 FreeExpContents(exp);
5632 op1.ops.Not(exp, op1);
5635 // Binary only operators
5639 FreeExpContents(exp);
5640 op1.ops.Div(exp, op1, op2);
5646 FreeExpContents(exp);
5647 op1.ops.Mod(exp, op1, op2);
5659 FreeExpContents(exp);
5660 op1.ops.Sma(exp, op1, op2);
5669 FreeExpContents(exp);
5670 op1.ops.Grt(exp, op1, op2);
5679 FreeExpContents(exp);
5680 op1.ops.SmaEqu(exp, op1, op2);
5689 FreeExpContents(exp);
5690 op1.ops.GrtEqu(exp, op1, op2);
5699 FreeExpContents(exp);
5700 op1.ops.Equ(exp, op1, op2);
5709 FreeExpContents(exp);
5710 op1.ops.Nqu(exp, op1, op2);
5717 FreeExpContents(exp);
5718 op1.ops.BitOr(exp, op1, op2);
5724 FreeExpContents(exp);
5725 op1.ops.BitXor(exp, op1, op2);
5733 FreeExpContents(exp);
5734 exp.type = constantExp;
5735 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5739 if(op1.type) FreeType(op1.type);
5740 if(op2.type) FreeType(op2.type);
5744 case extensionExpressionExp:
5747 for(e = exp.list->first; e; e = n)
5752 OldList * list = exp.list;
5753 Expression prev = exp.prev;
5754 Expression next = exp.next;
5755 ComputeExpression(e);
5756 //FreeExpContents(exp);
5757 FreeType(exp.expType);
5758 FreeType(exp.destType);
5777 exp.isConstant = true;
5779 ComputeExpression(exp.index.exp);
5780 if(!exp.index.exp.isConstant)
5781 exp.isConstant = false;
5783 for(e = exp.index.index->first; e; e = e.next)
5785 ComputeExpression(e);
5788 // Check if this type is int
5791 exp.isConstant = false;
5793 exp.expType = Dereference(exp.index.exp.expType);
5799 Expression memberExp = exp.member.exp;
5800 Identifier memberID = exp.member.member;
5803 ComputeExpression(exp.member.exp);
5804 type = exp.member.exp.expType;
5807 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);
5808 Property prop = null;
5809 DataMember member = null;
5810 Class convertTo = null;
5811 if(type.kind == subClassType && exp.member.exp.type == classExp)
5812 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5819 PrintTypeNoConst(type, string, false, true);
5820 classSym = FindClass(string);
5821 _class = classSym ? classSym.registered : null;
5824 if(exp.member.member)
5826 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5828 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5830 if(!prop && !member && _class && exp.member.member)
5832 Symbol classSym = FindClass(exp.member.member.string);
5834 _class = classSym ? classSym.registered : null;
5835 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5842 Type type = prop.dataType;
5843 // TODO: Assuming same base type for units...
5844 if(_class.type == unitClass)
5846 if(type.kind == classType)
5848 Class _class = type._class.registered;
5849 if(_class.type == unitClass)
5851 if(!_class.dataType)
5852 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5853 type = _class.dataType;
5861 float (*Get)(float) = (void *)prop.Get;
5862 GetFloat(exp.member.exp, &value);
5863 exp.constant = PrintFloat(Get ? Get(value) : value);
5864 exp.type = constantExp;
5870 double (*Get)(double);
5871 GetDouble(exp.member.exp, &value);
5874 Get = (void *)prop.Set;
5876 Get = (void *)prop.Get;
5877 exp.constant = PrintDouble(Get ? Get(value) : value);
5878 exp.type = constantExp;
5887 Expression value = exp.member.exp;
5890 ProcessPropertyType(prop);
5892 type = prop.dataType;
5895 // printf("Investigate this\n");
5897 else if(_class.type == structClass)
5903 Class propertyClass = type._class.registered;
5904 if(propertyClass.type == structClass && value.type == instanceExp)
5906 void (*Set)(void *, void *) = (void *)prop.Set;
5907 exp.instance = Instantiation { };
5908 exp.instance.data = new0 byte[_class.structSize];
5909 exp.instance._class = MkSpecifierName(_class.fullName);
5910 exp.instance.loc = exp.loc;
5911 exp.type = instanceExp;
5912 Set(exp.instance.data, value.instance.data);
5913 PopulateInstance(exp.instance);
5920 void (*Set)(void *, int) = (void *)prop.Set;
5922 exp.instance = Instantiation { };
5923 exp.instance.data = new0 byte[_class.structSize];
5924 exp.instance._class = MkSpecifierName(_class.fullName);
5925 exp.instance.loc = exp.loc;
5926 exp.type = instanceExp;
5928 GetInt(value, &intValue);
5930 Set(exp.instance.data, intValue);
5931 PopulateInstance(exp.instance);
5937 void (*Set)(void *, int64) = (void *)prop.Set;
5939 exp.instance = Instantiation { };
5940 exp.instance.data = new0 byte[_class.structSize];
5941 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5942 exp.instance.loc = exp.loc;
5943 exp.type = instanceExp;
5945 GetInt64(value, &intValue);
5947 Set(exp.instance.data, intValue);
5948 PopulateInstance(exp.instance);
5955 void (*Set)(void *, intptr) = (void *)prop.Set;
5957 exp.instance = Instantiation { };
5958 exp.instance.data = new0 byte[_class.structSize];
5959 exp.instance._class = MkSpecifierName(_class.fullName);
5960 exp.instance.loc = exp.loc;
5961 exp.type = instanceExp;
5963 GetIntPtr(value, &intValue);
5965 Set(exp.instance.data, intValue);
5966 PopulateInstance(exp.instance);
5973 void (*Set)(void *, intsize) = (void *)prop.Set;
5975 exp.instance = Instantiation { };
5976 exp.instance.data = new0 byte[_class.structSize];
5977 exp.instance._class = MkSpecifierName(_class.fullName);
5978 exp.instance.loc = exp.loc;
5979 exp.type = instanceExp;
5981 GetIntSize(value, &intValue);
5983 Set(exp.instance.data, intValue);
5984 PopulateInstance(exp.instance);
5990 void (*Set)(void *, float) = (void *)prop.Set;
5992 exp.instance = Instantiation { };
5993 exp.instance.data = new0 byte[_class.structSize];
5994 exp.instance._class = MkSpecifierName(_class.fullName);
5995 exp.instance.loc = exp.loc;
5996 exp.type = instanceExp;
5998 GetFloat(value, &floatValue);
6000 Set(exp.instance.data, floatValue);
6001 PopulateInstance(exp.instance);
6007 void (*Set)(void *, double) = (void *)prop.Set;
6009 exp.instance = Instantiation { };
6010 exp.instance.data = new0 byte[_class.structSize];
6011 exp.instance._class = MkSpecifierName(_class.fullName);
6012 exp.instance.loc = exp.loc;
6013 exp.type = instanceExp;
6015 GetDouble(value, &doubleValue);
6017 Set(exp.instance.data, doubleValue);
6018 PopulateInstance(exp.instance);
6023 else if(_class.type == bitClass)
6029 Class propertyClass = type._class.registered;
6030 if(propertyClass.type == structClass && value.instance.data)
6032 unsigned int (*Set)(void *) = (void *)prop.Set;
6033 unsigned int bits = Set(value.instance.data);
6034 exp.constant = PrintHexUInt(bits);
6035 exp.type = constantExp;
6038 else if(_class.type == bitClass)
6041 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6044 GetUInt(exp.member.exp, &value);
6046 exp.constant = PrintHexUInt(bits);
6047 exp.type = constantExp;
6055 if(_class.type == bitClass)
6058 GetUInt(exp.member.exp, &value);
6064 Class _class = type._class.registered;
6065 if(_class.type == structClass)
6067 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6069 exp.instance = Instantiation { };
6070 exp.instance.data = new0 byte[_class.structSize];
6071 exp.instance._class = MkSpecifierName(_class.fullName);
6072 exp.instance.loc = exp.loc;
6073 //exp.instance.fullSet = true;
6074 exp.type = instanceExp;
6075 Get(value, exp.instance.data);
6076 PopulateInstance(exp.instance);
6078 else if(_class.type == bitClass)
6080 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6081 uint64 bits = Get(value);
6082 exp.constant = PrintHexUInt64(bits);
6083 exp.type = constantExp;
6089 else if(_class.type == structClass)
6091 byte * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6096 Class _class = type._class.registered;
6097 if(_class.type == structClass && value)
6099 void (*Get)(void *, void *) = (void *)prop.Get;
6101 exp.instance = Instantiation { };
6102 exp.instance.data = new0 byte[_class.structSize];
6103 exp.instance._class = MkSpecifierName(_class.fullName);
6104 exp.instance.loc = exp.loc;
6105 //exp.instance.fullSet = true;
6106 exp.type = instanceExp;
6107 Get(value, exp.instance.data);
6108 PopulateInstance(exp.instance);
6116 char * value = exp.member.exp.instance.data;
6121 Class _class = type._class.registered;
6122 if(_class.type == normalClass)
6124 void *(*Get)(void *) = (void *)prop.Get;
6126 exp.instance = Instantiation { };
6127 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6128 exp.type = instanceExp;
6129 exp.instance.data = Get(value, exp.instance.data);
6141 exp.isConstant = false;
6149 if(exp.type != ExpressionType::memberExp)
6151 FreeExpression(memberExp);
6152 FreeIdentifier(memberID);
6158 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6159 FreeExpContents(exp);
6160 exp.constant = PrintUInt(ComputeTypeSize(type));
6161 exp.type = constantExp;
6167 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6168 if(classSym && classSym.registered)
6170 if(classSym.registered.fixed)
6172 FreeSpecifier(exp._class);
6173 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6174 exp.type = constantExp;
6178 char className[1024];
6179 strcpy(className, "__ecereClass_");
6180 FullClassNameCat(className, classSym.string, true);
6181 //MangleClassName(className);
6183 DeclareClass(classSym, className);
6185 FreeExpContents(exp);
6186 exp.type = pointerExp;
6187 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6188 exp.member.member = MkIdentifier("structSize");
6198 if(exp.type == castExp)
6201 ComputeExpression(exp.cast.exp);
6204 if(e && exp.expType)
6207 type = exp.destType;
6210 if(type.kind == classType)
6212 Class _class = type._class.registered;
6213 if(_class && (_class.type == unitClass || _class.type == bitClass))
6215 if(!_class.dataType)
6216 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6217 type = _class.dataType;
6228 if(GetChar(e, &value))
6230 FreeExpContents(exp);
6231 exp.constant = PrintChar(value);
6232 exp.type = constantExp;
6237 unsigned char value = 0;
6238 if(GetUChar(e, &value))
6240 FreeExpContents(exp);
6241 exp.constant = PrintUChar(value);
6242 exp.type = constantExp;
6250 if(GetShort(e, &value))
6252 FreeExpContents(exp);
6253 exp.constant = PrintShort(value);
6254 exp.type = constantExp;
6259 unsigned short value = 0;
6260 if(GetUShort(e, &value))
6262 FreeExpContents(exp);
6263 exp.constant = PrintUShort(value);
6264 exp.type = constantExp;
6272 if(GetInt(e, &value))
6274 FreeExpContents(exp);
6275 exp.constant = PrintInt(value);
6276 exp.type = constantExp;
6281 unsigned int value = 0;
6282 if(GetUInt(e, &value))
6284 FreeExpContents(exp);
6285 exp.constant = PrintUInt(value);
6286 exp.type = constantExp;
6294 if(GetInt64(e, &value))
6296 FreeExpContents(exp);
6297 exp.constant = PrintInt64(value);
6298 exp.type = constantExp;
6304 if(GetUInt64(e, &value))
6306 FreeExpContents(exp);
6307 exp.constant = PrintUInt64(value);
6308 exp.type = constantExp;
6316 if(GetIntPtr(e, &value))
6318 FreeExpContents(exp);
6319 exp.constant = PrintInt64((int64)value);
6320 exp.type = constantExp;
6326 if(GetUIntPtr(e, &value))
6328 FreeExpContents(exp);
6329 exp.constant = PrintUInt64((uint64)value);
6330 exp.type = constantExp;
6338 if(GetIntSize(e, &value))
6340 FreeExpContents(exp);
6341 exp.constant = PrintInt64((int64)value);
6342 exp.type = constantExp;
6348 if(GetUIntSize(e, &value))
6350 FreeExpContents(exp);
6351 exp.constant = PrintUInt64((uint64)value);
6352 exp.type = constantExp;
6359 if(GetFloat(e, &value))
6361 FreeExpContents(exp);
6362 exp.constant = PrintFloat(value);
6363 exp.type = constantExp;
6370 if(GetDouble(e, &value))
6372 FreeExpContents(exp);
6373 exp.constant = PrintDouble(value);
6374 exp.type = constantExp;
6389 // Caring only about last expression for now...
6390 ComputeExpression(exp.cond.exp->last);
6391 if(exp.cond.elseExp)
6392 ComputeExpression(exp.cond.elseExp);
6394 ComputeExpression(exp.cond.cond);
6396 op1 = GetOperand(exp.cond.cond);
6397 if(op1.type) op1.type.refCount++;
6398 op2 = GetOperand(exp.cond.exp->last);
6399 if(op2.type) op2.type.refCount++;
6400 op3 = GetOperand(exp.cond.elseExp);
6401 if(op3.type) op3.type.refCount++;
6403 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6404 if(op1.type) FreeType(op1.type);
6405 if(op2.type) FreeType(op2.type);
6406 if(op3.type) FreeType(op3.type);
6412 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6417 OldList converts { };
6420 if(destType.kind == voidType)
6423 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6427 // for(convert = converts.last; convert; convert = convert.prev)
6428 for(convert = converts.first; convert; convert = convert.next)
6430 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6433 Expression newExp { };
6434 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6436 // TODO: Check this...
6440 newExp.destType = null;
6445 exp.type = memberExp;
6446 exp.addedThis = true;
6447 exp.member.exp = newExp;
6448 FreeType(exp.member.exp.expType);
6450 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6451 exp.member.exp.expType.classObjectType = objectType;
6452 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6453 exp.member.memberType = propertyMember;
6454 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6455 // TESTING THIS... for (int)degrees
6456 exp.needCast = true;
6457 if(exp.expType) exp.expType.refCount++;
6458 ApplyAnyObjectLogic(exp.member.exp);
6463 /*if(exp.isConstant)
6465 // Color { ColorRGB = [exp] };
6466 exp.type = instanceExp;
6467 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6468 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6469 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6473 // If not constant, don't turn it yet into an instantiation
6474 // (Go through the deep members system first)
6475 exp.type = memberExp;
6476 exp.addedThis = true;
6477 exp.member.exp = newExp;
6479 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6480 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6481 newExp.expType._class.registered.type == noHeadClass)
6483 newExp.byReference = true;
6486 FreeType(exp.member.exp.expType);
6487 /*exp.member.exp.expType = convert.convert.dataType;
6488 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6489 exp.member.exp.expType = null;
6490 if(convert.convert.dataType)
6492 exp.member.exp.expType = { };
6493 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6494 exp.member.exp.expType.refCount = 1;
6495 exp.member.exp.expType.classObjectType = objectType;
6496 ApplyAnyObjectLogic(exp.member.exp);
6499 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6500 exp.member.memberType = reverseConversionMember;
6501 exp.expType = convert.resultType ? convert.resultType :
6502 MkClassType(convert.convert._class.fullName);
6503 exp.needCast = true;
6504 if(convert.resultType) convert.resultType.refCount++;
6510 FreeType(exp.expType);
6513 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6514 if(exp.destType.casted)
6515 exp.needCast = true;
6516 if(exp.expType) exp.expType.refCount++;
6520 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6521 if(exp.destType.casted)
6522 exp.needCast = true;
6523 if(convert.resultType)
6524 convert.resultType.refCount++;
6528 if(exp.isConstant && inCompiler)
6529 ComputeExpression(exp);
6531 converts.Free(FreeConvert);
6534 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6536 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6538 if(!result && exp.expType && exp.destType)
6540 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6541 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6542 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6543 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6547 // if(result) CheckTemplateTypes(exp);
6551 void CheckTemplateTypes(Expression exp)
6553 Expression nbExp = GetNonBracketsExp(exp);
6554 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6555 (nbExp == exp || nbExp.type != castExp))
6557 Expression newExp { };
6560 if(exp.destType) exp.destType.refCount++;
6561 if(exp.expType) exp.expType.refCount++;
6565 switch(exp.expType.kind)
6568 if(exp.destType.classObjectType)
6570 // We need to pass the address, just pass it along (Undo what was done above)
6571 if(exp.destType) exp.destType.refCount--;
6572 if(exp.expType) exp.expType.refCount--;
6577 // If we're looking for value:
6578 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6580 OldList * unionDefs = MkList();
6581 OldList * statements = MkList();
6582 context = PushContext();
6583 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6584 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6585 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6586 exp.type = extensionCompoundExp;
6587 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6588 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6589 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6590 exp.compound.compound.context = context;
6591 PopContext(context);
6596 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6597 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6598 exp.needCast = true;
6602 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6604 Expression newExp { };
6607 if(exp.destType) exp.destType.refCount++;
6608 if(exp.expType) exp.expType.refCount++;
6612 switch(exp.expType.kind)
6615 if(exp.destType.classObjectType)
6617 // We need to pass the address, just pass it along (Undo what was done above)
6618 if(exp.destType) exp.destType.refCount--;
6619 if(exp.expType) exp.expType.refCount--;
6624 // If we're looking for value:
6625 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6627 OldList * unionDefs = MkList();
6628 OldList * statements = MkList();
6629 context = PushContext();
6630 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6631 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6632 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6633 exp.type = extensionCompoundExp;
6634 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6635 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6636 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6637 exp.compound.compound.context = context;
6638 PopContext(context);
6643 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6645 exp.type = bracketsExp;
6646 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6647 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6648 ProcessExpressionType(exp.list->first);
6653 exp.type = bracketsExp;
6654 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6655 exp.needTemplateCast = 2;
6656 newExp.needCast = true;
6657 newExp.needTemplateCast = 2;
6658 ProcessExpressionType(exp.list->first);
6664 if(exp.expType.kind == templateType)
6666 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6669 FreeType(exp.destType);
6670 FreeType(exp.expType);
6675 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6680 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6681 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6685 char typeString[1024];
6687 OldList * specs = MkList();
6688 typeString[0] = '\0';
6689 PrintType(exp.expType, typeString, false, false);
6690 decl = SpecDeclFromString(typeString, specs, null);
6693 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6694 exp.cast.typeName = MkTypeName(specs, decl);
6695 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6696 exp.cast.exp.needCast = true;
6703 // TODO: The Symbol tree should be reorganized by namespaces
6705 // - Tree of all symbols within (stored without namespace)
6706 // - Tree of sub-namespaces
6708 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6710 int nsLen = strlen(nameSpace);
6712 // Start at the name space prefix
6713 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6715 char * s = symbol.string;
6716 if(!strncmp(s, nameSpace, nsLen))
6718 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6721 for(c = strlen(s)-1; c >= 0; c--)
6726 if(!strcmp(namePart, name))
6728 // TODO: Error on ambiguity
6738 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6741 char nameSpace[1024];
6742 const char * namePart;
6743 bool gotColon = false;
6745 nameSpace[0] = '\0';
6746 for(c = strlen(name)-1; c >= 0; c--)
6753 namePart = name+c+1;
6754 while(c >= 0 && name[c] == ':') c--;
6757 // Try an exact match first
6758 Symbol symbol = (Symbol)tree.FindString(name);
6762 // Namespace specified
6763 memcpy(nameSpace, name, c + 1);
6766 return ScanWithNameSpace(tree, nameSpace, namePart);
6770 // Looking for a global symbol, e.g. ::Sleep()
6771 Symbol symbol = (Symbol)tree.FindString(namePart);
6776 // Name only (no namespace specified)
6777 Symbol symbol = (Symbol)tree.FindString(namePart);
6780 return ScanWithNameSpace(tree, "", namePart);
6785 static void ProcessDeclaration(Declaration decl);
6787 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6790 //Time startTime = GetTime();
6792 // Optimize this later? Do this before/less?
6794 Symbol symbol = null;
6795 // First, check if the identifier is declared inside the function
6796 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6798 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6800 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6806 strcpy(curName, thisNameSpace);
6807 strcat(curName, "::");
6808 strcat(curName, name);
6809 // Try to resolve in current namespace first
6810 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6813 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6816 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6818 if(symbol || ctx == endContext) break;
6820 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6822 if(symbol.pointerExternal.type == functionExternal)
6824 FunctionDefinition function = symbol.pointerExternal.function;
6826 // Modified this recently...
6827 Context tmpContext = curContext;
6829 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6830 curContext = tmpContext;
6832 symbol.pointerExternal.symbol = symbol;
6835 DeclareType(symbol.type, true, true);
6837 ast->Insert(curExternal.prev, symbol.pointerExternal);
6839 symbol.id = curExternal.symbol.idCode;
6842 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6844 ast->Move(symbol.pointerExternal, curExternal.prev);
6845 symbol.id = curExternal.symbol.idCode;
6849 //findSymbolTotalTime += GetTime() - startTime;
6854 static void GetTypeSpecs(Type type, OldList * specs)
6856 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6861 if(type._class.registered)
6863 if(!type._class.registered.dataType)
6864 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6865 GetTypeSpecs(type._class.registered.dataType, specs);
6869 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6870 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6871 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6872 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6873 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6874 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6875 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6876 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6879 ListAdd(specs, MkSpecifier(INT)); break;
6883 static void PrintArraySize(Type arrayType, char * string)
6888 if(arrayType.enumClass)
6889 strcat(size, arrayType.enumClass.string);
6890 else if(arrayType.arraySizeExp)
6891 PrintExpression(arrayType.arraySizeExp, size);
6893 strcat(string, size);
6896 // WARNING : This function expects a null terminated string since it recursively concatenate...
6897 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6901 if(printConst && type.constant)
6902 strcat(string, "const ");
6907 Symbol c = type._class;
6908 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6909 // look into merging with thisclass ?
6910 if(type.classObjectType == typedObject)
6911 strcat(string, "typed_object");
6912 else if(type.classObjectType == anyObject)
6913 strcat(string, "any_object");
6917 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6919 if(type.byReference)
6920 strcat(string, " &");
6923 case voidType: strcat(string, "void"); break;
6924 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6925 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6926 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6927 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6928 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6929 case _BoolType: strcat(string, "_Bool"); break;
6930 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6931 case floatType: strcat(string, "float"); break;
6932 case doubleType: strcat(string, "double"); break;
6936 strcat(string, "struct ");
6937 strcat(string, type.enumName);
6939 else if(type.typeName)
6940 strcat(string, type.typeName);
6944 strcat(string, "struct { ");
6945 for(member = type.members.first; member; member = member.next)
6947 PrintType(member, string, true, fullName);
6948 strcat(string,"; ");
6956 strcat(string, "union ");
6957 strcat(string, type.enumName);
6959 else if(type.typeName)
6960 strcat(string, type.typeName);
6963 strcat(string, "union ");
6964 strcat(string,"(unnamed)");
6970 strcat(string, "enum ");
6971 strcat(string, type.enumName);
6973 else if(type.typeName)
6974 strcat(string, type.typeName);
6976 strcat(string, "int"); // "enum");
6979 strcat(string, "...");
6982 strcat(string, "subclass(");
6983 strcat(string, type._class ? type._class.string : "int");
6984 strcat(string, ")");
6987 strcat(string, type.templateParameter.identifier.string);
6990 strcat(string, "thisclass");
6993 strcat(string, "__builtin_va_list");
6999 static void PrintName(Type type, char * string, bool fullName)
7001 if(type.name && type.name[0])
7004 strcat(string, type.name);
7007 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
7008 if(name) name += 2; else name = type.name;
7009 strcat(string, name);
7014 static void PrintAttribs(Type type, char * string)
7018 if(type.dllExport) strcat(string, "dllexport ");
7019 if(type.attrStdcall) strcat(string, "stdcall ");
7023 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7025 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7027 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7028 PrintAttribs(type, string);
7029 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7030 strcat(string, " const");
7031 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7032 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7033 strcat(string, " (");
7034 if(type.kind == pointerType)
7036 if(type.type.kind == functionType || type.type.kind == methodType)
7037 PrintAttribs(type.type, string);
7039 if(type.kind == pointerType)
7041 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7042 strcat(string, "*");
7044 strcat(string, " *");
7046 if(printConst && type.constant && type.kind == pointerType)
7047 strcat(string, " const");
7050 PrintTypeSpecs(type, string, fullName, printConst);
7053 static void PostPrintType(Type type, char * string, bool fullName)
7055 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7056 strcat(string, ")");
7057 if(type.kind == arrayType)
7058 PrintArraySize(type, string);
7059 else if(type.kind == functionType)
7062 strcat(string, "(");
7063 for(param = type.params.first; param; param = param.next)
7065 PrintType(param, string, true, fullName);
7066 if(param.next) strcat(string, ", ");
7068 strcat(string, ")");
7070 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7071 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7075 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7077 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7079 PrePrintType(type, string, fullName, null, printConst);
7081 if(type.thisClass || (printName && type.name && type.name[0]))
7082 strcat(string, " ");
7083 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7085 Symbol _class = type.thisClass;
7086 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7088 if(type.classObjectType == classPointer)
7089 strcat(string, "class");
7091 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7093 else if(_class && _class.string)
7095 String s = _class.string;
7100 char * name = RSearchString(s, "::", strlen(s), true, false);
7101 if(name) name += 2; else name = s;
7102 strcat(string, name);
7105 strcat(string, "::");
7108 if(printName && type.name)
7109 PrintName(type, string, fullName);
7110 PostPrintType(type, string, fullName);
7111 if(type.bitFieldCount)
7114 sprintf(count, ":%d", type.bitFieldCount);
7115 strcat(string, count);
7119 void PrintType(Type type, char * string, bool printName, bool fullName)
7121 _PrintType(type, string, printName, fullName, true);
7124 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7126 _PrintType(type, string, printName, fullName, false);
7129 static Type FindMember(Type type, char * string)
7132 for(memberType = type.members.first; memberType; memberType = memberType.next)
7134 if(!memberType.name)
7136 Type subType = FindMember(memberType, string);
7140 else if(!strcmp(memberType.name, string))
7146 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7149 for(memberType = type.members.first; memberType; memberType = memberType.next)
7151 if(!memberType.name)
7153 Type subType = FindMember(memberType, string);
7156 *offset += memberType.offset;
7160 else if(!strcmp(memberType.name, string))
7162 *offset += memberType.offset;
7169 public bool GetParseError() { return parseError; }
7171 Expression ParseExpressionString(char * expression)
7175 fileInput = TempFile { };
7176 fileInput.Write(expression, 1, strlen(expression));
7177 fileInput.Seek(0, start);
7180 parsedExpression = null;
7182 expression_yyparse();
7185 return parsedExpression;
7188 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7190 Identifier id = exp.identifier;
7191 Method method = null;
7192 Property prop = null;
7193 DataMember member = null;
7194 ClassProperty classProp = null;
7196 if(_class && _class.type == enumClass)
7198 NamedLink value = null;
7199 Class enumClass = eSystem_FindClass(privateModule, "enum");
7203 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7205 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7206 for(value = e.values.first; value; value = value.next)
7208 if(!strcmp(value.name, id.string))
7215 FreeExpContents(exp);
7217 exp.type = constantExp;
7218 exp.isConstant = true;
7219 if(!strcmp(baseClass.dataTypeString, "int"))
7220 sprintf(constant, "%d",(int)value.data);
7222 sprintf(constant, "0x%X",(int)value.data);
7223 exp.constant = CopyString(constant);
7224 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7225 exp.expType = MkClassType(baseClass.fullName);
7233 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7235 ProcessMethodType(method);
7242 // TOCHECK: Put it back to what it was...
7243 // methodClass = _class;
7244 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7249 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7252 ProcessPropertyType(prop);
7253 exp.expType = prop.dataType;
7254 if(prop.dataType) prop.dataType.refCount++;
7257 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7259 if(!member.dataType)
7260 member.dataType = ProcessTypeString(member.dataTypeString, false);
7261 exp.expType = member.dataType;
7262 if(member.dataType) member.dataType.refCount++;
7265 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7267 if(!classProp.dataType)
7268 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7270 if(classProp.constant)
7272 FreeExpContents(exp);
7274 exp.isConstant = true;
7275 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7277 //char constant[256];
7278 exp.type = stringExp;
7279 exp.constant = QMkString((char *)classProp.Get(_class));
7284 exp.type = constantExp;
7285 sprintf(constant, "%d", (int)classProp.Get(_class));
7286 exp.constant = CopyString(constant);
7294 exp.expType = classProp.dataType;
7295 if(classProp.dataType) classProp.dataType.refCount++;
7301 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7303 BinaryTree * tree = &nameSpace.functions;
7304 GlobalData data = (GlobalData)tree->FindString(name);
7308 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7310 data = ScanGlobalData(child, name);
7318 static GlobalData FindGlobalData(char * name)
7321 NameSpace * nameSpace;
7322 nameSpace = globalData;
7323 for(c = 0; name[c]; c++)
7325 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7327 NameSpace * newSpace;
7328 char * spaceName = new char[c - start + 1];
7329 strncpy(spaceName, name + start, c - start);
7330 spaceName[c-start] = '\0';
7331 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7335 nameSpace = newSpace;
7336 if(name[c] == ':') c++;
7342 return ScanGlobalData(nameSpace, name + start);
7347 static int definedExpStackPos;
7348 static void * definedExpStack[512];
7350 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7351 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7353 Expression prev = checkedExp.prev, next = checkedExp.next;
7355 FreeExpContents(checkedExp);
7356 FreeType(checkedExp.expType);
7357 FreeType(checkedExp.destType);
7359 *checkedExp = *newExp;
7363 checkedExp.prev = prev;
7364 checkedExp.next = next;
7367 void ApplyAnyObjectLogic(Expression e)
7369 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7371 char debugExpString[4096];
7372 debugExpString[0] = '\0';
7373 PrintExpression(e, debugExpString);
7376 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7378 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7379 //ellipsisDestType = destType;
7382 Type type = e.expType;
7383 Class _class = null;
7384 //Type destType = e.destType;
7386 if(type.kind == classType && type._class && type._class.registered)
7388 _class = type._class.registered;
7390 else if(type.kind == subClassType)
7392 _class = FindClass("ecere::com::Class").registered;
7396 char string[1024] = "";
7399 PrintTypeNoConst(type, string, false, true);
7400 classSym = FindClass(string);
7401 if(classSym) _class = classSym.registered;
7404 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...
7405 (!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))) ||
7406 destType.byReference)))
7408 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7410 Expression checkedExp = e, newExp;
7412 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7414 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7416 if(checkedExp.type == extensionCompoundExp)
7418 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7421 checkedExp = checkedExp.list->last;
7423 else if(checkedExp.type == castExp)
7424 checkedExp = checkedExp.cast.exp;
7427 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7429 newExp = checkedExp.op.exp2;
7430 checkedExp.op.exp2 = null;
7431 FreeExpContents(checkedExp);
7433 if(e.expType && e.expType.passAsTemplate)
7436 ComputeTypeSize(e.expType);
7437 sprintf(size, "%d", e.expType.size);
7438 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7439 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7440 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7443 ReplaceExpContents(checkedExp, newExp);
7444 e.byReference = true;
7446 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7448 Expression checkedExp; //, newExp;
7451 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7453 e.type == identifierExp ||
7454 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7455 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7456 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7459 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7461 Context context = PushContext();
7463 OldList * specs = MkList();
7464 char typeString[1024];
7465 Expression newExp { };
7467 typeString[0] = '\0';
7470 //if(e.destType) e.destType.refCount++;
7471 // if(exp.expType) exp.expType.refCount++;
7474 newExp.expType = null;
7476 PrintTypeNoConst(e.expType, typeString, false, true);
7477 decl = SpecDeclFromString(typeString, specs, null);
7478 newExp.destType = ProcessType(specs, decl);
7480 curContext = context;
7482 // We need a current compound for this
7486 OldList * stmts = MkList();
7487 e.type = extensionCompoundExp;
7488 sprintf(name, "__internalValue%03X", internalValueCounter++);
7489 if(!curCompound.compound.declarations)
7490 curCompound.compound.declarations = MkList();
7491 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7492 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7493 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7494 e.compound = MkCompoundStmt(null, stmts);
7497 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7500 e.compound = MkCompoundStmt(
7501 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7502 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7504 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7508 Type type = e.destType;
7510 CopyTypeInto(e.destType, type);
7511 e.destType.refCount = 1;
7512 e.destType.classObjectType = none;
7516 e.compound.compound.context = context;
7517 PopContext(context);
7518 curContext = context.parent;
7522 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7524 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7526 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7528 if(checkedExp.type == extensionCompoundExp)
7530 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7533 checkedExp = checkedExp.list->last;
7535 else if(checkedExp.type == castExp)
7536 checkedExp = checkedExp.cast.exp;
7539 Expression operand { };
7540 operand = *checkedExp;
7541 checkedExp.destType = null;
7542 checkedExp.expType = null;
7544 checkedExp.type = opExp;
7545 checkedExp.op.op = '&';
7546 checkedExp.op.exp1 = null;
7547 checkedExp.op.exp2 = operand;
7549 //newExp = MkExpOp(null, '&', checkedExp);
7551 //ReplaceExpContents(checkedExp, newExp);
7558 // If expression type is a simple class, make it an address
7559 // FixReference(e, true);
7562 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7563 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7564 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7566 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"))
7568 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7572 Expression thisExp { };
7575 thisExp.prev = null;
7576 thisExp.next = null;
7579 e.type = bracketsExp;
7580 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7581 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7582 ((Expression)e.list->first).byReference = true;
7584 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7586 e.expType = thisExp.expType;
7587 e.expType.refCount++;
7592 CopyTypeInto(e.expType, thisExp.expType);
7593 e.expType.byReference = false;
7594 e.expType.refCount = 1;
7596 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7597 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7599 e.expType.classObjectType = none;
7604 // TOFIX: Try this for a nice IDE crash!
7606 // The other way around
7609 if(destType && e.expType &&
7610 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7611 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7612 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7614 if(destType.kind == ellipsisType)
7616 Compiler_Error($"Unspecified type\n");
7618 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7620 bool byReference = e.expType.byReference;
7621 Expression thisExp { };
7623 OldList * specs = MkList();
7624 char typeString[1024]; // Watch buffer overruns
7626 ClassObjectType backupClassObjectType;
7627 bool backupByReference;
7629 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7634 backupClassObjectType = type.classObjectType;
7635 backupByReference = type.byReference;
7637 type.classObjectType = none;
7638 type.byReference = false;
7640 typeString[0] = '\0';
7641 PrintType(type, typeString, false, true);
7642 decl = SpecDeclFromString(typeString, specs, null);
7644 type.classObjectType = backupClassObjectType;
7645 type.byReference = backupByReference;
7648 thisExp.prev = null;
7649 thisExp.next = null;
7652 if( ( type.kind == classType && type._class && type._class.registered &&
7653 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7654 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7655 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7656 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7661 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7664 CopyTypeInto(e.expType, type);
7665 e.expType.byReference = false;
7666 e.expType.refCount = 1;
7671 e.cast.typeName = MkTypeName(specs, decl);
7672 e.cast.exp = thisExp;
7673 e.byReference = true;
7677 e.destType = destType;
7678 destType.refCount++;
7683 void ApplyLocation(Expression exp, Location loc)
7689 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7690 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7696 for(e = exp.list->first; e; e = e.next)
7697 ApplyLocation(e, loc);
7704 for(e = exp.index.index->first; e; e = e.next)
7705 ApplyLocation(e, loc);
7708 ApplyLocation(exp.index.exp, loc);
7711 if(exp.call.arguments)
7714 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7715 ApplyLocation(arg, loc);
7718 ApplyLocation(exp.call.exp, loc);
7723 ApplyLocation(exp.member.exp, loc);
7727 ApplyLocation(exp.cast.exp, loc);
7733 for(e = exp.cond.exp->first; e; e = e.next)
7734 ApplyLocation(e, loc);
7737 ApplyLocation(exp.cond.cond, loc);
7738 if(exp.cond.elseExp)
7739 ApplyLocation(exp.cond.elseExp, loc);
7743 ApplyLocation(exp.vaArg.exp, loc);
7750 void ProcessExpressionType(Expression exp)
7752 bool unresolved = false;
7753 Location oldyylloc = yylloc;
7754 bool notByReference = false;
7756 char debugExpString[4096];
7757 debugExpString[0] = '\0';
7758 PrintExpression(exp, debugExpString);
7760 if(!exp || exp.expType)
7763 //eSystem_Logf("%s\n", expString);
7765 // Testing this here
7771 Identifier id = exp.identifier;
7772 if(!id || !topContext) return;
7774 // DOING THIS LATER NOW...
7775 if(id._class && id._class.name)
7777 id.classSym = id._class.symbol; // FindClass(id._class.name);
7778 /* TODO: Name Space Fix ups
7780 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7784 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7786 exp.expType = ProcessTypeString("Module", true);
7789 else */if(strstr(id.string, "__ecereClass") == id.string)
7791 exp.expType = ProcessTypeString("ecere::com::Class", true);
7794 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7796 // Added this here as well
7797 ReplaceClassMembers(exp, thisClass);
7798 if(exp.type != identifierExp)
7800 ProcessExpressionType(exp);
7804 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7809 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7810 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7811 if(!symbol/* && exp.destType*/)
7813 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7819 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7820 if(exp.type != identifierExp)
7822 ProcessExpressionType(exp);
7826 // Static methods called from inside the _class
7827 else if(currentClass && !id._class)
7829 if(ResolveIdWithClass(exp, currentClass, true))
7832 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7836 // If we manage to resolve this symbol
7839 Type type = symbol.type;
7840 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7842 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7844 Context context = SetupTemplatesContext(_class);
7845 type = ReplaceThisClassType(_class);
7846 FinishTemplatesContext(context);
7847 if(type) type.refCount = 0; // We'll be incrementing it right below...
7850 FreeSpecifier(id._class);
7853 id.string = CopyString(symbol.string);
7860 // Commented this out, it was making non-constant enum parameters seen as constant
7861 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7862 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7863 // Add missing cases here... enum Classes...
7864 exp.isConstant = true;
7866 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7867 if(symbol.isParam || !strcmp(id.string, "this"))
7869 if(_class && _class.type == structClass && !type.declaredWithStruct)
7870 exp.byReference = true;
7872 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7873 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7874 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7875 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7877 Identifier id = exp.identifier;
7878 exp.type = bracketsExp;
7879 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7883 if(symbol.isIterator)
7885 if(symbol.isIterator == 3)
7887 exp.type = bracketsExp;
7888 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7889 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7891 ProcessExpressionType(exp);
7893 else if(symbol.isIterator != 4)
7895 exp.type = memberExp;
7896 exp.member.exp = MkExpIdentifier(exp.identifier);
7897 exp.member.exp.expType = exp.expType;
7898 /*if(symbol.isIterator == 6)
7899 exp.member.member = MkIdentifier("key");
7901 exp.member.member = MkIdentifier("data");
7903 ProcessExpressionType(exp);
7910 DefinedExpression definedExp = null;
7911 if(thisNameSpace && !(id._class && !id._class.name))
7914 strcpy(name, thisNameSpace);
7916 strcat(name, id.string);
7917 definedExp = eSystem_FindDefine(privateModule, name);
7920 definedExp = eSystem_FindDefine(privateModule, id.string);
7924 for(c = 0; c<definedExpStackPos; c++)
7925 if(definedExpStack[c] == definedExp)
7927 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7929 Location backupYylloc = yylloc;
7930 File backInput = fileInput;
7931 definedExpStack[definedExpStackPos++] = definedExp;
7933 fileInput = TempFile { };
7934 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7935 fileInput.Seek(0, start);
7938 parsedExpression = null;
7940 expression_yyparse();
7943 fileInput = backInput;
7945 yylloc = backupYylloc;
7947 if(parsedExpression)
7950 exp.type = bracketsExp;
7951 exp.list = MkListOne(parsedExpression);
7952 ApplyLocation(parsedExpression, yylloc);
7953 ProcessExpressionType(exp);
7954 definedExpStackPos--;
7957 definedExpStackPos--;
7963 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7969 GlobalData data = null;
7970 if(thisNameSpace && !(id._class && !id._class.name))
7973 strcpy(name, thisNameSpace);
7975 strcat(name, id.string);
7976 data = FindGlobalData(name);
7979 data = FindGlobalData(id.string);
7982 DeclareGlobalData(data);
7983 exp.expType = data.dataType;
7984 if(data.dataType) data.dataType.refCount++;
7987 id.string = CopyString(data.fullName);
7988 FreeSpecifier(id._class);
7995 GlobalFunction function = null;
7996 if(thisNameSpace && !(id._class && !id._class.name))
7999 strcpy(name, thisNameSpace);
8001 strcat(name, id.string);
8002 function = eSystem_FindFunction(privateModule, name);
8005 function = eSystem_FindFunction(privateModule, id.string);
8010 id.string = CopyString(function.name);
8013 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8014 strcpy(name, "__ecereFunction_");
8015 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8016 if(DeclareFunction(function, name))
8019 id.string = CopyString(name);
8021 exp.expType = function.dataType;
8022 if(function.dataType) function.dataType.refCount++;
8024 FreeSpecifier(id._class);
8041 if(!exp.instance._class)
8043 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8045 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8049 //classSym = FindClass(exp.instance._class.fullName);
8050 //_class = classSym ? classSym.registered : null;
8052 ProcessInstantiationType(exp.instance);
8054 exp.isConstant = exp.instance.isConstant;
8057 if(_class.type == unitClass && _class.base.type != systemClass)
8060 Type destType = exp.destType;
8062 exp.destType = MkClassType(_class.base.fullName);
8063 exp.expType = MkClassType(_class.fullName);
8064 CheckExpressionType(exp, exp.destType, true);
8066 exp.destType = destType;
8068 exp.expType = MkClassType(_class.fullName);
8071 if(exp.instance._class)
8073 exp.expType = MkClassType(exp.instance._class.name);
8074 /*if(exp.expType._class && exp.expType._class.registered &&
8075 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8076 exp.expType.byReference = true;*/
8084 char * constant = exp.constant;
8092 if(constant[0] == '\'')
8094 if((int)((byte *)constant)[1] > 127)
8097 unichar ch = UTF8GetChar(constant + 1, &nb);
8098 if(nb < 2) ch = constant[1];
8100 exp.constant = PrintUInt(ch);
8101 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8102 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8103 type._class = FindClass("unichar");
8105 type.isSigned = false;
8109 type.kind = charType;
8110 type.isSigned = true;
8115 char * dot = strchr(constant, '.');
8116 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8120 exponent = strchr(constant, 'p');
8121 if(!exponent) exponent = strchr(constant, 'P');
8125 exponent = strchr(constant, 'e');
8126 if(!exponent) exponent = strchr(constant, 'E');
8131 if(strchr(constant, 'f') || strchr(constant, 'F'))
8132 type.kind = floatType;
8134 type.kind = doubleType;
8135 type.isSigned = true;
8139 bool isSigned = constant[0] == '-';
8141 int64 i64 = strtoll(constant, &endP, 0);
8142 uint64 ui64 = strtoull(constant, &endP, 0);
8143 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
8156 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8160 else if(constant[0] != '0' || !constant[1])
8163 type.kind = is64Bit ? int64Type : intType;
8164 type.isSigned = isSigned;
8167 exp.isConstant = true;
8168 if(exp.destType && exp.destType.kind == doubleType)
8169 type.kind = doubleType;
8170 else if(exp.destType && exp.destType.kind == floatType)
8171 type.kind = floatType;
8172 else if(exp.destType && exp.destType.kind == int64Type)
8173 type.kind = int64Type;
8179 exp.isConstant = true; // Why wasn't this constant?
8196 ProcessExpressionType(exp._new.size);
8201 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8203 DeclareType(exp.expType.type, false, false);
8207 ProcessExpressionType(exp._renew.size);
8208 ProcessExpressionType(exp._renew.exp);
8213 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8215 DeclareType(exp.expType.type, false, false);
8219 bool assign = false, boolResult = false, boolOps = false;
8220 Type type1 = null, type2 = null;
8221 bool useDestType = false, useSideType = false;
8222 Location oldyylloc = yylloc;
8223 bool useSideUnit = false;
8224 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8226 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8235 // Assignment Operators
8249 // boolean Operators
8251 // Expect boolean operators
8253 //boolResult = true;
8257 // Expect boolean operands
8268 // Gives boolean result
8300 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8306 /*// Implement speed etc.
8312 if(exp.op.op == '&')
8314 // Added this here earlier for Iterator address as key
8315 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8317 Identifier id = exp.op.exp2.identifier;
8318 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8319 if(symbol && symbol.isIterator == 2)
8321 exp.type = memberExp;
8322 exp.member.exp = exp.op.exp2;
8323 exp.member.member = MkIdentifier("key");
8325 exp.op.exp2.expType = symbol.type;
8326 symbol.type.refCount++;
8327 ProcessExpressionType(exp);
8331 // exp.op.exp2.usage.usageRef = true;
8335 //dummy.kind = TypeDummy;
8338 // Added this check here to use the dest type only for units derived from the base unit
8339 // So that untyped units will use the side unit as opposed to the untyped destination unit
8340 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8341 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8342 useDestType = false;
8344 if(destClass && useDestType &&
8345 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8347 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8349 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8350 exp.op.exp1.destType = exp.destType;
8351 exp.op.exp1.opDestType = true;
8353 exp.destType.refCount++;
8357 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8358 exp.op.exp1.destType = dummy;
8362 // TESTING THIS HERE...
8363 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8364 ProcessExpressionType(exp.op.exp1);
8365 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8367 exp.op.exp1.opDestType = false;
8369 // Fix for unit and ++ / --
8370 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8371 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8373 exp.op.exp2 = MkExpConstant("1");
8374 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8378 if(exp.op.exp1.destType == dummy)
8381 exp.op.exp1.destType = null;
8383 type1 = exp.op.exp1.expType;
8388 char expString[10240];
8389 expString[0] = '\0';
8390 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8394 exp.op.exp2.destType = exp.op.exp1.expType;
8395 if(exp.op.exp1.expType)
8396 exp.op.exp1.expType.refCount++;
8400 exp.op.exp2.destType = exp.destType;
8401 if(!exp.op.exp1 || exp.op.op != '&')
8402 exp.op.exp2.opDestType = true;
8404 exp.destType.refCount++;
8407 if(type1) type1.refCount++;
8408 exp.expType = type1;
8413 PrintExpression(exp.op.exp2, expString);
8415 if(type1 && type1.kind == pointerType)
8417 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 ||
8418 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8419 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8420 else if(exp.op.op == '=')
8422 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8423 exp.op.exp2.destType = type1;
8430 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8431 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/* ||
8432 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8435 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8436 exp.op.exp2.destType = type1;
8441 if(type1) type1.refCount++;
8442 exp.expType = type1;
8444 else if(destClass &&
8445 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8446 (destClass.type == enumClass && useDestType)))
8448 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8449 exp.op.exp2.destType = exp.destType;
8450 if(exp.op.op != '&')
8451 exp.op.exp2.opDestType = true;
8453 exp.destType.refCount++;
8457 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8458 exp.op.exp2.destType = dummy;
8462 // TESTING THIS HERE... (DANGEROUS)
8463 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8464 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8466 FreeType(exp.op.exp2.destType);
8467 exp.op.exp2.destType = type1;
8470 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8471 // Cannot lose the cast on a sizeof
8472 if(exp.op.op == SIZEOF)
8474 Expression e = exp.op.exp2;
8475 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8477 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8479 if(e.type == extensionCompoundExp)
8480 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8485 if(e.type == castExp && e.cast.exp)
8486 e.cast.exp.needCast = true;
8488 ProcessExpressionType(exp.op.exp2);
8489 exp.op.exp2.opDestType = false;
8490 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8492 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8494 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)
8496 if(exp.op.op != '=' && type1.type.kind == voidType)
8497 Compiler_Error($"void *: unknown size\n");
8499 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||
8500 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8501 (exp.op.exp2.expType._class.registered.type == normalClass ||
8502 exp.op.exp2.expType._class.registered.type == structClass ||
8503 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8505 if(exp.op.op == ADD_ASSIGN)
8506 Compiler_Error($"cannot add two pointers\n");
8508 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8509 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8511 if(exp.op.op == ADD_ASSIGN)
8512 Compiler_Error($"cannot add two pointers\n");
8516 char type1String[1024];
8517 char type2String[1024];
8518 type1String[0] = '\0';
8519 type2String[0] = '\0';
8521 PrintType(exp.op.exp2.expType, type1String, false, true);
8522 PrintType(type1, type2String, false, true);
8523 ChangeCh(expString, '\n', ' ');
8524 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8528 if(exp.op.exp2.destType == dummy)
8531 exp.op.exp2.destType = null;
8534 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8538 CopyTypeInto(type2, exp.op.exp2.expType);
8539 type2.isSigned = true;
8541 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8543 type2 = { kind = intType };
8545 type2.isSigned = true;
8549 type2 = exp.op.exp2.expType;
8550 if(type2) type2.refCount++;
8554 dummy.kind = voidType;
8556 if(exp.op.op == SIZEOF)
8563 exp.isConstant = true;
8565 // Get type of dereferenced pointer
8566 else if(exp.op.op == '*' && !exp.op.exp1)
8568 exp.expType = Dereference(type2);
8569 if(type2 && type2.kind == classType)
8570 notByReference = true;
8572 else if(exp.op.op == '&' && !exp.op.exp1)
8573 exp.expType = Reference(type2);
8580 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8581 exp.op.exp1.destType = MkClassType("bool");
8582 exp.op.exp1.destType.truth = true;
8583 if(!exp.op.exp1.expType)
8584 ProcessExpressionType(exp.op.exp1);
8586 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8587 FreeType(exp.op.exp1.expType);
8588 exp.op.exp1.expType = MkClassType("bool");
8589 exp.op.exp1.expType.truth = true;
8593 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8594 exp.op.exp2.destType = MkClassType("bool");
8595 exp.op.exp2.destType.truth = true;
8596 if(!exp.op.exp2.expType)
8597 ProcessExpressionType(exp.op.exp2);
8599 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8600 FreeType(exp.op.exp2.expType);
8601 exp.op.exp2.expType = MkClassType("bool");
8602 exp.op.exp2.expType.truth = true;
8605 else if(exp.op.exp1 && exp.op.exp2 &&
8608 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8609 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8610 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8611 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8613 if(type1 && type2 &&
8614 // If either both are class or both are not class
8615 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8617 // Added this check for enum subtraction to result in an int type:
8618 if(exp.op.op == '-' &&
8619 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8620 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8623 if(!type1._class.registered.dataType)
8624 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8625 if(!type2._class.registered.dataType)
8626 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8628 intType = ProcessTypeString(
8629 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8631 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8632 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8633 exp.op.exp1.destType = intType;
8634 exp.op.exp2.destType = intType;
8639 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8640 exp.op.exp2.destType = type1;
8642 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8643 exp.op.exp1.destType = type2;
8647 // Warning here for adding Radians + Degrees with no destination type
8648 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8649 type1._class.registered && type1._class.registered.type == unitClass &&
8650 type2._class.registered && type2._class.registered.type == unitClass &&
8651 type1._class.registered != type2._class.registered)
8652 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8653 type1._class.string, type2._class.string, type1._class.string);
8655 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8657 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8660 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8662 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8663 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8666 ProcessExpressionType(exp.op.exp1);
8668 if(type2.kind != pointerType)
8670 ProcessExpressionType(classExp);
8672 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8674 if(!exp.op.exp2.expType)
8678 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8682 ProcessExpressionType(exp.op.exp2);
8687 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)))
8689 if(type1.kind != classType && type1.type.kind == voidType)
8690 Compiler_Error($"void *: unknown size\n");
8691 exp.expType = type1;
8692 if(type1) type1.refCount++;
8694 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)))
8696 if(type2.kind != classType && type2.type.kind == voidType)
8697 Compiler_Error($"void *: unknown size\n");
8698 exp.expType = type2;
8699 if(type2) type2.refCount++;
8701 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8702 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8704 Compiler_Warning($"different levels of indirection\n");
8708 bool success = false;
8709 if(type1.kind == pointerType && type2.kind == pointerType)
8711 if(exp.op.op == '+')
8712 Compiler_Error($"cannot add two pointers\n");
8713 else if(exp.op.op == '-')
8715 // Pointer Subtraction gives integer
8716 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8725 if(type1.type.kind == templateType)
8727 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8730 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8732 ProcessExpressionType(classExp);
8734 exp.type = bracketsExp;
8735 exp.list = MkListOne(MkExpOp(
8736 MkExpBrackets(MkListOne(MkExpOp(
8737 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8739 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8740 MkExpMember(classExp, MkIdentifier("typeSize"))));
8742 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8751 if(!success && exp.op.exp1.type == constantExp)
8753 // If first expression is constant, try to match that first
8754 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8756 if(exp.expType) FreeType(exp.expType);
8757 exp.expType = exp.op.exp1.destType;
8758 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8761 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8763 if(exp.expType) FreeType(exp.expType);
8764 exp.expType = exp.op.exp2.destType;
8765 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8771 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8773 if(exp.expType) FreeType(exp.expType);
8774 exp.expType = exp.op.exp2.destType;
8775 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8778 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8780 if(exp.expType) FreeType(exp.expType);
8781 exp.expType = exp.op.exp1.destType;
8782 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8788 char expString1[10240];
8789 char expString2[10240];
8792 expString1[0] = '\0';
8793 expString2[0] = '\0';
8798 PrintExpression(exp.op.exp1, expString1);
8799 ChangeCh(expString1, '\n', ' ');
8800 PrintExpression(exp.op.exp2, expString2);
8801 ChangeCh(expString2, '\n', ' ');
8802 PrintType(exp.op.exp1.expType, type1, false, true);
8803 PrintType(exp.op.exp2.expType, type2, false, true);
8806 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8810 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8811 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8813 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8814 // Convert e.g. / 4 into / 4.0
8815 exp.op.exp1.destType = type2._class.registered.dataType;
8816 if(type2._class.registered.dataType)
8817 type2._class.registered.dataType.refCount++;
8818 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8819 exp.expType = type2;
8820 if(type2) type2.refCount++;
8822 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8824 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8825 // Convert e.g. / 4 into / 4.0
8826 exp.op.exp2.destType = type1._class.registered.dataType;
8827 if(type1._class.registered.dataType)
8828 type1._class.registered.dataType.refCount++;
8829 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8830 exp.expType = type1;
8831 if(type1) type1.refCount++;
8837 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8839 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8841 if(!type1._class.registered.dataType)
8842 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8843 exp.op.exp2.destType = type1._class.registered.dataType;
8844 exp.op.exp2.destType.refCount++;
8846 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8849 type2 = exp.op.exp2.destType;
8850 if(type2) type2.refCount++;
8852 exp.expType = type2;
8856 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8858 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8860 if(!type2._class.registered.dataType)
8861 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8862 exp.op.exp1.destType = type2._class.registered.dataType;
8863 exp.op.exp1.destType.refCount++;
8865 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8866 type1 = exp.op.exp1.destType;
8867 exp.expType = type1;
8871 // TESTING THIS NEW CODE
8872 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8874 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8875 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8876 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8878 // Convert the enum to an int instead for these operators
8879 if(op1IsEnum && exp.op.exp2.expType)
8881 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8883 if(exp.expType) FreeType(exp.expType);
8884 exp.expType = exp.op.exp2.expType;
8885 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8889 else if(op2IsEnum && exp.op.exp1.expType)
8891 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8893 if(exp.expType) FreeType(exp.expType);
8894 exp.expType = exp.op.exp1.expType;
8895 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8902 if(op1IsEnum && exp.op.exp2.expType)
8904 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8906 if(exp.expType) FreeType(exp.expType);
8907 exp.expType = exp.op.exp1.expType;
8908 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8912 else if(op2IsEnum && exp.op.exp1.expType)
8914 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8916 if(exp.expType) FreeType(exp.expType);
8917 exp.expType = exp.op.exp2.expType;
8918 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8927 // Added this first part of the if here to handle 5 + Degrees { 5 } with either a base unit dest or not a unit dest type
8928 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8929 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8931 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8932 exp.op.exp1.destType = type2;
8935 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8937 if(exp.expType) FreeType(exp.expType);
8938 exp.expType = exp.op.exp1.destType;
8939 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8944 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8945 exp.op.exp2.destType = type1;
8949 // Maybe this was meant to be an enum...
8950 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8952 Type oldType = exp.op.exp2.expType;
8953 exp.op.exp2.expType = null;
8954 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8957 exp.op.exp2.expType = oldType;
8962 // TESTING THIS HERE... LATEST ADDITION
8963 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8965 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8966 exp.op.exp2.destType = type2._class.registered.dataType;
8967 if(type2._class.registered.dataType)
8968 type2._class.registered.dataType.refCount++;
8969 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8971 //exp.expType = type2._class.registered.dataType; //type2;
8972 //if(type2) type2.refCount++;
8975 // TESTING THIS HERE... LATEST ADDITION
8976 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8978 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8979 exp.op.exp1.destType = type1._class.registered.dataType;
8980 if(type1._class.registered.dataType)
8981 type1._class.registered.dataType.refCount++;
8982 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8983 exp.expType = type1._class.registered.dataType; //type1;
8984 if(type1) type1.refCount++;
8988 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8990 if(exp.expType) FreeType(exp.expType);
8991 exp.expType = exp.op.exp2.destType;
8992 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8994 else if(type1 && type2)
8996 char expString1[10240];
8997 char expString2[10240];
8998 char type1String[1024];
8999 char type2String[1024];
9000 expString1[0] = '\0';
9001 expString2[0] = '\0';
9002 type1String[0] = '\0';
9003 type2String[0] = '\0';
9006 PrintExpression(exp.op.exp1, expString1);
9007 ChangeCh(expString1, '\n', ' ');
9008 PrintExpression(exp.op.exp2, expString2);
9009 ChangeCh(expString2, '\n', ' ');
9010 PrintType(exp.op.exp1.expType, type1String, false, true);
9011 PrintType(exp.op.exp2.expType, type2String, false, true);
9014 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9016 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9018 exp.expType = exp.op.exp1.expType;
9019 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9021 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9023 exp.expType = exp.op.exp2.expType;
9024 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9032 // Maybe this was meant to be an enum...
9033 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9035 Type oldType = exp.op.exp1.expType;
9036 exp.op.exp1.expType = null;
9037 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9040 exp.op.exp1.expType = oldType;
9043 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9044 exp.op.exp1.destType = type2;
9047 // TESTING THIS HERE... LATEST ADDITION
9048 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9050 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9051 exp.op.exp1.destType = type1._class.registered.dataType;
9052 if(type1._class.registered.dataType)
9053 type1._class.registered.dataType.refCount++;
9056 // TESTING THIS HERE... LATEST ADDITION
9057 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9059 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9060 exp.op.exp2.destType = type2._class.registered.dataType;
9061 if(type2._class.registered.dataType)
9062 type2._class.registered.dataType.refCount++;
9066 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9068 if(exp.expType) FreeType(exp.expType);
9069 exp.expType = exp.op.exp1.destType;
9070 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9074 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9076 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9078 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9079 // Convert e.g. / 4 into / 4.0
9080 exp.op.exp1.destType = type2._class.registered.dataType;
9081 if(type2._class.registered.dataType)
9082 type2._class.registered.dataType.refCount++;
9083 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9085 if(exp.op.op == '!')
9087 exp.expType = MkClassType("bool");
9088 exp.expType.truth = true;
9092 exp.expType = type2;
9093 if(type2) type2.refCount++;
9096 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9098 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9100 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9101 // Convert e.g. / 4 into / 4.0
9102 exp.op.exp2.destType = type1._class.registered.dataType;
9103 if(type1._class.registered.dataType)
9104 type1._class.registered.dataType.refCount++;
9105 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9107 exp.expType = type1;
9108 if(type1) type1.refCount++;
9113 if(exp.op.exp1 && !exp.op.exp1.expType)
9115 char expString[10000];
9116 expString[0] = '\0';
9119 PrintExpression(exp.op.exp1, expString);
9120 ChangeCh(expString, '\n', ' ');
9123 Compiler_Error($"couldn't determine type of %s\n", expString);
9125 if(exp.op.exp2 && !exp.op.exp2.expType)
9127 char expString[10240];
9128 expString[0] = '\0';
9131 PrintExpression(exp.op.exp2, expString);
9132 ChangeCh(expString, '\n', ' ');
9135 Compiler_Error($"couldn't determine type of %s\n", expString);
9140 FreeType(exp.expType);
9141 exp.expType = MkClassType("bool");
9142 exp.expType.truth = true;
9145 if(exp.op.op != SIZEOF)
9146 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9147 (!exp.op.exp2 || exp.op.exp2.isConstant);
9149 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9151 DeclareType(exp.op.exp2.expType, false, false);
9154 if(exp.op.op == DELETE && exp.op.exp2 && exp.op.exp2.expType && exp.op.exp2.expType.specConst)
9155 Compiler_Warning($"deleting const qualified object\n");
9165 case extensionExpressionExp:
9168 exp.isConstant = true;
9169 for(e = exp.list->first; e; e = e.next)
9174 FreeType(e.destType);
9175 e.opDestType = exp.opDestType;
9176 e.destType = exp.destType;
9177 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
9179 ProcessExpressionType(e);
9181 exp.destType.count--;
9182 if(!exp.expType && !e.next)
9184 exp.expType = e.expType;
9185 if(e.expType) e.expType.refCount++;
9188 exp.isConstant = false;
9191 // In case a cast became a member...
9192 e = exp.list->first;
9193 if(!e.next && e.type == memberExp)
9195 // Preserve prev, next
9196 Expression next = exp.next, prev = exp.prev;
9199 FreeType(exp.expType);
9200 FreeType(exp.destType);
9210 ProcessExpressionType(exp);
9217 exp.isConstant = true;
9219 ProcessExpressionType(exp.index.exp);
9220 if(!exp.index.exp.isConstant)
9221 exp.isConstant = false;
9223 if(exp.index.exp.expType)
9225 Type source = exp.index.exp.expType;
9226 if(source.kind == classType && source._class && source._class.registered)
9228 Class _class = source._class.registered;
9229 Class c = _class.templateClass ? _class.templateClass : _class;
9230 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9232 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9234 if(exp.index.index && exp.index.index->last)
9236 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9238 if(type.kind == classType) type.constant = true;
9239 else if(type.kind == pointerType)
9242 while(t.kind == pointerType) t = t.type;
9246 ((Expression)exp.index.index->last).destType = type;
9252 for(e = exp.index.index->first; e; e = e.next)
9254 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9256 if(e.destType) FreeType(e.destType);
9257 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9259 ProcessExpressionType(e);
9262 // Check if this type is int
9265 exp.isConstant = false;
9269 exp.expType = Dereference(exp.index.exp.expType);
9271 DeclareType(exp.expType, false, false);
9278 Type methodType = null;
9284 PrintExpression(exp.call.exp, name);
9285 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9287 //exp.call.exp.expType = null;
9288 PrintExpression(exp.call.exp, name);
9291 if(exp.call.exp.type == identifierExp)
9293 Expression idExp = exp.call.exp;
9294 Identifier id = idExp.identifier;
9295 if(!strcmp(id.string, "__builtin_frame_address"))
9297 exp.expType = ProcessTypeString("void *", true);
9298 if(exp.call.arguments && exp.call.arguments->first)
9299 ProcessExpressionType(exp.call.arguments->first);
9302 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9304 exp.expType = ProcessTypeString("int", true);
9305 if(exp.call.arguments && exp.call.arguments->first)
9306 ProcessExpressionType(exp.call.arguments->first);
9309 else if(!strcmp(id.string, "Max") ||
9310 !strcmp(id.string, "Min") ||
9311 !strcmp(id.string, "Sgn") ||
9312 !strcmp(id.string, "Abs"))
9314 Expression a = null;
9315 Expression b = null;
9316 Expression tempExp1 = null, tempExp2 = null;
9317 if((!strcmp(id.string, "Max") ||
9318 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9320 a = exp.call.arguments->first;
9321 b = exp.call.arguments->last;
9325 else if(exp.call.arguments->count == 1)
9327 a = exp.call.arguments->first;
9333 exp.call.arguments->Clear();
9334 idExp.identifier = null;
9336 FreeExpContents(exp);
9338 ProcessExpressionType(a);
9340 ProcessExpressionType(b);
9342 exp.type = bracketsExp;
9343 exp.list = MkList();
9345 if(a.expType && (!b || b.expType))
9347 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9349 // Use the simpleStruct name/ids for now...
9352 OldList * specs = MkList();
9353 OldList * decls = MkList();
9355 char temp1[1024], temp2[1024];
9357 GetTypeSpecs(a.expType, specs);
9359 if(a && !a.isConstant && a.type != identifierExp)
9361 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9362 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9363 tempExp1 = QMkExpId(temp1);
9364 tempExp1.expType = a.expType;
9366 a.expType.refCount++;
9367 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9369 if(b && !b.isConstant && b.type != identifierExp)
9371 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9372 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9373 tempExp2 = QMkExpId(temp2);
9374 tempExp2.expType = b.expType;
9376 b.expType.refCount++;
9377 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9380 decl = MkDeclaration(specs, decls);
9381 if(!curCompound.compound.declarations)
9382 curCompound.compound.declarations = MkList();
9383 curCompound.compound.declarations->Insert(null, decl);
9388 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9390 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9392 MkExpCondition(MkExpBrackets(MkListOne(
9393 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9394 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9395 exp.expType = a.expType;
9397 a.expType.refCount++;
9399 else if(!strcmp(id.string, "Abs"))
9402 MkExpCondition(MkExpBrackets(MkListOne(
9403 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9404 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9405 exp.expType = a.expType;
9407 a.expType.refCount++;
9409 else if(!strcmp(id.string, "Sgn"))
9411 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9413 MkExpCondition(MkExpBrackets(MkListOne(
9414 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9415 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9416 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9417 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9418 exp.expType = ProcessTypeString("int", false);
9421 FreeExpression(tempExp1);
9422 if(tempExp2) FreeExpression(tempExp2);
9436 if(!exp.call.exp.destType)
9438 exp.call.exp.destType = dummy;
9441 ProcessExpressionType(exp.call.exp);
9442 if(exp.call.exp.destType == dummy)
9445 exp.call.exp.destType = null;
9450 // Check argument types against parameter types
9451 functionType = exp.call.exp.expType;
9453 if(functionType && functionType.kind == TypeKind::methodType)
9455 methodType = functionType;
9456 functionType = methodType.method.dataType;
9458 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9459 // TOCHECK: Instead of doing this here could this be done per param?
9460 if(exp.call.exp.expType.usedClass)
9462 char typeString[1024];
9463 typeString[0] = '\0';
9465 Symbol back = functionType.thisClass;
9466 // Do not output class specifier here (thisclass was added to this)
9467 functionType.thisClass = null;
9468 PrintType(functionType, typeString, true, true);
9469 functionType.thisClass = back;
9471 if(strstr(typeString, "thisclass"))
9473 OldList * specs = MkList();
9476 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9478 decl = SpecDeclFromString(typeString, specs, null);
9480 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9481 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9482 exp.call.exp.expType.usedClass))
9483 thisClassParams = false;
9485 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9487 Class backupThisClass = thisClass;
9488 thisClass = exp.call.exp.expType.usedClass;
9489 ProcessDeclarator(decl);
9490 thisClass = backupThisClass;
9493 thisClassParams = true;
9495 functionType = ProcessType(specs, decl);
9496 functionType.refCount = 0;
9497 FinishTemplatesContext(context);
9499 // Mark parameters that were 'thisclass'
9502 for(p = functionType.params.first, op = methodType.method.dataType.params.first; p && op; p = p.next, op = op.next)
9503 p.wasThisClass = op.kind == thisClassType;
9507 FreeList(specs, FreeSpecifier);
9508 FreeDeclarator(decl);
9512 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9514 Type type = functionType.type;
9515 if(!functionType.refCount)
9517 functionType.type = null;
9518 FreeType(functionType);
9520 //methodType = functionType;
9521 functionType = type;
9523 if(functionType && functionType.kind != TypeKind::functionType)
9525 Compiler_Error($"called object %s is not a function\n", name);
9527 else if(functionType)
9529 bool emptyParams = false, noParams = false;
9530 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9531 Type type = functionType.params.first;
9532 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9534 Location oldyylloc = yylloc;
9536 if(!type) emptyParams = true;
9539 if(functionType.extraParam && e && functionType.thisClass)
9541 e.destType = MkClassType(functionType.thisClass.string);
9545 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9546 // Fixed #141 by adding '&& !functionType.extraParam'
9547 if(!functionType.staticMethod && !functionType.extraParam)
9549 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9550 memberExp.member.exp.expType._class)
9552 type = MkClassType(memberExp.member.exp.expType._class.string);
9557 type = functionType.params.first;
9562 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9564 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9565 type.byReference = functionType.byReference;
9566 type.typedByReference = functionType.typedByReference;
9569 // Allow manually passing a class for typed object
9570 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9574 type = functionType.params.first;
9582 if(type && type.kind == voidType)
9585 if(!type.refCount) FreeType(type);
9589 for( ; e; e = e.next)
9591 if(!type && !emptyParams)
9594 if(methodType && methodType.methodClass)
9595 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9596 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9597 noParams ? 0 : functionType.params.count);
9599 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9600 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9601 noParams ? 0 : functionType.params.count);
9605 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9607 Type templatedType = null;
9608 Class _class = methodType.usedClass;
9609 ClassTemplateParameter curParam = null;
9611 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9614 for(sClass = _class; sClass; sClass = sClass.base)
9616 if(sClass.templateClass) sClass = sClass.templateClass;
9618 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9620 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9623 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9625 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9626 id += nextClass.templateParams.count;
9635 if(curParam && _class.templateArgs[id].dataTypeString)
9637 bool constant = type.constant;
9638 ClassTemplateArgument arg = _class.templateArgs[id];
9640 Context context = SetupTemplatesContext(_class);
9643 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9644 templatedType = ProcessTypeString(arg.dataTypeString, false);
9645 FinishTemplatesContext(context);
9648 if(templatedType.kind == classType && constant) templatedType.constant = true;
9649 else if(templatedType.kind == pointerType)
9651 Type t = templatedType.type;
9652 while(t.kind == pointerType) t = t.type;
9653 if(constant) t.constant = constant;
9656 e.destType = templatedType;
9659 templatedType.passAsTemplate = true;
9660 // templatedType.refCount++;
9666 if(type) type.refCount++;
9671 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9673 e.destType = type.prev;
9674 e.destType.refCount++;
9679 if(type) type.refCount++;
9682 // Don't reach the end for the ellipsis
9683 if(type && type.kind != ellipsisType)
9685 Type next = type.next;
9686 if(!type.refCount) FreeType(type);
9691 if(type && type.kind != ellipsisType)
9693 if(methodType && methodType.methodClass)
9694 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9695 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9696 functionType.params.count + extra);
9698 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9699 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9700 functionType.params.count + extra);
9703 if(type && !type.refCount) FreeType(type);
9710 kind = TypeKind::functionType;
9713 if(exp.call.exp.type == identifierExp)
9715 char * string = exp.call.exp.identifier.string;
9719 Location oldyylloc = yylloc;
9721 yylloc = exp.call.exp.identifier.loc;
9722 if(strstr(string, "__builtin_") == string)
9726 functionType.returnType = exp.destType;
9727 exp.destType.refCount++;
9731 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9732 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9733 globalContext.symbols.Add((BTNode)symbol);
9734 if(strstr(symbol.string, "::"))
9735 globalContext.hasNameSpace = true;
9740 else if(exp.call.exp.type == memberExp)
9742 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9743 exp.call.exp.member.member.string);*/
9746 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9748 if(!functionType.returnType)
9750 functionType.returnType = Type
9757 if(functionType && functionType.kind == TypeKind::functionType)
9759 exp.expType = functionType.returnType;
9761 if(functionType.returnType)
9762 functionType.returnType.refCount++;
9764 if(!functionType.refCount)
9765 FreeType(functionType);
9768 if(exp.call.arguments)
9770 for(e = exp.call.arguments->first; e; e = e.next)
9771 ProcessExpressionType(e);
9778 Location oldyylloc = yylloc;
9780 Expression checkExp = exp.member.exp;
9783 if(checkExp.type == castExp)
9784 checkExp = checkExp.cast.exp;
9785 else if(checkExp.type == bracketsExp)
9786 checkExp = checkExp.list ? checkExp.list->first : null;
9791 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9792 exp.thisPtr = thisPtr;
9794 // DOING THIS LATER NOW...
9795 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9797 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9798 /* TODO: Name Space Fix ups
9799 if(!exp.member.member.classSym)
9800 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9804 ProcessExpressionType(exp.member.exp);
9805 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9806 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9808 exp.isConstant = false;
9811 exp.isConstant = exp.member.exp.isConstant;
9812 type = exp.member.exp.expType;
9816 if(type && (type.kind == templateType))
9818 Class _class = thisClass ? thisClass : currentClass;
9819 ClassTemplateParameter param = null;
9822 for(param = _class.templateParams.first; param; param = param.next)
9824 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9828 if(param && param.defaultArg.member)
9830 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9833 Expression expMember = exp.member.exp;
9835 OldList * specs = MkList();
9836 char thisClassTypeString[1024];
9838 FreeIdentifier(exp.member.member);
9840 ProcessExpressionType(argExp);
9843 char * colon = strstr(param.defaultArg.memberString, "::");
9846 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9847 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9850 strcpy(thisClassTypeString, _class.fullName);
9853 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9855 exp.expType = ProcessType(specs, decl);
9856 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9858 Class expClass = exp.expType._class.registered;
9859 Class cClass = null;
9863 char templateString[1024];
9864 ClassTemplateParameter param;
9865 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9866 for(cClass = expClass; cClass; cClass = cClass.base)
9869 for(param = cClass.templateParams.first; param; param = param.next)
9873 ClassTemplateArgument arg;
9874 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9875 arg = expClass.templateArgs[id];
9877 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9879 ClassTemplateParameter cParam;
9880 //int p = numParams - sClass.templateParams.count;
9883 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9885 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9887 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9889 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9891 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9892 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9904 strcat(argument, arg.name.string);
9905 strcat(argument, " = ");
9911 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9912 char expString[1024];
9913 OldList * specs = MkList();
9914 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9916 char * string = PrintHexUInt64(arg.expression.ui64);
9917 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9920 ProcessExpressionType(exp);
9921 ComputeExpression(exp);
9922 expString[0] = '\0';
9923 PrintExpression(exp, expString);
9924 strcat(argument, expString);
9926 FreeExpression(exp);
9931 strcat(argument, arg.member.name);
9934 case TemplateParameterType::type:
9936 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9938 if(!strcmp(arg.dataTypeString, "thisclass"))
9939 strcat(argument, thisClassTypeString);
9941 strcat(argument, arg.dataTypeString);
9948 if(paramCount) strcat(templateString, ", ");
9949 if(lastParam != p - 1)
9951 strcat(templateString, param.name);
9952 strcat(templateString, " = ");
9954 strcat(templateString, argument);
9963 int len = strlen(templateString);
9964 if(templateString[len-1] == '>') templateString[len++] = ' ';
9965 templateString[len++] = '>';
9966 templateString[len++] = '\0';
9969 Context context = SetupTemplatesContext(_class);
9970 FreeType(exp.expType);
9971 exp.expType = ProcessTypeString(templateString, false);
9972 FinishTemplatesContext(context);
9976 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9977 exp.type = bracketsExp;
9978 exp.list = MkListOne(MkExpOp(null, '*',
9983 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9984 MkExpBrackets(MkListOne(
9985 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9987 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9989 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9994 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9995 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9997 type = ProcessTemplateParameterType(type.templateParameter);
10000 // TODO: *** This seems to be where we should add method support for all basic types ***
10001 if(type && (type.kind == templateType));
10002 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
10003 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
10004 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
10005 (type.kind == pointerType && type.type.kind == charType)))
10007 Identifier id = exp.member.member;
10008 TypeKind typeKind = type.kind;
10009 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10010 if(typeKind == subClassType && exp.member.exp.type == classExp)
10012 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10013 typeKind = classType;
10018 if(typeKind == intType || typeKind == enumType)
10019 _class = eSystem_FindClass(privateModule, "int");
10022 if(type.kind == classType && type._class && type._class.registered)
10024 _class = type._class.registered;
10026 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10028 _class = FindClass("char *").registered;
10030 else if(type.kind == pointerType)
10032 _class = eSystem_FindClass(privateModule, "uintptr");
10033 FreeType(exp.expType);
10034 exp.expType = ProcessTypeString("uintptr", false);
10035 exp.byReference = true;
10039 char string[1024] = "";
10041 PrintTypeNoConst(type, string, false, true);
10042 classSym = FindClass(string);
10043 if(classSym) _class = classSym.registered;
10051 (exp.member.exp.type == identifierExp &&
10052 !strcmp(exp.member.exp.identifier.string, "this"));*/
10053 Property prop = null;
10054 Method method = null;
10055 DataMember member = null;
10056 Property revConvert = null;
10057 ClassProperty classProp = null;
10059 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10060 exp.member.memberType = propertyMember;
10062 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10063 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10065 if(typeKind != subClassType)
10067 // Prioritize data members over properties for "this"
10068 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10070 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10071 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10073 prop = eClass_FindProperty(_class, id.string, privateModule);
10077 if(!member && !prop)
10078 prop = eClass_FindProperty(_class, id.string, privateModule);
10079 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10080 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10081 exp.member.thisPtr = true;
10083 // Prioritize properties over data members otherwise
10086 bool useMemberForNonConst = false;
10087 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10090 prop = eClass_FindProperty(_class, id.string, null);
10092 useMemberForNonConst = prop && exp.destType &&
10093 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10094 !strncmp(prop.dataTypeString, "const ", 6);
10096 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10097 member = eClass_FindDataMember(_class, id.string, null, null, null);
10100 if((!prop || useMemberForNonConst) && !member)
10102 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10105 prop = eClass_FindProperty(_class, id.string, privateModule);
10107 useMemberForNonConst |= prop && exp.destType &&
10108 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10109 !strncmp(prop.dataTypeString, "const ", 6);
10111 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10112 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10118 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10125 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10126 method = eClass_FindMethod(_class, id.string, privateModule);
10127 if(!prop && !member && !method)
10129 if(typeKind == subClassType)
10131 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10134 exp.member.memberType = classPropertyMember;
10135 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10139 // Assume this is a class_data member
10140 char structName[1024];
10141 Identifier id = exp.member.member;
10142 Expression classExp = exp.member.exp;
10145 FreeType(classExp.expType);
10146 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10148 strcpy(structName, "__ecereClassData_");
10149 FullClassNameCat(structName, type._class.string, false);
10150 exp.type = pointerExp;
10151 exp.member.member = id;
10153 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10154 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10155 MkExpBrackets(MkListOne(MkExpOp(
10156 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10157 MkExpMember(classExp, MkIdentifier("data"))), '+',
10158 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10163 ProcessExpressionType(exp);
10169 // Check for reverse conversion
10170 // (Convert in an instantiation later, so that we can use
10171 // deep properties system)
10172 Symbol classSym = FindClass(id.string);
10175 Class convertClass = classSym.registered;
10177 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10182 if(!exp.member.exp.destType)
10184 if(method && !method._class.symbol)
10185 method._class.symbol = FindClass(method._class.fullName);
10187 exp.member.exp.destType = Type
10191 _class = prop ? prop._class.symbol : method ? method._class.symbol : _class.symbol;
10192 // wasThisClass = type ? type.wasThisClass : false;
10198 exp.member.memberType = propertyMember;
10200 ProcessPropertyType(prop);
10201 exp.expType = prop.dataType;
10202 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10205 CopyTypeInto(type, exp.expType);
10207 type.constant = true;
10208 exp.expType = type;
10210 else if(prop.dataType)
10211 prop.dataType.refCount++;
10215 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10217 FreeExpContents(exp);
10218 exp.type = identifierExp;
10219 exp.identifier = MkIdentifier("class");
10220 ProcessExpressionType(exp);
10224 exp.member.memberType = dataMember;
10225 DeclareStruct(_class.fullName, false);
10226 if(!member.dataType)
10228 Context context = SetupTemplatesContext(_class);
10229 member.dataType = ProcessTypeString(member.dataTypeString, false);
10230 FinishTemplatesContext(context);
10232 exp.expType = member.dataType;
10233 if(member.dataType) member.dataType.refCount++;
10235 else if(revConvert)
10237 exp.member.memberType = reverseConversionMember;
10238 exp.expType = MkClassType(revConvert._class.fullName);
10246 exp.type = identifierExp;
10247 exp.identifier = exp.member.member;
10250 exp.member.memberType = methodMember;
10252 if(!method.dataType)
10253 ProcessMethodType(method);
10261 // Tricky spot here... To use instance versus class virtual table
10262 // Put it back to what it was... What did we break?
10264 // Had to put it back for overriding Main of Thread global instance
10266 //exp.expType.methodClass = _class;
10267 exp.expType.methodClass = (id && id._class) ? _class : null;
10269 // Need the actual class used for templated classes
10270 exp.expType.usedClass = _class;
10272 else if(!classProp)
10274 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10276 FreeExpContents(exp);
10277 exp.type = identifierExp;
10278 exp.identifier = MkIdentifier("class");
10279 FreeType(exp.expType);
10280 exp.expType = MkClassType("ecere::com::Class");
10283 yylloc = exp.member.member.loc;
10284 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10286 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10289 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10293 tClass = type._class && type._class.registered ? type._class.registered : _class;
10294 while(tClass && !tClass.templateClass) tClass = tClass.base;
10296 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10299 ClassTemplateParameter curParam = null;
10302 for(sClass = tClass; sClass; sClass = sClass.base)
10305 if(sClass.templateClass) sClass = sClass.templateClass;
10306 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10308 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10310 for(sClass = sClass.base; sClass; sClass = sClass.base)
10311 id += sClass.templateParams.count;
10316 if(curParam) break;
10319 if(curParam && tClass.templateArgs[id].dataTypeString)
10321 ClassTemplateArgument arg = tClass.templateArgs[id];
10322 Context context = SetupTemplatesContext(tClass);
10323 bool constant = exp.expType.constant;
10324 /*if(!arg.dataType)
10325 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10326 FreeType(exp.expType);
10328 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10329 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10330 else if(exp.expType.kind == pointerType)
10332 Type t = exp.expType.type;
10333 while(t.kind == pointerType) t = t.type;
10334 if(constant) t.constant = constant;
10338 if(exp.expType.kind == thisClassType)
10340 FreeType(exp.expType);
10341 exp.expType = ReplaceThisClassType(_class);
10344 if(tClass.templateClass && (exp.expType.kind != templateType || (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType))))
10345 exp.expType.passAsTemplate = true;
10346 //exp.expType.refCount++;
10349 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10350 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10351 else if(exp.destType.kind == pointerType)
10353 Type t = exp.destType.type;
10354 while(t.kind == pointerType) t = t.type;
10355 if(constant) t.constant = constant;
10358 //exp.destType.refCount++;
10360 if(exp.destType.kind == thisClassType)
10362 FreeType(exp.destType);
10363 exp.destType = ReplaceThisClassType(_class);
10367 FinishTemplatesContext(context);
10370 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10371 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10374 ClassTemplateParameter curParam = null;
10377 for(sClass = tClass; sClass; sClass = sClass.base)
10380 if(sClass.templateClass) sClass = sClass.templateClass;
10381 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10383 if(curParam.type == TemplateParameterType::type &&
10384 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10386 for(sClass = sClass.base; sClass; sClass = sClass.base)
10387 id += sClass.templateParams.count;
10392 if(curParam) break;
10397 ClassTemplateArgument arg = tClass.templateArgs[id];
10398 Context context = SetupTemplatesContext(tClass);
10400 /*if(!arg.dataType)
10401 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10403 basicType = ProcessTypeString(arg.dataTypeString, false);
10406 if(basicType.kind == thisClassType)
10408 FreeType(basicType);
10409 basicType = ReplaceThisClassType(_class);
10412 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10413 if(tClass.templateClass)
10414 basicType.passAsTemplate = true;
10417 FreeType(exp.expType);
10419 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10420 //exp.expType.refCount++;
10423 exp.destType = exp.expType;
10424 exp.destType.refCount++;
10428 Expression newExp { };
10429 OldList * specs = MkList();
10431 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10433 if(exp.destType) exp.destType.refCount++;
10434 if(exp.expType) exp.expType.refCount++;
10435 exp.type = castExp;
10436 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10437 exp.cast.exp = newExp;
10438 //FreeType(exp.expType);
10439 //exp.expType = null;
10440 //ProcessExpressionType(sourceExp);
10443 FinishTemplatesContext(context);
10446 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10448 Class expClass = exp.expType._class.registered;
10451 Class cClass = null;
10453 int paramCount = 0;
10454 int lastParam = -1;
10455 char templateString[1024];
10456 ClassTemplateParameter param;
10457 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10458 while(cClass != expClass)
10461 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10464 for(param = cClass.templateParams.first; param; param = param.next)
10466 Class cClassCur = null;
10468 ClassTemplateParameter paramCur = null;
10469 ClassTemplateArgument arg;
10470 while(cClassCur != tClass && !paramCur)
10473 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10474 cClassCur = sClassCur;
10476 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10478 if(!strcmp(paramCur.name, param.name))
10486 if(paramCur && paramCur.type == TemplateParameterType::type)
10487 arg = tClass.templateArgs[cp];
10489 arg = expClass.templateArgs[p];
10492 char argument[256];
10493 argument[0] = '\0';
10496 strcat(argument, arg.name.string);
10497 strcat(argument, " = ");
10503 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10504 char expString[1024];
10505 OldList * specs = MkList();
10506 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10508 char * string = PrintHexUInt64(arg.expression.ui64);
10509 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10512 ProcessExpressionType(exp);
10513 ComputeExpression(exp);
10514 expString[0] = '\0';
10515 PrintExpression(exp, expString);
10516 strcat(argument, expString);
10518 FreeExpression(exp);
10523 strcat(argument, arg.member.name);
10526 case TemplateParameterType::type:
10528 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10529 strcat(argument, arg.dataTypeString);
10535 if(paramCount) strcat(templateString, ", ");
10536 if(lastParam != p - 1)
10538 strcat(templateString, param.name);
10539 strcat(templateString, " = ");
10541 strcat(templateString, argument);
10550 int len = strlen(templateString);
10551 if(templateString[len-1] == '>') templateString[len++] = ' ';
10552 templateString[len++] = '>';
10553 templateString[len++] = '\0';
10556 FreeType(exp.expType);
10558 Context context = SetupTemplatesContext(tClass);
10559 exp.expType = ProcessTypeString(templateString, false);
10560 FinishTemplatesContext(context);
10567 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10569 else if(type && (type.kind == structType || type.kind == unionType))
10571 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10574 exp.expType = memberType;
10576 memberType.refCount++;
10581 char expString[10240];
10582 expString[0] = '\0';
10583 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10584 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10587 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10589 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10591 Identifier id = exp.member.member;
10592 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10595 FreeType(exp.expType);
10596 exp.expType = ReplaceThisClassType(_class);
10600 yylloc = oldyylloc;
10603 // Convert x->y into (*x).y
10606 Type destType = exp.destType;
10608 // DOING THIS LATER NOW...
10609 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10611 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10612 /* TODO: Name Space Fix ups
10613 if(!exp.member.member.classSym)
10614 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10618 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10619 exp.type = memberExp;
10622 ProcessExpressionType(exp);
10629 //ComputeExpression(exp);
10631 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10632 if(classSym && classSym.registered)
10634 if(classSym.registered.type == noHeadClass)
10638 DeclareStruct(classSym.string, false);
10639 FreeSpecifier(exp._class);
10640 exp.type = typeSizeExp;
10641 FullClassNameCat(name, classSym.string, false);
10642 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10646 if(classSym.registered.fixed)
10648 FreeSpecifier(exp._class);
10649 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10650 exp.type = constantExp;
10654 char className[1024];
10655 strcpy(className, "__ecereClass_");
10656 FullClassNameCat(className, classSym.string, true);
10657 //MangleClassName(className);
10659 DeclareClass(classSym, className);
10661 FreeExpContents(exp);
10662 exp.type = pointerExp;
10663 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10664 exp.member.member = MkIdentifier("structSize");
10672 kind = intSizeType;
10674 // exp.isConstant = true;
10679 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10684 kind = intSizeType;
10686 exp.isConstant = true;
10688 DeclareType(type, false, false);
10694 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10696 FreeType(exp.cast.exp.destType);
10697 exp.cast.exp.destType = type;
10699 type.casted = true;
10700 ProcessExpressionType(exp.cast.exp);
10701 type.casted = false;
10703 exp.expType = type;
10706 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10707 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10709 void * prev = exp.prev, * next = exp.next;
10710 Type expType = exp.cast.exp.destType;
10711 Expression castExp = exp.cast.exp;
10712 Type destType = exp.destType;
10714 if(expType) expType.refCount++;
10716 //FreeType(exp.destType);
10717 FreeType(exp.expType);
10718 FreeTypeName(exp.cast.typeName);
10721 FreeType(exp.expType);
10722 FreeType(exp.destType);
10724 exp.expType = expType;
10725 exp.destType = destType;
10735 exp.isConstant = exp.cast.exp.isConstant;
10740 case extensionInitializerExp:
10742 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10743 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10744 // ProcessInitializer(exp.initializer.initializer, type);
10745 exp.expType = type;
10750 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10751 ProcessExpressionType(exp.vaArg.exp);
10752 exp.expType = type;
10758 exp.isConstant = true;
10760 FreeType(exp.cond.cond.destType);
10761 exp.cond.cond.destType = MkClassType("bool");
10762 exp.cond.cond.destType.truth = true;
10763 ProcessExpressionType(exp.cond.cond);
10764 if(!exp.cond.cond.isConstant)
10765 exp.isConstant = false;
10766 for(e = exp.cond.exp->first; e; e = e.next)
10770 FreeType(e.destType);
10771 e.destType = exp.destType;
10772 if(e.destType) e.destType.refCount++;
10774 ProcessExpressionType(e);
10777 exp.expType = e.expType;
10778 if(e.expType) e.expType.refCount++;
10781 exp.isConstant = false;
10784 FreeType(exp.cond.elseExp.destType);
10785 // Added this check if we failed to find an expType
10786 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10789 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10791 if(exp.cond.elseExp.destType)
10792 exp.cond.elseExp.destType.refCount++;
10793 ProcessExpressionType(exp.cond.elseExp);
10795 // FIXED THIS: Was done before calling process on elseExp
10796 if(!exp.cond.elseExp.isConstant)
10797 exp.isConstant = false;
10800 case extensionCompoundExp:
10802 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10804 Statement last = exp.compound.compound.statements->last;
10805 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10807 ((Expression)last.expressions->last).destType = exp.destType;
10809 exp.destType.refCount++;
10811 ProcessStatement(exp.compound);
10812 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10814 exp.expType.refCount++;
10820 Specifier spec = exp._classExp.specifiers->first;
10821 if(spec && spec.type == nameSpecifier)
10823 exp.expType = MkClassType(spec.name);
10824 exp.expType.kind = subClassType;
10825 exp.byReference = true;
10829 exp.expType = MkClassType("ecere::com::Class");
10830 exp.byReference = true;
10836 Class _class = thisClass ? thisClass : currentClass;
10839 Identifier id = exp.classData.id;
10840 char structName[1024];
10841 Expression classExp;
10842 strcpy(structName, "__ecereClassData_");
10843 FullClassNameCat(structName, _class.fullName, false);
10844 exp.type = pointerExp;
10845 exp.member.member = id;
10846 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10847 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10849 classExp = MkExpIdentifier(MkIdentifier("class"));
10851 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10852 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10853 MkExpBrackets(MkListOne(MkExpOp(
10854 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10855 MkExpMember(classExp, MkIdentifier("data"))), '+',
10856 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10859 ProcessExpressionType(exp);
10867 const char * typeString = null;
10868 char typeStringBuf[1024];
10869 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10870 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10872 Class templateClass = exp.destType._class.registered;
10873 typeString = templateClass.templateArgs[2].dataTypeString;
10877 // Guess type from expressions in the array
10879 for(e = exp.list->first; e; e = e.next)
10881 ProcessExpressionType(e);
10884 if(!type) { type = e.expType; type.refCount++; }
10887 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10888 if(!MatchTypeExpression(e, type, null, false, true))
10894 e = exp.list->first;
10895 ProcessExpressionType(e);
10898 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10899 if(!MatchTypeExpression(e, type, null, false, true))
10901 FreeType(e.expType);
10912 FreeType(e.expType);
10919 typeStringBuf[0] = '\0';
10920 PrintTypeNoConst(type, typeStringBuf, false, true);
10921 typeString = typeStringBuf;
10929 (Container)& (struct BuiltInContainer)
10931 ._vTbl = class(BuiltInContainer)._vTbl,
10932 ._class = class(BuiltInContainer),
10934 .data = (int[]){ 1, 7, 3, 4, 5 },
10936 .type = class(int),
10939 char templateString[1024];
10940 OldList * initializers = MkList();
10941 OldList * structInitializers = MkList();
10942 OldList * specs = MkList();
10944 Declarator decl = SpecDeclFromString(typeString, specs, null);
10945 sprintf(templateString, "Container<%s>", typeString);
10950 type = ProcessTypeString(typeString, false);
10951 while((e = exp.list->first))
10953 exp.list->Remove(e);
10956 ProcessExpressionType(e);
10957 ListAdd(initializers, MkInitializerAssignment(e));
10963 DeclareStruct("ecere::com::BuiltInContainer", false);
10965 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10966 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10967 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10968 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10969 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10970 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10971 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10972 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10973 MkInitializerList(initializers))));
10974 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10975 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10976 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10977 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10978 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10979 exp.expType = ProcessTypeString(templateString, false);
10980 exp.type = bracketsExp;
10981 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10983 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10984 MkInitializerList(structInitializers)))));
10985 ProcessExpressionType(expExt);
10989 exp.expType = ProcessTypeString("Container", false);
10990 Compiler_Error($"Couldn't determine type of array elements\n");
10996 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10998 FreeType(exp.expType);
10999 exp.expType = ReplaceThisClassType(thisClass);
11002 // Resolve structures here
11003 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
11005 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
11006 // TODO: Fix members reference...
11009 if(exp.expType.kind != enumType)
11012 String enumName = CopyString(exp.expType.enumName);
11014 // Fixed a memory leak on self-referencing C structs typedefs
11015 // by instantiating a new type rather than simply copying members
11016 // into exp.expType
11017 FreeType(exp.expType);
11018 exp.expType = Type { };
11019 exp.expType.kind = symbol.type.kind;
11020 exp.expType.refCount++;
11021 exp.expType.enumName = enumName;
11023 exp.expType.members = symbol.type.members;
11024 for(member = symbol.type.members.first; member; member = member.next)
11030 for(member = symbol.type.members.first; member; member = member.next)
11032 NamedLink value { name = CopyString(member.name) };
11033 exp.expType.members.Add(value);
11040 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11041 else if(exp.destType && !exp.destType.keepCast)
11043 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11044 exp.needTemplateCast = 1;
11046 if(exp.destType.kind == voidType);
11047 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11049 if(!exp.destType.count || unresolved)
11054 if(exp.destType.kind != ellipsisType)
11060 char expString[10240];
11061 expString[0] = '\0';
11063 PrintType(exp.destType, type2, false, true);
11065 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11067 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11068 else if(exp.type != dummyExp)
11069 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11074 char expString[10240] ;
11075 expString[0] = '\0';
11076 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11079 Compiler_Error($"unresolved identifier %s\n", expString);
11080 else if(exp.type != dummyExp)
11081 Compiler_Error($"couldn't determine type of %s\n", expString);
11092 PrintType(exp.expType, type1, false, true);
11093 PrintType(exp.destType, type2, false, true);
11096 //CheckExpressionType(exp, exp.destType, false);
11098 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11099 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11100 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11103 char expString[10240];
11104 expString[0] = '\0';
11105 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11108 CheckExpressionType(exp, exp.destType, false, true);
11110 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11111 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
11112 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11114 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11115 FreeType(exp.expType);
11116 exp.destType.refCount++;
11117 exp.expType = exp.destType;
11122 /*else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
11124 Expression newExp { };
11125 char typeString[1024];
11126 OldList * specs = MkList();
11129 typeString[0] = '\0';
11133 if(exp.expType) exp.expType.refCount++;
11134 if(exp.expType) exp.expType.refCount++;
11135 exp.type = castExp;
11136 newExp.destType = exp.expType;
11138 PrintType(exp.expType, typeString, false, false);
11139 decl = SpecDeclFromString(typeString, specs, null);
11141 exp.cast.typeName = MkTypeName(specs, decl);
11142 exp.cast.exp = newExp;
11145 else if(unresolved)
11147 if(exp.identifier._class && exp.identifier._class.name)
11148 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11149 else if(exp.identifier.string && exp.identifier.string[0])
11150 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11152 else if(!exp.expType && exp.type != dummyExp)
11154 char expString[10240];
11155 expString[0] = '\0';
11156 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11157 Compiler_Error($"couldn't determine type of %s\n", expString);
11160 // Let's try to support any_object & typed_object here:
11162 ApplyAnyObjectLogic(exp);
11164 // Mark nohead classes as by reference, unless we're casting them to an integral type
11165 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11166 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11167 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11168 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11170 exp.byReference = true;
11172 yylloc = oldyylloc;
11175 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11177 // THIS CODE WILL FIND NEXT MEMBER...
11180 *curMember = (*curMember).next;
11182 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11184 *curMember = subMemberStack[--(*subMemberStackPos)];
11185 *curMember = (*curMember).next;
11188 // SKIP ALL PROPERTIES HERE...
11189 while((*curMember) && (*curMember).isProperty)
11190 *curMember = (*curMember).next;
11192 if(subMemberStackPos)
11194 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11196 subMemberStack[(*subMemberStackPos)++] = *curMember;
11198 *curMember = (*curMember).members.first;
11199 while(*curMember && (*curMember).isProperty)
11200 *curMember = (*curMember).next;
11208 if(subMemberStackPos && *subMemberStackPos)
11210 *curMember = subMemberStack[--(*subMemberStackPos)];
11211 *curMember = (*curMember).next;
11215 Class lastCurClass = *curClass;
11217 if(*curClass == _class) break; // REACHED THE END
11219 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11220 *curMember = (*curClass).membersAndProperties.first;
11223 while((*curMember) && (*curMember).isProperty)
11224 *curMember = (*curMember).next;
11225 if(subMemberStackPos)
11227 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11229 subMemberStack[(*subMemberStackPos)++] = *curMember;
11231 *curMember = (*curMember).members.first;
11232 while(*curMember && (*curMember).isProperty)
11233 *curMember = (*curMember).next;
11241 static void ProcessInitializer(Initializer init, Type type)
11245 case expInitializer:
11246 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11248 // TESTING THIS FOR SHUTTING = 0 WARNING
11249 if(init.exp && !init.exp.destType)
11251 FreeType(init.exp.destType);
11252 init.exp.destType = type;
11253 if(type) type.refCount++;
11257 ProcessExpressionType(init.exp);
11258 init.isConstant = init.exp.isConstant;
11264 Expression exp = init.exp;
11265 Instantiation inst = exp.instance;
11266 MembersInit members;
11268 init.type = listInitializer;
11269 init.list = MkList();
11273 for(members = inst.members->first; members; members = members.next)
11275 if(members.type == dataMembersInit)
11278 for(member = members.dataMembers->first; member; member = member.next)
11280 ListAdd(init.list, member.initializer);
11281 member.initializer = null;
11284 // Discard all MembersInitMethod
11287 FreeExpression(exp);
11289 case listInitializer:
11292 Type initializerType = null;
11293 Class curClass = null;
11294 DataMember curMember = null;
11295 DataMember subMemberStack[256];
11296 int subMemberStackPos = 0;
11298 if(type && type.kind == arrayType)
11299 initializerType = Dereference(type);
11300 else if(type && (type.kind == structType || type.kind == unionType))
11301 initializerType = type.members.first;
11303 for(i = init.list->first; i; i = i.next)
11305 if(type && type.kind == classType && type._class && type._class.registered)
11307 // 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)
11308 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11309 // TODO: Generate error on initializing a private data member this way from another module...
11312 if(!curMember.dataType)
11313 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11314 initializerType = curMember.dataType;
11317 ProcessInitializer(i, initializerType);
11318 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11319 initializerType = initializerType.next;
11321 init.isConstant = false;
11324 if(type && type.kind == arrayType)
11325 FreeType(initializerType);
11327 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11329 Compiler_Error($"Assigning list initializer to non list\n");
11336 static void ProcessSpecifier(Specifier spec, bool declareStruct)
11340 case baseSpecifier:
11342 if(spec.specifier == THISCLASS)
11346 spec.type = nameSpecifier;
11347 spec.name = ReplaceThisClass(thisClass);
11348 spec.symbol = FindClass(spec.name);
11349 ProcessSpecifier(spec, declareStruct);
11354 case nameSpecifier:
11356 Symbol symbol = FindType(curContext, spec.name);
11358 DeclareType(symbol.type, true, true);
11359 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
11360 DeclareStruct(spec.name, false);
11363 case enumSpecifier:
11368 for(e = spec.list->first; e; e = e.next)
11371 ProcessExpressionType(e.exp);
11376 case structSpecifier:
11377 case unionSpecifier:
11379 if(spec.definitions)
11382 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11384 ProcessClass(spec.definitions, symbol);
11387 for(def = spec.definitions->first; def; def = def.next)
11389 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11390 ProcessDeclaration(def.decl);
11397 case classSpecifier:
11399 Symbol classSym = FindClass(spec.name);
11400 if(classSym && classSym.registered && classSym.registered.type == structClass)
11401 DeclareStruct(spec.name, false);
11409 static void ProcessDeclarator(Declarator decl)
11413 case identifierDeclarator:
11414 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11416 FreeSpecifier(decl.identifier._class);
11417 decl.identifier._class = null;
11420 case arrayDeclarator:
11422 ProcessExpressionType(decl.array.exp);
11423 case structDeclarator:
11424 case bracketsDeclarator:
11425 case functionDeclarator:
11426 case pointerDeclarator:
11427 case extendedDeclarator:
11428 case extendedDeclaratorEnd:
11429 if(decl.declarator)
11430 ProcessDeclarator(decl.declarator);
11431 if(decl.type == functionDeclarator)
11433 Identifier id = GetDeclId(decl);
11434 if(id && id._class)
11438 qualifiers = MkListOne(id._class);
11441 if(!decl.function.parameters)
11442 decl.function.parameters = MkList();
11443 decl.function.parameters->Insert(null, param);
11446 if(decl.function.parameters)
11450 for(param = decl.function.parameters->first; param; param = param.next)
11452 if(param.qualifiers && param.qualifiers->first)
11454 Specifier spec = param.qualifiers->first;
11455 if(spec && spec.specifier == TYPED_OBJECT)
11457 Declarator d = param.declarator;
11460 qualifiers = MkListOne(MkSpecifier(VOID));
11461 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11463 if(d.type != pointerDeclarator)
11464 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11466 FreeList(param.qualifiers, FreeSpecifier);
11468 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11469 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11471 decl.function.parameters->Insert(param, newParam);
11474 else if(spec && spec.specifier == ANY_OBJECT)
11476 Declarator d = param.declarator;
11478 FreeList(param.qualifiers, FreeSpecifier);
11480 param.qualifiers = MkListOne(MkSpecifier(VOID));
11481 if(d.type != pointerDeclarator)
11482 param.qualifiers->Insert(null, MkSpecifier(CONST));
11483 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11485 else if(spec.specifier == THISCLASS)
11489 spec.type = nameSpecifier;
11490 spec.name = ReplaceThisClass(thisClass);
11491 spec.symbol = FindClass(spec.name);
11492 ProcessSpecifier(spec, false);
11497 if(param.declarator)
11498 ProcessDeclarator(param.declarator);
11506 static void ProcessDeclaration(Declaration decl)
11511 case initDeclaration:
11513 bool declareStruct = false;
11515 lineNum = decl.pos.line;
11516 column = decl.pos.col;
11519 if(decl.declarators)
11523 for(d = decl.declarators->first; d; d = d.next)
11525 Type type, subType;
11526 ProcessDeclarator(d.declarator);
11528 type = ProcessType(decl.specifiers, d.declarator);
11532 ProcessInitializer(d.initializer, type);
11534 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11536 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11537 d.initializer.exp.type == instanceExp)
11539 if(type.kind == classType && type._class ==
11540 d.initializer.exp.expType._class)
11542 Instantiation inst = d.initializer.exp.instance;
11543 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11545 d.initializer.exp.instance = null;
11546 if(decl.specifiers)
11547 FreeList(decl.specifiers, FreeSpecifier);
11548 FreeList(decl.declarators, FreeInitDeclarator);
11552 decl.type = instDeclaration;
11557 for(subType = type; subType;)
11559 if(subType.kind == classType)
11561 declareStruct = true;
11564 else if(subType.kind == pointerType)
11566 else if(subType.kind == arrayType)
11567 subType = subType.arrayType;
11577 if(decl.specifiers)
11580 for(s = decl.specifiers->first; s; s = s.next)
11582 ProcessSpecifier(s, declareStruct);
11587 case instDeclaration:
11589 ProcessInstantiationType(decl.inst);
11592 case structDeclaration:
11596 bool declareStruct = false;
11598 if(decl.declarators)
11600 for(d = decl.declarators->first; d; d = d.next)
11602 Type type = ProcessType(decl.specifiers, d.declarator);
11604 ProcessDeclarator(d);
11605 for(subType = type; subType;)
11607 if(subType.kind == classType)
11609 declareStruct = true;
11612 else if(subType.kind == pointerType)
11614 else if(subType.kind == arrayType)
11615 subType = subType.arrayType;
11622 if(decl.specifiers)
11624 for(spec = decl.specifiers->first; spec; spec = spec.next)
11625 ProcessSpecifier(spec, declareStruct);
11632 static FunctionDefinition curFunction;
11634 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11636 char propName[1024], propNameM[1024];
11637 char getName[1024], setName[1024];
11640 DeclareProperty(prop, setName, getName);
11642 // eInstance_FireWatchers(object, prop);
11643 strcpy(propName, "__ecereProp_");
11644 FullClassNameCat(propName, prop._class.fullName, false);
11645 strcat(propName, "_");
11646 // strcat(propName, prop.name);
11647 FullClassNameCat(propName, prop.name, true);
11648 //MangleClassName(propName);
11650 strcpy(propNameM, "__ecerePropM_");
11651 FullClassNameCat(propNameM, prop._class.fullName, false);
11652 strcat(propNameM, "_");
11653 // strcat(propNameM, prop.name);
11654 FullClassNameCat(propNameM, prop.name, true);
11655 //MangleClassName(propNameM);
11657 if(prop.isWatchable)
11660 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11661 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11662 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11665 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11666 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11667 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11673 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11674 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11675 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11678 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11679 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11680 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11683 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11684 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11685 curFunction.propSet.fireWatchersDone = true;
11688 static void ProcessStatement(Statement stmt)
11692 lineNum = stmt.pos.line;
11693 column = stmt.pos.col;
11698 ProcessStatement(stmt.labeled.stmt);
11701 // This expression should be constant...
11702 if(stmt.caseStmt.exp)
11704 FreeType(stmt.caseStmt.exp.destType);
11705 stmt.caseStmt.exp.destType = curSwitchType;
11706 if(curSwitchType) curSwitchType.refCount++;
11707 ProcessExpressionType(stmt.caseStmt.exp);
11708 ComputeExpression(stmt.caseStmt.exp);
11710 if(stmt.caseStmt.stmt)
11711 ProcessStatement(stmt.caseStmt.stmt);
11715 if(stmt.compound.context)
11720 Statement prevCompound = curCompound;
11721 Context prevContext = curContext;
11723 if(!stmt.compound.isSwitch)
11724 curCompound = stmt;
11725 curContext = stmt.compound.context;
11727 if(stmt.compound.declarations)
11729 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11730 ProcessDeclaration(decl);
11732 if(stmt.compound.statements)
11734 for(s = stmt.compound.statements->first; s; s = s.next)
11735 ProcessStatement(s);
11738 curContext = prevContext;
11739 curCompound = prevCompound;
11743 case expressionStmt:
11746 if(stmt.expressions)
11748 for(exp = stmt.expressions->first; exp; exp = exp.next)
11749 ProcessExpressionType(exp);
11757 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11758 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11759 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11760 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11762 ProcessExpressionType(exp);
11764 if(stmt.ifStmt.stmt)
11765 ProcessStatement(stmt.ifStmt.stmt);
11766 if(stmt.ifStmt.elseStmt)
11767 ProcessStatement(stmt.ifStmt.elseStmt);
11772 Type oldSwitchType = curSwitchType;
11773 if(stmt.switchStmt.exp)
11776 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11786 e.exp.destType = destType;
11789 ProcessExpressionType(exp);
11792 curSwitchType = exp.expType;
11795 ProcessStatement(stmt.switchStmt.stmt);
11796 curSwitchType = oldSwitchType;
11801 if(stmt.whileStmt.exp)
11805 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11806 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11807 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11808 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11810 ProcessExpressionType(exp);
11813 if(stmt.whileStmt.stmt)
11814 ProcessStatement(stmt.whileStmt.stmt);
11819 if(stmt.doWhile.exp)
11823 if(stmt.doWhile.exp->last)
11825 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11826 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11827 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11829 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11831 ProcessExpressionType(exp);
11834 if(stmt.doWhile.stmt)
11835 ProcessStatement(stmt.doWhile.stmt);
11841 if(stmt.forStmt.init)
11842 ProcessStatement(stmt.forStmt.init);
11844 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11846 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11847 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11848 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11851 if(stmt.forStmt.check)
11852 ProcessStatement(stmt.forStmt.check);
11853 if(stmt.forStmt.increment)
11855 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11856 ProcessExpressionType(exp);
11859 if(stmt.forStmt.stmt)
11860 ProcessStatement(stmt.forStmt.stmt);
11865 Identifier id = stmt.forEachStmt.id;
11866 OldList * exp = stmt.forEachStmt.exp;
11867 OldList * filter = stmt.forEachStmt.filter;
11868 Statement block = stmt.forEachStmt.stmt;
11869 char iteratorType[1024];
11872 bool isBuiltin = exp && exp->last &&
11873 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11874 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11875 Expression arrayExp;
11876 const char * typeString = null;
11877 int builtinCount = 0;
11879 for(e = exp ? exp->first : null; e; e = e.next)
11883 FreeType(e.destType);
11884 e.destType = ProcessTypeString("Container", false);
11886 if(!isBuiltin || e.next)
11887 ProcessExpressionType(e);
11890 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11891 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11892 eClass_IsDerived(source._class.registered, containerClass)))
11894 Class _class = source ? source._class.registered : null;
11896 Expression expIt = null;
11897 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
11898 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11899 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11900 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11901 stmt.type = compoundStmt;
11903 stmt.compound.context = Context { };
11904 stmt.compound.context.parent = curContext;
11905 curContext = stmt.compound.context;
11907 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11909 Class mapClass = eSystem_FindClass(privateModule, "Map");
11910 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11911 isCustomAVLTree = true;
11912 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
11914 else */if(eClass_IsDerived(source._class.registered, mapClass))
11917 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11918 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11920 Class listClass = eSystem_FindClass(privateModule, "List");
11922 isList = eClass_IsDerived(source._class.registered, listClass);
11928 OldList * specs = MkList();
11929 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11930 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11931 stmt.compound.declarations = MkListOne(
11932 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11933 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11934 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11935 MkInitializerAssignment(MkExpBrackets(exp))))));
11940 char typeStringBuf[1024];
11942 // TODO: Merge this code?
11943 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11944 if(((Expression)exp->last).type == castExp)
11946 TypeName typeName = ((Expression)exp->last).cast.typeName;
11948 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11951 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11952 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11953 arrayExp.destType._class.registered.templateArgs)
11955 Class templateClass = arrayExp.destType._class.registered;
11956 typeString = templateClass.templateArgs[2].dataTypeString;
11958 else if(arrayExp.list)
11960 // Guess type from expressions in the array
11962 for(e = arrayExp.list->first; e; e = e.next)
11964 ProcessExpressionType(e);
11967 if(!type) { type = e.expType; type.refCount++; }
11970 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11971 if(!MatchTypeExpression(e, type, null, false, true))
11977 e = arrayExp.list->first;
11978 ProcessExpressionType(e);
11981 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11982 if(!MatchTypeExpression(e, type, null, false, true))
11984 FreeType(e.expType);
11995 FreeType(e.expType);
12002 typeStringBuf[0] = '\0';
12003 PrintType(type, typeStringBuf, false, true);
12004 typeString = typeStringBuf;
12010 OldList * initializers = MkList();
12012 OldList * specs = MkList();
12017 builtinCount = arrayExp.list->count;
12018 type = ProcessTypeString(typeString, false);
12019 while((e = arrayExp.list->first))
12021 arrayExp.list->Remove(e);
12024 ProcessExpressionType(e);
12025 ListAdd(initializers, MkInitializerAssignment(e));
12028 delete arrayExp.list;
12030 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12031 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12032 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12034 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12036 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12037 ), MkInitializerList(initializers)))));
12038 FreeList(exp, FreeExpression);
12042 arrayExp.expType = ProcessTypeString("Container", false);
12043 Compiler_Error($"Couldn't determine type of array elements\n");
12048 OldList * specs = MkList();
12050 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12051 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12052 stmt.compound.declarations = MkListOne(
12053 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12054 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12055 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12056 MkInitializerAssignment(MkExpBrackets(exp))))));
12059 else if(isLinkList && !isList)
12062 OldList * specs = MkList();
12063 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12064 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12065 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12066 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12067 MkInitializerAssignment(MkExpBrackets(exp))))));
12069 /*else if(isCustomAVLTree)
12072 OldList * specs = MkList();
12073 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12074 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12075 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12076 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12077 MkInitializerAssignment(MkExpBrackets(exp))))));
12079 else if(_class.templateArgs)
12082 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12084 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12086 stmt.compound.declarations = MkListOne(
12087 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12088 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12089 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12091 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12095 // Reparent sub-contexts in this statement
12099 if(block.compound.context)
12100 block.compound.context.parent = stmt.compound.context;
12103 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12104 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12105 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12106 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12109 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12110 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12113 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12114 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12117 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12118 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12121 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12122 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12125 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12126 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12128 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12131 case expressionStmt:
12137 case badDeclarationStmt:
12138 case fireWatchersStmt:
12139 case stopWatchingStmt:
12146 block = MkIfStmt(filter, block, null);
12150 stmt.compound.statements = MkListOne(MkForStmt(
12151 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12152 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12153 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12154 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12156 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12157 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12158 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12163 //OldList * specs = MkList();
12164 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12166 sprintf(count, "%d", builtinCount);
12168 stmt.compound.statements = MkListOne(MkForStmt(
12169 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12170 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12171 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12172 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12176 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12177 stmt.compound.statements = MkListOne(MkForStmt(
12178 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12179 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12180 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12181 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12184 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12185 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12186 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12188 else if(isLinkList && !isList)
12190 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12191 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12192 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12193 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12195 stmt.compound.statements = MkListOne(MkForStmt(
12196 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12197 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12198 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12203 OldList * specs = MkList();
12204 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12205 stmt.compound.statements = MkListOne(MkForStmt(
12206 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12207 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12208 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12209 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12210 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12213 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12214 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12215 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12217 /*else if(isCustomAVLTree)
12219 stmt.compound.statements = MkListOne(MkForStmt(
12220 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12221 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12222 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12223 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12226 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12227 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12228 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12232 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12233 MkIdentifier("Next")), null)), block));
12235 ProcessExpressionType(expIt);
12236 if(stmt.compound.declarations->first)
12237 ProcessDeclaration(stmt.compound.declarations->first);
12240 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12242 ProcessStatement(stmt);
12243 curContext = stmt.compound.context.parent;
12248 Compiler_Error($"Expression is not a container\n");
12261 if(stmt.expressions)
12263 for(exp = stmt.expressions->first; exp; exp = exp.next)
12267 if(curFunction && !curFunction.type)
12268 curFunction.type = ProcessType(
12269 curFunction.specifiers, curFunction.declarator);
12270 FreeType(exp.destType);
12271 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12272 if(exp.destType) exp.destType.refCount++;
12274 ProcessExpressionType(exp);
12279 case badDeclarationStmt:
12281 ProcessDeclaration(stmt.decl);
12287 if(stmt.asmStmt.inputFields)
12289 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12290 if(field.expression)
12291 ProcessExpressionType(field.expression);
12293 if(stmt.asmStmt.outputFields)
12295 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12296 if(field.expression)
12297 ProcessExpressionType(field.expression);
12299 if(stmt.asmStmt.clobberedFields)
12301 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12303 if(field.expression)
12304 ProcessExpressionType(field.expression);
12311 PropertyWatch propWatch;
12312 OldList * watches = stmt._watch.watches;
12313 Expression object = stmt._watch.object;
12314 Expression watcher = stmt._watch.watcher;
12316 ProcessExpressionType(watcher);
12318 ProcessExpressionType(object);
12322 if(watcher || thisClass)
12324 External external = curExternal;
12325 Context context = curContext;
12327 stmt.type = expressionStmt;
12328 stmt.expressions = MkList();
12330 curExternal = external.prev;
12332 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12334 ClassFunction func;
12335 char watcherName[1024];
12336 Class watcherClass = watcher ?
12337 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12338 External createdExternal;
12340 // Create a declaration above
12341 External externalDecl = MkExternalDeclaration(null);
12342 ast->Insert(curExternal.prev, externalDecl);
12344 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12345 if(propWatch.deleteWatch)
12346 strcat(watcherName, "_delete");
12350 for(propID = propWatch.properties->first; propID; propID = propID.next)
12352 strcat(watcherName, "_");
12353 strcat(watcherName, propID.string);
12357 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12359 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
12360 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12361 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
12362 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12363 ProcessClassFunctionBody(func, propWatch.compound);
12364 propWatch.compound = null;
12366 //afterExternal = afterExternal ? afterExternal : curExternal;
12368 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
12369 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12371 createdExternal.symbol.idCode = external.symbol.idCode;
12373 curExternal = createdExternal;
12374 ProcessFunction(createdExternal.function);
12377 // Create a declaration above
12379 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
12380 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
12381 externalDecl.declaration = decl;
12382 if(decl.symbol && !decl.symbol.pointerExternal)
12383 decl.symbol.pointerExternal = externalDecl;
12386 if(propWatch.deleteWatch)
12388 OldList * args = MkList();
12389 ListAdd(args, CopyExpression(object));
12390 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12391 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12392 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12396 Class _class = object.expType._class.registered;
12399 for(propID = propWatch.properties->first; propID; propID = propID.next)
12401 char propName[1024];
12402 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12405 char getName[1024], setName[1024];
12406 OldList * args = MkList();
12408 DeclareProperty(prop, setName, getName);
12410 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12411 strcpy(propName, "__ecereProp_");
12412 FullClassNameCat(propName, prop._class.fullName, false);
12413 strcat(propName, "_");
12414 // strcat(propName, prop.name);
12415 FullClassNameCat(propName, prop.name, true);
12417 ListAdd(args, CopyExpression(object));
12418 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12419 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12420 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12422 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12425 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12430 Compiler_Error($"Invalid watched object\n");
12433 curExternal = external;
12434 curContext = context;
12437 FreeExpression(watcher);
12439 FreeExpression(object);
12440 FreeList(watches, FreePropertyWatch);
12443 Compiler_Error($"No observer specified and not inside a _class\n");
12447 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12449 ProcessStatement(propWatch.compound);
12455 case fireWatchersStmt:
12457 OldList * watches = stmt._watch.watches;
12458 Expression object = stmt._watch.object;
12460 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12461 // printf("%X\n", watches);
12462 // printf("%X\n", stmt._watch.watches);
12464 ProcessExpressionType(object);
12469 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12475 stmt.type = expressionStmt;
12476 stmt.expressions = MkList();
12478 // Check if we're inside a property set
12479 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12481 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12485 //Compiler_Error($"No property specified and not inside a property set\n");
12489 for(propID = watches->first; propID; propID = propID.next)
12491 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12494 CreateFireWatcher(prop, object, stmt);
12497 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12502 // Fire all properties!
12505 for(base = _class; base; base = base.base)
12507 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12509 if(prop.isProperty && prop.isWatchable)
12511 CreateFireWatcher(prop, object, stmt);
12518 FreeExpression(object);
12519 FreeList(watches, FreeIdentifier);
12522 Compiler_Error($"Invalid object specified and not inside a class\n");
12526 case stopWatchingStmt:
12528 OldList * watches = stmt._watch.watches;
12529 Expression object = stmt._watch.object;
12530 Expression watcher = stmt._watch.watcher;
12533 ProcessExpressionType(object);
12535 ProcessExpressionType(watcher);
12538 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12540 if(watcher || thisClass)
12546 stmt.type = expressionStmt;
12547 stmt.expressions = MkList();
12552 // eInstance_StopWatching(object, null, watcher);
12554 ListAdd(args, CopyExpression(object));
12555 ListAdd(args, MkExpConstant("0"));
12556 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12557 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12561 for(propID = watches->first; propID; propID = propID.next)
12563 char propName[1024];
12564 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12567 char getName[1024], setName[1024];
12568 OldList * args = MkList();
12570 DeclareProperty(prop, setName, getName);
12572 // eInstance_StopWatching(object, prop, watcher);
12573 strcpy(propName, "__ecereProp_");
12574 FullClassNameCat(propName, prop._class.fullName, false);
12575 strcat(propName, "_");
12576 // strcat(propName, prop.name);
12577 FullClassNameCat(propName, prop.name, true);
12578 //MangleClassName(propName);
12580 ListAdd(args, CopyExpression(object));
12581 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12582 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12583 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12586 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12591 FreeExpression(object);
12593 FreeExpression(watcher);
12594 FreeList(watches, FreeIdentifier);
12597 Compiler_Error($"Invalid object specified and not inside a class\n");
12600 Compiler_Error($"No observer specified and not inside a class\n");
12607 static void ProcessFunction(FunctionDefinition function)
12609 Identifier id = GetDeclId(function.declarator);
12610 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12611 Type type = symbol ? symbol.type : null;
12612 Class oldThisClass = thisClass;
12613 Context oldTopContext = topContext;
12615 yylloc = function.loc;
12616 // Process thisClass
12618 if(type && type.thisClass)
12620 Symbol classSym = type.thisClass;
12621 Class _class = type.thisClass.registered;
12622 char className[1024];
12623 char structName[1024];
12624 Declarator funcDecl;
12627 bool typedObject = false;
12629 if(_class && !_class.base)
12631 _class = currentClass;
12632 if(_class && !_class.symbol)
12633 _class.symbol = FindClass(_class.fullName);
12634 classSym = _class ? _class.symbol : null;
12635 typedObject = true;
12638 thisClass = _class;
12640 if(inCompiler && _class)
12642 if(type.kind == functionType)
12644 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12646 //TypeName param = symbol.type.params.first;
12647 Type param = symbol.type.params.first;
12648 symbol.type.params.Remove(param);
12649 //FreeTypeName(param);
12652 if(type.classObjectType != classPointer)
12654 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12655 symbol.type.staticMethod = true;
12656 symbol.type.thisClass = null;
12658 // HIGH DANGER: VERIFYING THIS...
12659 symbol.type.extraParam = false;
12663 strcpy(className, "__ecereClass_");
12664 FullClassNameCat(className, _class.fullName, true);
12666 //MangleClassName(className);
12669 FullClassNameCat(structName, _class.fullName, false);
12674 funcDecl = GetFuncDecl(function.declarator);
12677 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12679 TypeName param = funcDecl.function.parameters->first;
12680 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12682 funcDecl.function.parameters->Remove(param);
12683 FreeTypeName(param);
12687 // DANGER: Watch for this... Check if it's a Conversion?
12688 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12690 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12691 if(!function.propertyNoThis)
12693 TypeName thisParam;
12695 if(type.classObjectType != classPointer)
12697 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12698 if(!funcDecl.function.parameters)
12699 funcDecl.function.parameters = MkList();
12700 funcDecl.function.parameters->Insert(null, thisParam);
12705 if(type.classObjectType != classPointer)
12707 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12708 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12711 thisParam = TypeName
12713 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12714 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12716 funcDecl.function.parameters->Insert(null, thisParam);
12721 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12723 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12724 funcDecl = GetFuncDecl(initDecl.declarator);
12727 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12729 TypeName param = funcDecl.function.parameters->first;
12730 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12732 funcDecl.function.parameters->Remove(param);
12733 FreeTypeName(param);
12737 if(type.classObjectType != classPointer)
12739 // DANGER: Watch for this... Check if it's a Conversion?
12740 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12742 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12744 if(!funcDecl.function.parameters)
12745 funcDecl.function.parameters = MkList();
12746 funcDecl.function.parameters->Insert(null, thisParam);
12753 // Add this to the context
12756 if(type.classObjectType != classPointer)
12758 thisSymbol = Symbol
12760 string = CopyString("this");
12761 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12763 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12765 if(typedObject && thisSymbol.type)
12767 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12768 thisSymbol.type.byReference = type.byReference;
12769 thisSymbol.type.typedByReference = type.byReference;
12771 thisSymbol = Symbol { string = CopyString("class") };
12772 function.body.compound.context.symbols.Add(thisSymbol);
12778 // Pointer to class data
12780 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12782 DataMember member = null;
12785 for(base = _class; base && base.type != systemClass; base = base.next)
12787 for(member = base.membersAndProperties.first; member; member = member.next)
12788 if(!member.isProperty)
12794 for(member = _class.membersAndProperties.first; member; member = member.next)
12795 if(!member.isProperty)
12799 char pointerName[1024];
12802 Initializer initializer;
12803 Expression exp, bytePtr;
12805 strcpy(pointerName, "__ecerePointer_");
12806 FullClassNameCat(pointerName, _class.fullName, false);
12808 char className[1024];
12809 strcpy(className, "__ecereClass_");
12810 FullClassNameCat(className, classSym.string, true);
12811 //MangleClassName(className);
12814 DeclareClass(classSym, className);
12818 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12823 sprintf(string, "%d", _class.offset);
12824 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12828 // ([bytePtr] + [className]->offset)
12829 exp = QBrackets(MkExpOp(bytePtr, '+',
12830 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12833 // (this ? [exp] : 0)
12834 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12838 kind = pointerType;
12839 type = Type { refCount = 1, kind = voidType };
12844 yylloc = function.body.loc;
12845 // ([structName] *) [exp]
12846 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12847 initializer = MkInitializerAssignment(
12848 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12850 // [structName] * [pointerName] = [initializer];
12851 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12854 Context prevContext = curContext;
12855 curContext = function.body.compound.context;
12857 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12858 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12860 curContext = prevContext;
12864 decl.symbol = null;
12866 if(!function.body.compound.declarations)
12867 function.body.compound.declarations = MkList();
12868 function.body.compound.declarations->Insert(null, decl);
12874 // Loop through the function and replace undeclared identifiers
12875 // which are a member of the class (methods, properties or data)
12876 // by "this.[member]"
12883 FreeSpecifier(id._class);
12886 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12888 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12889 id = GetDeclId(initDecl.declarator);
12891 FreeSpecifier(id._class);
12896 topContext = function.body.compound.context;
12898 FunctionDefinition oldFunction = curFunction;
12899 curFunction = function;
12901 ProcessStatement(function.body);
12903 // If this is a property set and no firewatchers has been done yet, add one here
12904 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12906 Statement prevCompound = curCompound;
12907 Context prevContext = curContext;
12909 Statement fireWatchers = MkFireWatchersStmt(null, null);
12910 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12911 ListAdd(function.body.compound.statements, fireWatchers);
12913 curCompound = function.body;
12914 curContext = function.body.compound.context;
12916 ProcessStatement(fireWatchers);
12918 curContext = prevContext;
12919 curCompound = prevCompound;
12923 curFunction = oldFunction;
12926 if(function.declarator)
12928 ProcessDeclarator(function.declarator);
12931 topContext = oldTopContext;
12932 thisClass = oldThisClass;
12935 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12936 static void ProcessClass(OldList definitions, Symbol symbol)
12939 External external = curExternal;
12940 Class regClass = symbol ? symbol.registered : null;
12942 // Process all functions
12943 for(def = definitions.first; def; def = def.next)
12945 if(def.type == functionClassDef)
12947 if(def.function.declarator)
12948 curExternal = def.function.declarator.symbol.pointerExternal;
12950 curExternal = external;
12952 ProcessFunction((FunctionDefinition)def.function);
12954 else if(def.type == declarationClassDef)
12956 if(def.decl.type == instDeclaration)
12958 thisClass = regClass;
12959 ProcessInstantiationType(def.decl.inst);
12965 Class backThisClass = thisClass;
12966 if(regClass) thisClass = regClass;
12967 ProcessDeclaration(def.decl);
12968 thisClass = backThisClass;
12971 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12973 MemberInit defProperty;
12975 // Add this to the context
12976 Symbol thisSymbol = Symbol
12978 string = CopyString("this");
12979 type = regClass ? MkClassType(regClass.fullName) : null;
12981 globalContext.symbols.Add((BTNode)thisSymbol);
12983 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12985 thisClass = regClass;
12986 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12990 globalContext.symbols.Remove((BTNode)thisSymbol);
12991 FreeSymbol(thisSymbol);
12993 else if(def.type == propertyClassDef && def.propertyDef)
12995 PropertyDef prop = def.propertyDef;
12997 // Add this to the context
12999 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
13000 globalContext.symbols.Add(thisSymbol);
13003 thisClass = regClass;
13010 string = CopyString("this");
13011 type = MkClassType(regClass.fullName);
13013 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13016 curExternal = prop.symbol ? prop.symbol.externalSet : null;
13017 ProcessStatement(prop.setStmt);
13025 string = CopyString("this");
13026 type = MkClassType(regClass.fullName);
13028 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13031 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13032 ProcessStatement(prop.getStmt);
13040 string = CopyString("this");
13041 type = MkClassType(regClass.fullName);
13043 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13046 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13047 ProcessStatement(prop.issetStmt);
13053 globalContext.symbols.Remove(thisSymbol);
13054 FreeSymbol(thisSymbol);
13057 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13059 PropertyWatch propertyWatch = def.propertyWatch;
13061 thisClass = regClass;
13062 if(propertyWatch.compound)
13066 string = CopyString("this");
13067 type = regClass ? MkClassType(regClass.fullName) : null;
13070 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13072 curExternal = null;
13073 ProcessStatement(propertyWatch.compound);
13080 void DeclareFunctionUtil(const String s)
13082 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13087 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13088 strcpy(name, "__ecereFunction_");
13089 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13090 DeclareFunction(function, name);
13094 void ComputeDataTypes()
13098 External after = null;
13100 currentClass = null;
13102 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13104 for(external = ast->first; external; external = external.next)
13106 if(external.type == declarationExternal)
13108 Declaration decl = external.declaration;
13111 OldList * decls = decl.declarators;
13114 InitDeclarator initDecl = decls->first;
13117 Declarator declarator = initDecl.declarator;
13118 if(declarator && declarator.type == identifierDeclarator)
13120 Identifier id = declarator.identifier;
13121 if(id && id.string)
13123 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
13125 external.symbol.id = -1001, external.symbol.idCode = -1001;
13137 // Workaround until we have proper toposort for declarations reordering
13138 External e = MkExternalDeclaration(MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Instance"), null)), null));
13139 ast->Insert(after, e);
13143 temp.symbol = Symbol { id = -1000, idCode = -1000 };
13144 ast->Insert(after, temp);
13145 curExternal = temp;
13147 DeclareFunctionUtil("eSystem_New");
13148 DeclareFunctionUtil("eSystem_New0");
13149 DeclareFunctionUtil("eSystem_Renew");
13150 DeclareFunctionUtil("eSystem_Renew0");
13151 DeclareFunctionUtil("eSystem_Delete");
13152 DeclareFunctionUtil("eClass_GetProperty");
13153 DeclareFunctionUtil("eClass_SetProperty");
13154 DeclareFunctionUtil("eInstance_FireSelfWatchers");
13155 DeclareFunctionUtil("eInstance_SetMethod");
13156 DeclareFunctionUtil("eInstance_IncRef");
13157 DeclareFunctionUtil("eInstance_StopWatching");
13158 DeclareFunctionUtil("eInstance_Watch");
13159 DeclareFunctionUtil("eInstance_FireWatchers");
13161 DeclareStruct("ecere::com::Class", false);
13162 DeclareStruct("ecere::com::Instance", false);
13163 DeclareStruct("ecere::com::Property", false);
13164 DeclareStruct("ecere::com::DataMember", false);
13165 DeclareStruct("ecere::com::Method", false);
13166 DeclareStruct("ecere::com::SerialBuffer", false);
13167 DeclareStruct("ecere::com::ClassTemplateArgument", false);
13171 for(external = ast->first; external; external = external.next)
13173 afterExternal = curExternal = external;
13174 if(external.type == functionExternal)
13176 currentClass = external.function._class;
13177 ProcessFunction(external.function);
13179 // There shouldn't be any _class member access here anyways...
13180 else if(external.type == declarationExternal)
13182 currentClass = null;
13183 if(external.declaration)
13184 ProcessDeclaration(external.declaration);
13186 else if(external.type == classExternal)
13188 ClassDefinition _class = external._class;
13189 currentClass = external.symbol.registered;
13190 if(_class.definitions)
13192 ProcessClass(_class.definitions, _class.symbol);
13196 // Free class data...
13197 ast->Remove(external);
13201 else if(external.type == nameSpaceExternal)
13203 thisNameSpace = external.id.string;
13206 currentClass = null;
13207 thisNameSpace = null;
13208 curExternal = null;
13210 delete temp.symbol;