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 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;
892 Context context = isMember ? null : SetupTemplatesContext(_class);
894 *addedPadding = false;
896 if(!isMember && _class.base)
898 maxSize = _class.structSize;
899 //if(_class.base.type != systemClass) // Commented out with new Instance _class
901 // DANGER: Testing this noHeadClass here...
902 if(_class.type == structClass || _class.type == noHeadClass)
903 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
906 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
907 if(maxSize > baseSize)
915 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
917 if(!member.isProperty)
923 if(member.dataTypeString)
925 OldList * specs = MkList(), * decls = MkList();
928 decl = SpecDeclFromString(member.dataTypeString, specs,
929 MkDeclaratorIdentifier(MkIdentifier(member.name)));
930 ListAdd(decls, MkStructDeclarator(decl, null));
931 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
934 member.dataType = ProcessType(specs, decl);
936 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
939 Type type = ProcessType(specs, decl);
940 DeclareType(member.dataType, false, false);
944 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
945 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
946 DeclareStruct(member.dataType._class.string, false);
949 ComputeTypeSize(member.dataType);
950 size = member.dataType.size;
951 alignment = member.dataType.alignment;
955 if(totalSize % alignment)
956 totalSize += alignment - (totalSize % alignment);
965 OldList * specs = MkList(), * list = MkList();
968 AddMembers(list, (Class)member, true, &size, topClass, null);
970 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
971 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, null, null)));
972 alignment = member.structAlignment;
976 if(totalSize % alignment)
977 totalSize += alignment - (totalSize % alignment);
987 if(topMember && topMember.type == unionMember)
988 *retSize = Max(*retSize, totalSize);
990 *retSize += totalSize;
992 else if(totalSize < maxSize && _class.type != systemClass)
995 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
996 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
997 if(totalSize + autoPadding < maxSize)
1000 sprintf(sizeString, "%d", maxSize - totalSize);
1001 ListAdd(declarations,
1002 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1003 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1005 *addedPadding = true;
1009 FinishTemplatesContext(context);
1010 return topMember ? topMember.memberID : _class.memberID;
1013 static int DeclareMembers(Class _class, bool isMember)
1015 DataMember topMember = isMember ? (DataMember) _class : null;
1017 Context context = isMember ? null : SetupTemplatesContext(_class);
1019 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1020 DeclareMembers(_class.base, false);
1022 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1024 if(!member.isProperty)
1031 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1032 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1033 DeclareStruct(member.dataType._class.string, false);
1035 if(!member.dataType && member.dataTypeString)
1036 member.dataType = ProcessTypeString(member.dataTypeString, false);
1038 DeclareType(member.dataType, false, false);
1044 DeclareMembers((Class)member, true);
1051 FinishTemplatesContext(context);
1053 return topMember ? topMember.memberID : _class.memberID;
1056 void DeclareStruct(char * name, bool skipNoHead)
1058 External external = null;
1059 Symbol classSym = FindClass(name);
1061 if(!inCompiler || !classSym) return;
1063 // We don't need any declaration for bit classes...
1064 if(classSym.registered &&
1065 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1068 /*if(classSym.registered.templateClass)
1069 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1072 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1074 // Add typedef struct
1076 OldList * specifiers, * declarators;
1077 OldList * declarations = null;
1078 char structName[1024];
1079 Specifier spec = null;
1080 external = (classSym.registered && classSym.registered.type == structClass) ?
1081 classSym.pointerExternal : classSym.structExternal;
1083 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1084 // Moved this one up because DeclareClass done later will need it
1086 classSym.declaring++;
1088 if(strchr(classSym.string, '<'))
1090 if(classSym.registered.templateClass)
1092 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1093 classSym.declaring--;
1099 DeclareMembers(classSym.registered, false);
1102 FullClassNameCat(structName, name, false);
1104 if(external && external.declaration && external.declaration.specifiers)
1106 for(spec = external.declaration.specifiers->first; spec; spec = spec.next)
1108 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1114 external = MkExternalDeclaration(null);*/
1116 if(!skipNoHead && (!spec || !spec.definitions))
1118 bool addedPadding = false;
1119 classSym.declaredStructSym = true;
1121 declarations = MkList();
1123 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1125 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1126 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1128 if(!declarations->count || (declarations->count == 1 && addedPadding))
1130 FreeList(declarations, FreeClassDef);
1131 declarations = null;
1134 if(skipNoHead || declarations)
1139 spec.definitions = declarations;
1141 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1144 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1147 if(classSym.structExternal)
1148 ast->Move(classSym.structExternal, curExternal.prev);
1149 ast->Move(classSym.pointerExternal, curExternal.prev);
1151 classSym.id = curExternal.symbol.idCode;
1152 classSym.idCode = curExternal.symbol.idCode;
1153 // external = classSym.pointerExternal;
1154 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1160 external = MkExternalDeclaration(null);
1162 specifiers = MkList();
1163 declarators = MkList();
1164 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1167 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1168 ListAdd(declarators, MkInitDeclarator(d, null));
1170 external.declaration = decl = MkDeclaration(specifiers, declarators);
1171 if(decl.symbol && !decl.symbol.pointerExternal)
1172 decl.symbol.pointerExternal = external;
1174 // For simple classes, keep the declaration as the external to move around
1175 if(classSym.registered && classSym.registered.type == structClass)
1177 char className[1024];
1178 strcpy(className, "__ecereClass_");
1179 FullClassNameCat(className, classSym.string, true);
1180 MangleClassName(className);
1183 DeclareClass(classSym, className);
1185 external.symbol = classSym;
1186 classSym.pointerExternal = external;
1187 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1188 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1192 char className[1024];
1193 strcpy(className, "__ecereClass_");
1194 FullClassNameCat(className, classSym.string, true);
1195 MangleClassName(className);
1197 // TOFIX: TESTING THIS...
1198 classSym.structExternal = external;
1199 DeclareClass(classSym, className);
1200 external.symbol = classSym;
1204 ast->Insert(curExternal ? curExternal.prev : null, external);
1208 classSym.declaring--;
1210 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1212 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1213 // Moved this one up because DeclareClass done later will need it
1216 classSym.declaring++;
1220 if(classSym.registered)
1221 DeclareMembers(classSym.registered, false);
1224 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1227 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1230 if(classSym.structExternal)
1231 ast->Move(classSym.structExternal, curExternal.prev);
1232 ast->Move(classSym.pointerExternal, curExternal.prev);
1234 classSym.id = curExternal.symbol.idCode;
1235 classSym.idCode = curExternal.symbol.idCode;
1236 // external = classSym.pointerExternal;
1237 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1240 classSym.declaring--;
1245 void DeclareProperty(Property prop, char * setName, char * getName)
1247 Symbol symbol = prop.symbol;
1248 char propName[1024];
1250 strcpy(setName, "__ecereProp_");
1251 FullClassNameCat(setName, prop._class.fullName, false);
1252 strcat(setName, "_Set_");
1253 // strcat(setName, prop.name);
1254 FullClassNameCat(setName, prop.name, true);
1256 strcpy(getName, "__ecereProp_");
1257 FullClassNameCat(getName, prop._class.fullName, false);
1258 strcat(getName, "_Get_");
1259 FullClassNameCat(getName, prop.name, true);
1260 // strcat(getName, prop.name);
1262 strcpy(propName, "__ecereProp_");
1263 FullClassNameCat(propName, prop._class.fullName, false);
1264 strcat(propName, "_");
1265 FullClassNameCat(propName, prop.name, true);
1266 // strcat(propName, prop.name);
1268 // To support "char *" property
1269 MangleClassName(getName);
1270 MangleClassName(setName);
1271 MangleClassName(propName);
1273 if(prop._class.type == structClass)
1274 DeclareStruct(prop._class.fullName, false);
1276 if(!symbol || curExternal.symbol.idCode < symbol.id)
1278 bool imported = false;
1279 bool dllImport = false;
1280 if(!symbol || symbol._import)
1285 if(!prop._class.symbol)
1286 prop._class.symbol = FindClass(prop._class.fullName);
1287 classSym = prop._class.symbol;
1288 if(classSym && !classSym._import)
1290 ModuleImport module;
1292 if(prop._class.module)
1293 module = FindModule(prop._class.module);
1295 module = mainModule;
1297 classSym._import = ClassImport
1299 name = CopyString(prop._class.fullName);
1300 isRemote = prop._class.isRemote;
1302 module.classes.Add(classSym._import);
1304 symbol = prop.symbol = Symbol { };
1305 symbol._import = (ClassImport)PropertyImport
1307 name = CopyString(prop.name);
1308 isVirtual = false; //prop.isVirtual;
1309 hasSet = prop.Set ? true : false;
1310 hasGet = prop.Get ? true : false;
1313 classSym._import.properties.Add(symbol._import);
1316 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1317 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1318 prop._class.module.importType != staticImport)
1324 Context context = SetupTemplatesContext(prop._class);
1325 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1326 FinishTemplatesContext(context);
1332 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1335 OldList * specifiers, * declarators;
1340 Declarator typeDecl;
1341 bool simple = false;
1343 specifiers = MkList();
1344 declarators = MkList();
1347 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1348 MkDeclaratorIdentifier(MkIdentifier("this"))));
1350 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1353 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1356 Context context = SetupTemplatesContext(prop._class);
1357 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1358 FinishTemplatesContext(context);
1361 // Make sure the simple _class's type is declared
1362 for(spec = specifiers->first; spec; spec = spec.next)
1364 if(spec.type == nameSpecifier /*SpecifierClass*/)
1366 if((!typeDecl || typeDecl.type == identifierDeclarator))
1368 Symbol classSym = spec.symbol; // FindClass(spec.name);
1369 symbol._class = classSym.registered;
1370 if(classSym.registered && classSym.registered.type == structClass)
1372 DeclareStruct(spec.name, false);
1380 d = PlugDeclarator(typeDecl, d);
1383 ListAdd(params, MkTypeName(specifiers,
1384 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1385 specifiers = MkList();
1388 d = MkDeclaratorFunction(d, params);
1392 specifiers->Insert(null, MkSpecifier(EXTERN));
1393 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1394 specifiers->Insert(null, MkSpecifier(STATIC));
1396 ListAdd(specifiers, MkSpecifier(VOID));
1398 ListAdd(declarators, MkInitDeclarator(d, null));
1400 decl = MkDeclaration(specifiers, declarators);
1402 external = MkExternalDeclaration(decl);
1403 ast->Insert(curExternal.prev, external);
1404 external.symbol = symbol;
1405 symbol.externalGet = external;
1407 ReplaceThisClassSpecifiers(specifiers, prop._class);
1410 FreeDeclarator(typeDecl);
1414 // Move declaration higher...
1415 ast->Move(symbol.externalGet, curExternal.prev);
1422 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1425 OldList * specifiers, * declarators;
1430 Declarator typeDecl;
1432 declarators = MkList();
1435 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1436 if(!prop.conversion || prop._class.type == structClass)
1438 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1439 MkDeclaratorIdentifier(MkIdentifier("this"))));
1442 specifiers = MkList();
1445 Context context = SetupTemplatesContext(prop._class);
1446 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1447 MkDeclaratorIdentifier(MkIdentifier("value")));
1448 FinishTemplatesContext(context);
1450 ListAdd(params, MkTypeName(specifiers, d));
1452 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1455 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1456 d = MkDeclaratorFunction(d, params);
1458 // Make sure the simple _class's type is declared
1459 for(spec = specifiers->first; spec; spec = spec.next)
1461 if(spec.type == nameSpecifier /*SpecifierClass*/)
1463 if((!typeDecl || typeDecl.type == identifierDeclarator))
1465 Symbol classSym = spec.symbol; // FindClass(spec.name);
1466 symbol._class = classSym.registered;
1467 if(classSym.registered && classSym.registered.type == structClass)
1468 DeclareStruct(spec.name, false);
1473 ListAdd(declarators, MkInitDeclarator(d, null));
1475 specifiers = MkList();
1478 specifiers->Insert(null, MkSpecifier(EXTERN));
1479 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1480 specifiers->Insert(null, MkSpecifier(STATIC));
1482 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1483 if(!prop.conversion || prop._class.type == structClass)
1484 ListAdd(specifiers, MkSpecifier(VOID));
1486 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1488 decl = MkDeclaration(specifiers, declarators);
1490 external = MkExternalDeclaration(decl);
1491 ast->Insert(curExternal.prev, external);
1492 external.symbol = symbol;
1493 symbol.externalSet = external;
1495 ReplaceThisClassSpecifiers(specifiers, prop._class);
1499 // Move declaration higher...
1500 ast->Move(symbol.externalSet, curExternal.prev);
1504 // Property (for Watchers)
1505 if(!symbol.externalPtr)
1509 OldList * specifiers = MkList();
1512 specifiers->Insert(null, MkSpecifier(EXTERN));
1514 specifiers->Insert(null, MkSpecifier(STATIC));
1516 ListAdd(specifiers, MkSpecifierName("Property"));
1519 OldList * list = MkList();
1520 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1521 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1525 strcpy(propName, "__ecerePropM_");
1526 FullClassNameCat(propName, prop._class.fullName, false);
1527 strcat(propName, "_");
1528 // strcat(propName, prop.name);
1529 FullClassNameCat(propName, prop.name, true);
1531 MangleClassName(propName);
1533 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1534 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1536 decl = MkDeclaration(specifiers, list);
1539 external = MkExternalDeclaration(decl);
1540 ast->Insert(curExternal.prev, external);
1541 external.symbol = symbol;
1542 symbol.externalPtr = external;
1546 // Move declaration higher...
1547 ast->Move(symbol.externalPtr, curExternal.prev);
1550 symbol.id = curExternal.symbol.idCode;
1554 // ***************** EXPRESSION PROCESSING ***************************
1555 public Type Dereference(Type source)
1560 if(source.kind == pointerType || source.kind == arrayType)
1563 source.type.refCount++;
1565 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1573 // Support dereferencing of no head classes for now...
1574 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1580 Compiler_Error($"cannot dereference type\n");
1585 static Type Reference(Type source)
1601 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1603 Identifier ident = member.identifiers ? member.identifiers->first : null;
1605 DataMember dataMember = null;
1606 Method method = null;
1607 bool freeType = false;
1609 yylloc = member.loc;
1615 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1619 dataMember = *curMember;
1625 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1626 DataMember _subMemberStack[256];
1627 int _subMemberStackPos = 0;
1629 // FILL MEMBER STACK
1631 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1634 dataMember = thisMember;
1635 if(curMember && thisMember.memberAccess == publicAccess)
1637 *curMember = thisMember;
1638 *curClass = thisMember._class;
1639 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1640 *subMemberStackPos = _subMemberStackPos;
1647 method = eClass_FindMethod(_class, ident.string, privateModule);
1648 if(method && method.type == virtualMethod)
1660 if(!dataMember.dataType && dataMember.dataTypeString)
1662 //Context context = SetupTemplatesContext(dataMember._class);
1663 Context context = SetupTemplatesContext(_class);
1664 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1665 FinishTemplatesContext(context);
1667 type = dataMember.dataType;
1671 // This is for destination type...
1672 if(!method.dataType)
1673 ProcessMethodType(method);
1674 //DeclareMethod(method);
1675 // method.dataType = ((Symbol)method.symbol)->type;
1676 type = method.dataType;
1679 if(ident && ident.next)
1681 for(ident = ident.next; ident && type; ident = ident.next)
1683 if(type.kind == classType)
1685 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1687 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1689 type = dataMember.dataType;
1691 else if(type.kind == structType || type.kind == unionType)
1694 for(memberType = type.members.first; memberType; memberType = memberType.next)
1696 if(!strcmp(memberType.name, ident.string))
1706 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1707 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1710 ClassTemplateParameter curParam = null;
1712 for(sClass = _class; sClass; sClass = sClass.base)
1715 if(sClass.templateClass) sClass = sClass.templateClass;
1716 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1718 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1720 for(sClass = sClass.base; sClass; sClass = sClass.base)
1722 if(sClass.templateClass) sClass = sClass.templateClass;
1723 id += sClass.templateParams.count;
1734 ClassTemplateArgument arg = _class.templateArgs[id];
1735 if(arg.dataTypeString)
1738 type = ProcessTypeString(arg.dataTypeString, false);
1740 if(type && _class.templateClass)
1741 type.passAsTemplate = true;
1747 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1748 exp.destType.refCount++;
1754 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1756 Class expClass = type._class.registered;
1757 Class cClass = null;
1762 char templateString[1024];
1763 ClassTemplateParameter param;
1764 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1765 for(cClass = expClass; cClass; cClass = cClass.base)
1768 if(cClass.templateClass) cClass = cClass.templateClass;
1769 for(param = cClass.templateParams.first; param; param = param.next)
1773 ClassTemplateArgument arg;
1774 for(sClass = cClass.base; sClass; sClass = sClass.base)
1776 if(sClass.templateClass) sClass = sClass.templateClass;
1777 id += sClass.templateParams.count;
1779 arg = expClass.templateArgs[id];
1781 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1783 ClassTemplateParameter cParam;
1784 //int p = numParams - sClass.templateParams.count;
1787 if(sClass.templateClass) sClass = sClass.templateClass;
1789 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1791 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1792 p += nextClass.templateParams.count;
1795 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1797 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1799 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1801 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1802 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1814 strcat(argument, arg.name.string);
1815 strcat(argument, " = ");
1821 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1822 char expString[1024];
1823 OldList * specs = MkList();
1824 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1826 char * string = PrintHexUInt64(arg.expression.ui64);
1827 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1830 ProcessExpressionType(exp);
1831 ComputeExpression(exp);
1832 expString[0] = '\0';
1833 PrintExpression(exp, expString);
1834 strcat(argument, expString);
1836 FreeExpression(exp);
1841 strcat(argument, arg.member.name);
1844 case TemplateParameterType::type:
1846 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1847 strcat(argument, arg.dataTypeString);
1853 if(paramCount) strcat(templateString, ", ");
1854 if(lastParam != p - 1)
1856 strcat(templateString, param.name);
1857 strcat(templateString, " = ");
1859 strcat(templateString, argument);
1868 int len = strlen(templateString);
1869 if(templateString[len-1] == '<')
1873 if(templateString[len-1] == '>')
1874 templateString[len++] = ' ';
1875 templateString[len++] = '>';
1877 templateString[len++] = '\0';
1880 Context context = SetupTemplatesContext(_class);
1881 if(freeType) FreeType(type);
1882 type = ProcessTypeString(templateString, false);
1884 FinishTemplatesContext(context);
1888 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1890 ProcessExpressionType(member.initializer.exp);
1891 if(!member.initializer.exp.expType)
1895 char expString[10240];
1896 expString[0] = '\0';
1897 PrintExpression(member.initializer.exp, expString);
1898 ChangeCh(expString, '\n', ' ');
1899 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1902 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1903 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1905 Compiler_Error($"incompatible instance method %s\n", ident.string);
1908 else if(member.initializer)
1911 FreeType(member.exp.destType);
1912 member.exp.destType = type;
1913 if(member.exp.destType)
1914 member.exp.destType.refCount++;
1915 ProcessExpressionType(member.exp);
1918 ProcessInitializer(member.initializer, type);
1920 if(freeType) FreeType(type);
1924 if(_class && _class.type == unitClass)
1926 if(member.initializer)
1929 FreeType(member.exp.destType);
1930 member.exp.destType = MkClassType(_class.fullName);
1931 ProcessExpressionType(member.initializer, type);
1933 Type type = MkClassType(_class.fullName);
1934 ProcessInitializer(member.initializer, type);
1940 if(member.initializer)
1942 //ProcessExpressionType(member.exp);
1943 ProcessInitializer(member.initializer, null);
1949 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1953 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1955 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1959 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1964 void ProcessInstantiationType(Instantiation inst)
1969 MembersInit members;
1970 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1973 /*if(!inst._class.symbol)
1974 inst._class.symbol = FindClass(inst._class.name);*/
1975 classSym = inst._class.symbol;
1976 _class = classSym ? classSym.registered : null;
1978 // DANGER: Patch for mutex not declaring its struct when not needed
1979 if(!_class || _class.type != noHeadClass)
1980 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1982 afterExternal = afterExternal ? afterExternal : curExternal;
1985 ProcessExpressionType(inst.exp);
1987 inst.isConstant = true;
1990 DataMember curMember = null;
1991 Class curClass = null;
1992 DataMember subMemberStack[256];
1993 int subMemberStackPos = 0;
1995 for(members = inst.members->first; members; members = members.next)
1997 switch(members.type)
1999 case methodMembersInit:
2002 static uint instMethodID = 0;
2003 External external = curExternal;
2004 Context context = curContext;
2005 Declarator declarator = members.function.declarator;
2006 Identifier nameID = GetDeclId(declarator);
2007 char * unmangled = nameID ? nameID.string : null;
2009 External createdExternal = null;
2014 //members.function.dontMangle = true;
2015 strcpy(name, "__ecereInstMeth_");
2016 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2018 strcat(name, nameID.string);
2020 sprintf(number, "_%08d", instMethodID++);
2021 strcat(name, number);
2022 nameID.string = CopyString(name);
2025 // Do modifications here...
2028 Symbol symbol = declarator.symbol;
2029 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2031 if(method && method.type == virtualMethod)
2033 symbol.method = method;
2034 ProcessMethodType(method);
2036 if(!symbol.type.thisClass)
2038 if(method.dataType.thisClass && currentClass &&
2039 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2041 if(!currentClass.symbol)
2042 currentClass.symbol = FindClass(currentClass.fullName);
2043 symbol.type.thisClass = currentClass.symbol;
2048 _class.symbol = FindClass(_class.fullName);
2049 symbol.type.thisClass = _class.symbol;
2052 // TESTING THIS HERE:
2053 DeclareType(symbol.type, true, true);
2058 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2059 unmangled, classSym.string);
2063 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2064 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2068 FreeSpecifier(nameID._class);
2069 nameID._class = null;
2074 //Type type = declarator.symbol.type;
2075 External oldExternal = curExternal;
2077 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2078 // *** It was commented out for problems such as
2080 class VirtualDesktop : Window
2082 clientSize = Size { };
2093 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2095 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2098 if(strcmp(declarator.symbol.string, name))
2100 printf("TOCHECK: Look out for this\n");
2101 delete declarator.symbol.string;
2102 declarator.symbol.string = CopyString(name);
2105 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2107 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2108 excludedSymbols->Remove(declarator.symbol);
2109 globalContext.symbols.Add((BTNode)declarator.symbol);
2110 if(strstr(declarator.symbol.string), "::")
2111 globalContext.hasNameSpace = true;
2116 //curExternal = curExternal.prev;
2117 //afterExternal = afterExternal->next;
2119 //ProcessFunction(afterExternal->function);
2121 //curExternal = afterExternal;
2123 External externalDecl;
2124 externalDecl = MkExternalDeclaration(null);
2125 ast->Insert(oldExternal.prev, externalDecl);
2127 // Which function does this process?
2128 if(createdExternal.function)
2130 ProcessFunction(createdExternal.function);
2132 //curExternal = oldExternal;
2135 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2137 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2138 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2140 //externalDecl = MkExternalDeclaration(decl);
2142 //***** ast->Insert(external.prev, externalDecl);
2143 //ast->Insert(curExternal.prev, externalDecl);
2144 externalDecl.declaration = decl;
2145 if(decl.symbol && !decl.symbol.pointerExternal)
2146 decl.symbol.pointerExternal = externalDecl;
2148 // Trying this out...
2149 declarator.symbol.pointerExternal = externalDecl;
2156 curExternal = declarator.symbol.pointerExternal;
2157 ProcessFunction((FunctionDefinition)members.function);
2159 curExternal = external;
2160 curContext = context;
2164 FreeClassFunction(members.function);
2166 // In this pass, turn this into a MemberInitData
2167 exp = QMkExpId(name);
2168 members.type = dataMembersInit;
2169 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2175 case dataMembersInit:
2177 if(members.dataMembers && classSym)
2180 Location oldyyloc = yylloc;
2181 for(member = members.dataMembers->first; member; member = member.next)
2183 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2184 if(member.initializer && !member.initializer.isConstant)
2185 inst.isConstant = false;
2197 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2199 // OPTIMIZATIONS: TESTING THIS...
2202 if(type.kind == functionType)
2207 for(param = type.params.first; param; param = param.next)
2208 DeclareType(param, declarePointers, true);
2210 DeclareType(type.returnType, declarePointers, true);
2212 else if(type.kind == pointerType && declarePointers)
2213 DeclareType(type.type, declarePointers, false);
2214 else if(type.kind == classType)
2216 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2217 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2219 else if(type.kind == structType || type.kind == unionType)
2222 for(member = type.members.first; member; member = member.next)
2223 DeclareType(member, false, false);
2225 else if(type.kind == arrayType)
2226 DeclareType(type.arrayType, declarePointers, false);
2230 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2232 ClassTemplateArgument * arg = null;
2234 ClassTemplateParameter curParam = null;
2236 for(sClass = _class; sClass; sClass = sClass.base)
2239 if(sClass.templateClass) sClass = sClass.templateClass;
2240 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2242 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2244 for(sClass = sClass.base; sClass; sClass = sClass.base)
2246 if(sClass.templateClass) sClass = sClass.templateClass;
2247 id += sClass.templateParams.count;
2257 arg = &_class.templateArgs[id];
2258 if(arg && param.type == type)
2259 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2264 public Context SetupTemplatesContext(Class _class)
2266 Context context = PushContext();
2267 context.templateTypesOnly = true;
2268 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2270 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2271 for(; param; param = param.next)
2273 if(param.type == type && param.identifier)
2275 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2276 curContext.templateTypes.Add((BTNode)type);
2283 for(sClass = _class; sClass; sClass = sClass.base)
2285 ClassTemplateParameter p;
2286 for(p = sClass.templateParams.first; p; p = p.next)
2288 //OldList * specs = MkList();
2289 //Declarator decl = null;
2290 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2293 TemplateParameter param = p.param;
2297 // ADD DATA TYPE HERE...
2298 p.param = param = TemplateParameter
2300 identifier = MkIdentifier(p.name), type = p.type,
2301 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2304 type = TemplatedType { key = (uintptr)p.name, param = param };
2305 curContext.templateTypes.Add((BTNode)type);
2313 public void FinishTemplatesContext(Context context)
2315 PopContext(context);
2316 FreeContext(context);
2320 public void ProcessMethodType(Method method)
2322 if(!method.dataType)
2324 Context context = SetupTemplatesContext(method._class);
2326 method.dataType = ProcessTypeString(method.dataTypeString, false);
2328 FinishTemplatesContext(context);
2330 if(method.type != virtualMethod && method.dataType)
2332 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2334 if(!method._class.symbol)
2335 method._class.symbol = FindClass(method._class.fullName);
2336 method.dataType.thisClass = method._class.symbol;
2340 // Why was this commented out? Working fine without now...
2343 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2344 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2351 char * par = strstr(type, "(");
2352 char * classOp = null;
2357 for(c = par-type-1; c >= 0; c++)
2359 if(type[c] == ':' && type[c+1] == ':')
2361 classOp = type + c - 1;
2362 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2369 else if(!isspace(type[c]))
2376 int typeLen = strlen(type);
2377 memcpy(temp, classOp, classOpLen);
2378 temp[classOpLen] = '\0';
2380 _class = eSystem_FindClass(module, temp);
2383 method.dataTypeString = new char[typeLen - classOpLen + 1];
2384 memcpy(method.dataTypeString, type, classOp - type);
2385 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2388 method.dataTypeString = type;
2394 public void ProcessPropertyType(Property prop)
2398 Context context = SetupTemplatesContext(prop._class);
2399 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2400 FinishTemplatesContext(context);
2404 public void DeclareMethod(Method method, char * name)
2406 Symbol symbol = method.symbol;
2407 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2409 bool imported = false;
2410 bool dllImport = false;
2412 if(!method.dataType)
2413 method.dataType = ProcessTypeString(method.dataTypeString, false);
2415 if(!symbol || symbol._import || method.type == virtualMethod)
2417 if(!symbol || method.type == virtualMethod)
2420 if(!method._class.symbol)
2421 method._class.symbol = FindClass(method._class.fullName);
2422 classSym = method._class.symbol;
2423 if(!classSym._import)
2425 ModuleImport module;
2427 if(method._class.module && method._class.module.name)
2428 module = FindModule(method._class.module);
2430 module = mainModule;
2431 classSym._import = ClassImport
2433 name = CopyString(method._class.fullName);
2434 isRemote = method._class.isRemote;
2436 module.classes.Add(classSym._import);
2440 symbol = method.symbol = Symbol { };
2444 symbol._import = (ClassImport)MethodImport
2446 name = CopyString(method.name);
2447 isVirtual = method.type == virtualMethod;
2449 classSym._import.methods.Add(symbol._import);
2453 // Set the symbol type
2457 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2459 else if(type.thisClass == (void *)-1)
2461 type.thisClass = null;
2464 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2465 symbol.type = method.dataType;
2466 if(symbol.type) symbol.type.refCount++;
2469 if(!method.thisClass || strcmp(method.thisClass, "void"))
2470 symbol.type.params.Insert(null,
2471 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2474 if(!method.dataType.dllExport)
2477 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2483 if(!method.dataType)
2484 method.dataType = ((Symbol)method.symbol).type;
2485 //ProcessMethodType(method);
2488 if(method.type != virtualMethod && method.dataType)
2489 DeclareType(method.dataType, true, true);
2491 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2493 // We need a declaration here :)
2495 OldList * specifiers, * declarators;
2497 Declarator funcDecl;
2500 specifiers = MkList();
2501 declarators = MkList();
2505 ListAdd(specifiers, MkSpecifier(EXTERN));
2506 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2507 ListAdd(specifiers, MkSpecifier(STATIC));
2509 if(method.type == virtualMethod)
2511 ListAdd(specifiers, MkSpecifier(INT));
2512 d = MkDeclaratorIdentifier(MkIdentifier(name));
2516 d = MkDeclaratorIdentifier(MkIdentifier(name));
2519 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2521 Context context = SetupTemplatesContext(method._class);
2522 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2523 FinishTemplatesContext(context);
2525 funcDecl = GetFuncDecl(d);
2529 Specifier spec, next;
2530 for(spec = specifiers->first; spec; spec = next)
2533 if(spec.type == extendedSpecifier)
2535 specifiers->Remove(spec);
2536 FreeSpecifier(spec);
2541 // Add this parameter if not a static method
2542 if(method.dataType && !method.dataType.staticMethod)
2544 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2546 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2547 TypeName thisParam = MkTypeName(MkListOne(
2548 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2549 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2550 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2551 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2553 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2555 TypeName param = funcDecl.function.parameters->first;
2556 funcDecl.function.parameters->Remove(param);
2557 FreeTypeName(param);
2560 if(!funcDecl.function.parameters)
2561 funcDecl.function.parameters = MkList();
2562 funcDecl.function.parameters->Insert(null, thisParam);
2565 // Make sure we don't have empty parameter declarations for static methods...
2567 else if(!funcDecl.function.parameters)
2569 funcDecl.function.parameters = MkList();
2570 funcDecl.function.parameters->Insert(null,
2571 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2575 ProcessDeclarator(d);
2577 ListAdd(declarators, MkInitDeclarator(d, null));
2579 decl = MkDeclaration(specifiers, declarators);
2581 ReplaceThisClassSpecifiers(specifiers, method._class);
2583 // Keep a different symbol for the function definition than the declaration...
2584 if(symbol.pointerExternal)
2586 Symbol functionSymbol { };
2590 *functionSymbol = *symbol;
2591 functionSymbol.string = CopyString(symbol.string);
2592 if(functionSymbol.type)
2593 functionSymbol.type.refCount++;
2596 excludedSymbols->Add(functionSymbol);
2597 symbol.pointerExternal.symbol = functionSymbol;
2599 external = MkExternalDeclaration(decl);
2601 ast->Insert(curExternal ? curExternal.prev : null, external);
2602 external.symbol = symbol;
2603 symbol.pointerExternal = external;
2607 // Move declaration higher...
2608 ast->Move(symbol.pointerExternal, curExternal.prev);
2611 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2615 char * ReplaceThisClass(Class _class)
2617 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2621 ClassTemplateParameter param;
2624 char className[1024];
2625 strcpy(className, _class.fullName);
2626 for(param = _class.templateParams.first; param; param = param.next)
2628 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2630 if(first) strcat(className, "<");
2631 if(!first) strcat(className, ", ");
2632 if(lastParam + 1 != p)
2634 strcat(className, param.name);
2635 strcat(className, " = ");
2637 strcat(className, param.name);
2645 int len = strlen(className);
2646 if(className[len-1] == '>') className[len++] = ' ';
2647 className[len++] = '>';
2648 className[len++] = '\0';
2650 return CopyString(className);
2653 return CopyString(_class.fullName);
2656 Type ReplaceThisClassType(Class _class)
2658 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2662 ClassTemplateParameter param;
2664 char className[1024];
2665 strcpy(className, _class.fullName);
2667 for(param = _class.templateParams.first; param; param = param.next)
2669 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2671 if(first) strcat(className, "<");
2672 if(!first) strcat(className, ", ");
2673 if(lastParam + 1 != p)
2675 strcat(className, param.name);
2676 strcat(className, " = ");
2678 strcat(className, param.name);
2686 int len = strlen(className);
2687 if(className[len-1] == '>') className[len++] = ' ';
2688 className[len++] = '>';
2689 className[len++] = '\0';
2691 return MkClassType(className);
2692 //return ProcessTypeString(className, false);
2696 return MkClassType(_class.fullName);
2697 //return ProcessTypeString(_class.fullName, false);
2701 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2703 if(specs != null && _class)
2706 for(spec = specs.first; spec; spec = spec.next)
2708 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2710 spec.type = nameSpecifier;
2711 spec.name = ReplaceThisClass(_class);
2712 spec.symbol = FindClass(spec.name); //_class.symbol;
2718 // Returns imported or not
2719 bool DeclareFunction(GlobalFunction function, char * name)
2721 Symbol symbol = function.symbol;
2722 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2724 bool imported = false;
2725 bool dllImport = false;
2727 if(!function.dataType)
2729 function.dataType = ProcessTypeString(function.dataTypeString, false);
2730 if(!function.dataType.thisClass)
2731 function.dataType.staticMethod = true;
2738 ModuleImport module = FindModule(function.module);
2739 // WARNING: This is not added anywhere...
2740 symbol = function.symbol = Symbol { };
2744 if(!function.dataType.dllExport)
2746 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2747 module.functions.Add(symbol._import);
2750 // Set the symbol type
2752 symbol.type = ProcessTypeString(function.dataTypeString, false);
2753 if(!symbol.type.thisClass)
2754 symbol.type.staticMethod = true;
2757 imported = symbol._import ? true : false;
2758 if(imported && function.module != privateModule && function.module.importType != staticImport)
2762 DeclareType(function.dataType, true, true);
2766 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2768 // We need a declaration here :)
2770 OldList * specifiers, * declarators;
2772 Declarator funcDecl;
2775 specifiers = MkList();
2776 declarators = MkList();
2779 ListAdd(specifiers, MkSpecifier(EXTERN));
2782 ListAdd(specifiers, MkSpecifier(STATIC));
2785 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2788 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2790 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2791 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2792 if(function.module.importType == staticImport)
2795 for(spec = specifiers->first; spec; spec = spec.next)
2796 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2798 specifiers->Remove(spec);
2799 FreeSpecifier(spec);
2804 funcDecl = GetFuncDecl(d);
2806 // Make sure we don't have empty parameter declarations for static methods...
2807 if(funcDecl && !funcDecl.function.parameters)
2809 funcDecl.function.parameters = MkList();
2810 funcDecl.function.parameters->Insert(null,
2811 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2814 ListAdd(declarators, MkInitDeclarator(d, null));
2817 Context oldCtx = curContext;
2818 curContext = globalContext;
2819 decl = MkDeclaration(specifiers, declarators);
2820 curContext = oldCtx;
2823 // Keep a different symbol for the function definition than the declaration...
2824 if(symbol.pointerExternal)
2826 Symbol functionSymbol { };
2829 *functionSymbol = *symbol;
2830 functionSymbol.string = CopyString(symbol.string);
2831 if(functionSymbol.type)
2832 functionSymbol.type.refCount++;
2835 excludedSymbols->Add(functionSymbol);
2837 symbol.pointerExternal.symbol = functionSymbol;
2839 external = MkExternalDeclaration(decl);
2841 ast->Insert(curExternal.prev, external);
2842 external.symbol = symbol;
2843 symbol.pointerExternal = external;
2847 // Move declaration higher...
2848 ast->Move(symbol.pointerExternal, curExternal.prev);
2852 symbol.id = curExternal.symbol.idCode;
2855 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2858 void DeclareGlobalData(GlobalData data)
2860 Symbol symbol = data.symbol;
2861 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2866 symbol = data.symbol = Symbol { };
2869 data.dataType = ProcessTypeString(data.dataTypeString, false);
2870 DeclareType(data.dataType, true, true);
2873 if(!symbol.pointerExternal)
2875 // We need a declaration here :)
2877 OldList * specifiers, * declarators;
2881 specifiers = MkList();
2882 declarators = MkList();
2884 ListAdd(specifiers, MkSpecifier(EXTERN));
2885 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2886 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2888 ListAdd(declarators, MkInitDeclarator(d, null));
2890 decl = MkDeclaration(specifiers, declarators);
2891 external = MkExternalDeclaration(decl);
2893 ast->Insert(curExternal.prev, external);
2894 external.symbol = symbol;
2895 symbol.pointerExternal = external;
2899 // Move declaration higher...
2900 ast->Move(symbol.pointerExternal, curExternal.prev);
2904 symbol.id = curExternal.symbol.idCode;
2909 class Conversion : struct
2911 Conversion prev, next;
2917 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2921 // Property convert;
2923 if(source.kind == templateType && dest.kind != templateType)
2925 Type type = ProcessTemplateParameterType(source.templateParameter);
2926 if(type) source = type;
2929 if(dest.kind == templateType && source.kind != templateType)
2931 Type type = ProcessTemplateParameterType(dest.templateParameter);
2932 if(type) dest = type;
2935 if(dest.classObjectType == typedObject)
2937 if(source.classObjectType != anyObject)
2941 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2942 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2950 if(source.classObjectType == anyObject)
2952 if(dest.classObjectType == anyObject && source.classObjectType != typedObject)
2956 if((dest.kind == structType && source.kind == structType) ||
2957 (dest.kind == unionType && source.kind == unionType))
2959 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2960 (source.members.first && source.members.first == dest.members.first))
2964 if(dest.kind == ellipsisType && source.kind != voidType)
2967 if(dest.kind == pointerType && dest.type.kind == voidType &&
2968 ((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))
2969 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2971 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2973 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2975 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2976 ((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))
2977 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2979 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2981 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2984 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2986 if(source._class.registered && source._class.registered.type == unitClass)
2988 if(conversions != null)
2990 if(source._class.registered == dest._class.registered)
2995 Class sourceBase, destBase;
2996 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2997 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2998 if(sourceBase == destBase)
3002 // Don't match enum inheriting from other enum if resolving enumeration values
3003 // TESTING: !dest.classObjectType
3004 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
3006 (!source._class.registered || source._class.registered.type != enumClass) ||
3007 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
3011 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
3013 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
3014 ((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)
3016 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3024 // JUST ADDED THIS...
3025 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3030 // Just added this for Straight conversion of ColorAlpha => Color
3031 if(source.kind == classType)
3034 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3037 for(convert = _class.conversions.first; convert; convert = convert.next)
3039 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3041 Conversion after = (conversions != null) ? conversions.last : null;
3043 if(!convert.dataType)
3044 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3045 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3046 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3047 MatchTypes(convert.dataType, dest, conversions, null, null,
3048 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3049 convert.dataType.kind == classType, false, true))
3051 if(!conversions && !convert.Get)
3053 else if(conversions != null)
3055 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3056 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3057 (dest.kind != classType || dest._class.registered != _class.base))
3061 Conversion conv { convert = convert, isGet = true };
3062 // conversions.Add(conv);
3063 conversions.Insert(after, conv);
3075 if(dest.kind == classType)
3078 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3081 for(convert = _class.conversions.first; convert; convert = convert.next)
3083 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3085 // Conversion after = (conversions != null) ? conversions.last : null;
3087 if(!convert.dataType)
3088 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3089 // Just added this equality check to prevent recursion.... Make it safer?
3090 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3091 if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
3093 if(!conversions && !convert.Set)
3095 else if(conversions != null)
3097 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3098 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3099 (source.kind != classType || source._class.registered != _class.base))
3103 // *** Testing this! ***
3104 Conversion conv { convert = convert };
3105 conversions.Add(conv);
3106 //conversions.Insert(after, conv);
3114 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3116 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3117 (source.kind != classType || source._class.registered.type != structClass))
3121 // TESTING THIS... IS THIS OK??
3122 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3124 if(!dest._class.registered.dataType)
3125 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3126 // Only support this for classes...
3127 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3128 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3130 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false))
3139 if(source.kind == classType)
3142 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3145 for(convert = _class.conversions.first; convert; convert = convert.next)
3147 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3149 Conversion after = (conversions != null) ? conversions.last : null;
3151 if(!convert.dataType)
3152 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3153 if(convert.dataType != source &&
3154 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3155 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true))
3157 if(!conversions && !convert.Get)
3159 else if(conversions != null)
3161 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3162 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3163 (dest.kind != classType || dest._class.registered != _class.base))
3167 Conversion conv { convert = convert, isGet = true };
3169 // conversions.Add(conv);
3170 conversions.Insert(after, conv);
3179 // TESTING THIS... IS THIS OK??
3180 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3182 if(!source._class.registered.dataType)
3183 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3184 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3186 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, source._class.registered.dataType.kind == classType, source._class.registered.dataType.kind == classType, false, false))
3188 // For bool to be accepted by byte, short, etc.
3189 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false))
3196 if(source.kind == classType || source.kind == subClassType)
3198 else if(dest.kind == source.kind &&
3199 (dest.kind != structType && dest.kind != unionType &&
3200 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3202 // RECENTLY ADDED THESE
3203 else if(dest.kind == doubleType && source.kind == floatType)
3205 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3207 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3209 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3211 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3213 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3215 else if(source.kind == enumType &&
3216 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3218 else if(dest.kind == enumType && !isConversionExploration &&
3219 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3221 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3222 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3224 Type paramSource, paramDest;
3226 if(dest.kind == methodType)
3227 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3228 if(source.kind == methodType)
3229 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3231 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3232 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3233 if(dest.kind == methodType)
3234 dest = dest.method.dataType;
3235 if(source.kind == methodType)
3236 source = source.method.dataType;
3238 paramSource = source.params.first;
3239 if(paramSource && paramSource.kind == voidType) paramSource = null;
3240 paramDest = dest.params.first;
3241 if(paramDest && paramDest.kind == voidType) paramDest = null;
3244 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3245 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3247 // Source thisClass must be derived from destination thisClass
3248 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3249 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3251 if(paramDest && paramDest.kind == classType)
3252 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3254 Compiler_Error($"method class should not take an object\n");
3257 paramDest = paramDest.next;
3259 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3261 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3265 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3267 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3273 // THIS WAS BACKWARDS:
3274 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3275 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3278 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3280 Compiler_Error($"overriding class expected to be derived from method class\n");
3284 paramSource = paramSource.next;
3290 // Source thisClass must be derived from destination thisClass
3291 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3293 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3299 // THIS WAS BACKWARDS TOO??
3300 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3301 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3304 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3306 //Compiler_Error($"overriding class expected to be derived from method class\n");
3314 // Source return type must be derived from destination return type
3315 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3317 Compiler_Warning($"incompatible return type for function\n");
3323 for(; paramDest; paramDest = paramDest.next)
3327 //Compiler_Warning($"not enough parameters\n");
3328 Compiler_Error($"not enough parameters\n");
3332 Type paramDestType = paramDest;
3333 Type paramSourceType = paramSource;
3334 Type type = paramDestType;
3336 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3337 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3338 paramSource.kind != templateType)
3341 ClassTemplateParameter curParam = null;
3343 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3346 if(sClass.templateClass) sClass = sClass.templateClass;
3347 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3349 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3351 for(sClass = sClass.base; sClass; sClass = sClass.base)
3353 if(sClass.templateClass) sClass = sClass.templateClass;
3354 id += sClass.templateParams.count;
3365 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3366 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3370 // paramDest must be derived from paramSource
3371 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3372 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3376 PrintType(paramDest, type, false, true);
3377 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3379 if(paramDestType != paramDest)
3380 FreeType(paramDestType);
3383 if(paramDestType != paramDest)
3384 FreeType(paramDestType);
3387 paramSource = paramSource.next;
3391 Compiler_Error($"too many parameters\n");
3396 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3400 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3401 (source.kind == arrayType || source.kind == pointerType))
3403 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3410 static void FreeConvert(Conversion convert)
3412 if(convert.resultType)
3413 FreeType(convert.resultType);
3416 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3417 char * string, OldList conversions)
3421 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3423 Class _class = link.data;
3424 if(_class.type == enumClass)
3426 OldList converts { };
3428 type.kind = classType;
3431 _class.symbol = FindClass(_class.fullName);
3432 type._class = _class.symbol;
3434 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3437 Class enumClass = eSystem_FindClass(privateModule, "enum");
3441 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3443 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3444 for(value = e.values.first; value; value = value.next)
3446 if(!strcmp(value.name, string))
3451 FreeExpContents(sourceExp);
3452 FreeType(sourceExp.expType);
3454 sourceExp.isConstant = true;
3455 sourceExp.expType = MkClassType(baseClass.fullName);
3459 sourceExp.type = constantExp;
3460 if(!strcmp(baseClass.dataTypeString, "int"))
3461 sprintf(constant, "%d",(int)value.data);
3463 sprintf(constant, "0x%X",(int)value.data);
3464 sourceExp.constant = CopyString(constant);
3465 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3468 while(converts.first)
3470 Conversion convert = converts.first;
3471 converts.Remove(convert);
3472 conversions.Add(convert);
3481 converts.Free(FreeConvert);
3485 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3486 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3491 public bool ModuleVisibility(Module searchIn, Module searchFor)
3493 SubModule subModule;
3495 if(searchFor == searchIn)
3498 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3500 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3502 if(ModuleVisibility(subModule.module, searchFor))
3509 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3513 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3515 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3517 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3520 for(module = mainModule.application.allModules.first; module; module = module.next)
3522 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3528 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3531 Type realDest = dest;
3532 Type backupSourceExpType = null;
3533 Expression computedExp = sourceExp;
3536 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3537 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3539 computedExp = CopyExpression(sourceExp); // Keep the original expression, but compute for checking enum ranges
3540 ComputeExpression(computedExp /*sourceExp*/);
3543 source = sourceExp.expType;
3545 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3547 if(computedExp != sourceExp)
3549 FreeExpression(computedExp);
3550 computedExp = sourceExp;
3556 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3558 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3560 Class sourceBase, destBase;
3561 for(sourceBase = source._class.registered;
3562 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3563 sourceBase = sourceBase.base);
3564 for(destBase = dest._class.registered;
3565 destBase && destBase.base && destBase.base.type != systemClass;
3566 destBase = destBase.base);
3567 //if(source._class.registered == dest._class.registered)
3568 if(sourceBase == destBase)
3570 if(computedExp != sourceExp)
3572 FreeExpression(computedExp);
3573 computedExp = sourceExp;
3585 int64 value = MAXINT;
3589 if(computedExp.type == constantExp)
3592 value = strtoll(computedExp.constant, null, 0);
3594 value = strtoull(computedExp.constant, null, 0);
3596 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3599 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3601 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3603 if(computedExp != sourceExp)
3605 FreeExpression(computedExp);
3606 computedExp = sourceExp;
3609 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3610 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3613 source = Type { kind = intType, isSigned = false, refCount = 1 };
3616 if(dest.kind == classType)
3618 Class _class = dest._class ? dest._class.registered : null;
3620 if(_class && _class.type == unitClass)
3622 if(source.kind != classType)
3625 Type tempDest, tempSource;
3627 for(; _class.base.type != systemClass; _class = _class.base);
3629 tempDest = tempType;
3631 tempType.kind = classType;
3633 _class.symbol = FindClass(_class.fullName);
3635 tempType._class = _class.symbol;
3636 tempType.truth = dest.truth;
3638 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3640 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3641 backupSourceExpType = sourceExp.expType;
3642 sourceExp.expType = dest; dest.refCount++;
3643 //sourceExp.expType = MkClassType(_class.fullName);
3651 // Why wasn't there something like this?
3652 if(_class && _class.type == bitClass && source.kind != classType)
3654 if(!dest._class.registered.dataType)
3655 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3656 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3659 FreeType(sourceExp.expType);
3660 source = sourceExp.expType = MkClassType(dest._class.string);
3663 //source.kind = classType;
3664 //source._class = dest._class;
3668 // Adding two enumerations
3670 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3672 if(!source._class.registered.dataType)
3673 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3674 if(!dest._class.registered.dataType)
3675 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3677 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3680 source = sourceExp.expType = MkClassType(dest._class.string);
3683 //source.kind = classType;
3684 //source._class = dest._class;
3688 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3690 OldList * specs = MkList();
3694 ReadString(string, sourceExp.string);
3695 decl = SpecDeclFromString(string, specs, null);
3697 FreeExpContents(sourceExp);
3698 FreeType(sourceExp.expType);
3700 sourceExp.type = classExp;
3701 sourceExp._classExp.specifiers = specs;
3702 sourceExp._classExp.decl = decl;
3703 sourceExp.expType = dest;
3708 if(backupSourceExpType) FreeType(backupSourceExpType);
3712 else if(source.kind == classType)
3714 Class _class = source._class ? source._class.registered : null;
3716 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3719 if(dest.kind != classType)
3721 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3722 if(!source._class.registered.dataType)
3723 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3726 dest = MkClassType(source._class.string);
3727 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3728 // dest = MkClassType(source._class.string);
3732 if(dest.kind != classType)
3735 Type tempDest, tempSource;
3737 if(!source._class.registered.dataType)
3738 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3740 for(; _class.base.type != systemClass; _class = _class.base);
3742 tempSource = tempType;
3743 tempType.kind = classType;
3744 tempType._class = FindClass(_class.fullName);
3745 tempType.truth = source.truth;
3746 tempType.classObjectType = source.classObjectType;
3749 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3751 // PUT THIS BACK TESTING UNITS?
3752 if(conversions.last)
3754 ((Conversion)(conversions.last)).resultType = dest;
3758 FreeType(sourceExp.expType);
3759 sourceExp.expType = MkClassType(_class.fullName);
3760 sourceExp.expType.truth = source.truth;
3761 sourceExp.expType.classObjectType = source.classObjectType;
3763 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3765 if(!sourceExp.destType)
3767 FreeType(sourceExp.destType);
3768 sourceExp.destType = sourceExp.expType;
3769 if(sourceExp.expType)
3770 sourceExp.expType.refCount++;
3773 //source = _class.dataType;
3776 // TOCHECK: TESTING THIS NEW CODE
3777 if(!_class.dataType)
3778 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3780 dest = MkClassType(source._class.string);
3781 dest.truth = source.truth;
3782 dest.classObjectType = source.classObjectType;
3785 source = _class.dataType;
3795 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3805 if(source.kind == classType)
3807 Class _class = source._class.registered;
3808 if(_class.type == unitClass)
3810 if(!_class.dataType)
3811 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3812 source = _class.dataType;
3816 if(dest.kind == classType)
3818 Class _class = dest._class ? dest._class.registered : null;
3819 bool fittingValue = false;
3820 if(_class && _class.type == enumClass)
3822 Class enumClass = eSystem_FindClass(privateModule, "enum");
3823 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3824 if(c && value >= 0 && value <= c.largest)
3825 fittingValue = true;
3828 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3829 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3831 if(_class.type == normalClass || _class.type == noHeadClass)
3833 Expression newExp { };
3834 *newExp = *sourceExp;
3835 if(sourceExp.destType) sourceExp.destType.refCount++;
3836 if(sourceExp.expType) sourceExp.expType.refCount++;
3837 sourceExp.type = castExp;
3838 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3839 sourceExp.cast.exp = newExp;
3840 FreeType(sourceExp.expType);
3841 sourceExp.expType = null;
3842 ProcessExpressionType(sourceExp);
3844 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3847 FreeType(sourceExp.expType);
3848 sourceExp.expType = dest;
3852 if(inCompiler) FreeType(dest);
3854 if(backupSourceExpType) FreeType(backupSourceExpType);
3858 if(!_class.dataType)
3859 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3861 dest = _class.dataType;
3865 // Accept lower precision types for units, since we want to keep the unit type
3866 if(dest.kind == doubleType &&
3867 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3868 source.kind == charType || source.kind == _BoolType))
3870 specs = MkListOne(MkSpecifier(DOUBLE));
3872 else if(dest.kind == floatType &&
3873 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3874 source.kind == _BoolType || source.kind == doubleType))
3876 specs = MkListOne(MkSpecifier(FLOAT));
3878 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3879 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3882 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3883 ListAdd(specs, MkSpecifier(INT64));
3885 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3886 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3889 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3890 ListAdd(specs, MkSpecifier(INT));
3892 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3893 source.kind == floatType || source.kind == doubleType))
3896 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3897 ListAdd(specs, MkSpecifier(SHORT));
3899 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3900 source.kind == floatType || source.kind == doubleType))
3903 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3904 ListAdd(specs, MkSpecifier(CHAR));
3910 if(backupSourceExpType)
3912 // Failed to convert: revert previous exp type
3913 if(sourceExp.expType) FreeType(sourceExp.expType);
3914 sourceExp.expType = backupSourceExpType;
3919 else if(dest.kind == doubleType &&
3920 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3921 source.kind == _BoolType || source.kind == charType))
3923 specs = MkListOne(MkSpecifier(DOUBLE));
3925 else if(dest.kind == floatType &&
3926 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3928 specs = MkListOne(MkSpecifier(FLOAT));
3930 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3931 (value == 1 || value == 0))
3934 ListAdd(specs, MkSpecifier(BOOL));
3936 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3937 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3940 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3941 ListAdd(specs, MkSpecifier(CHAR));
3943 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3944 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3947 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3948 ListAdd(specs, MkSpecifier(SHORT));
3950 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3953 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3954 ListAdd(specs, MkSpecifier(INT));
3956 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3959 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3960 ListAdd(specs, MkSpecifier(INT64));
3962 else if(dest.kind == enumType &&
3963 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3965 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3971 if(backupSourceExpType)
3973 // Failed to convert: revert previous exp type
3974 if(sourceExp.expType) FreeType(sourceExp.expType);
3975 sourceExp.expType = backupSourceExpType;
3980 if(!flag && !sourceExp.opDestType)
3982 Expression newExp { };
3983 *newExp = *sourceExp;
3986 if(sourceExp.destType) sourceExp.destType.refCount++;
3987 if(sourceExp.expType) sourceExp.expType.refCount++;
3989 sourceExp.type = castExp;
3990 if(realDest.kind == classType)
3992 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3993 FreeList(specs, FreeSpecifier);
3996 sourceExp.cast.typeName = MkTypeName(specs, null);
3997 if(newExp.type == opExp)
3999 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4002 sourceExp.cast.exp = newExp;
4004 FreeType(sourceExp.expType);
4005 sourceExp.expType = null;
4006 ProcessExpressionType(sourceExp);
4009 FreeList(specs, FreeSpecifier);
4013 if(backupSourceExpType) FreeType(backupSourceExpType);
4019 if(computedExp != sourceExp)
4021 FreeExpression(computedExp);
4022 computedExp = sourceExp;
4025 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4026 if(sourceExp.type == identifierExp)
4028 Identifier id = sourceExp.identifier;
4029 if(dest.kind == classType)
4031 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4033 Class _class = dest._class.registered;
4034 Class enumClass = eSystem_FindClass(privateModule, "enum");
4037 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4040 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4041 for(value = e.values.first; value; value = value.next)
4043 if(!strcmp(value.name, id.string))
4048 FreeExpContents(sourceExp);
4049 FreeType(sourceExp.expType);
4051 sourceExp.isConstant = true;
4052 sourceExp.expType = MkClassType(_class.fullName);
4056 sourceExp.type = constantExp;
4057 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
4058 sprintf(constant, "%d", (int) value.data);
4060 sprintf(constant, "0x%X", (int) value.data);
4061 sourceExp.constant = CopyString(constant);
4062 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4072 // Loop through all enum classes
4073 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4084 #define TERTIARY(o, name, m, t, p) \
4085 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4087 exp.type = constantExp; \
4088 exp.string = p(op1.m ? op2.m : op3.m); \
4090 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4094 #define BINARY(o, name, m, t, p) \
4095 static bool name(Expression exp, Operand op1, Operand op2) \
4098 exp.type = constantExp; \
4099 exp.string = p((t)(op1.m o value2)); \
4101 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4105 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4106 static bool name(Expression exp, Operand op1, Operand op2) \
4109 exp.type = constantExp; \
4110 exp.string = p(value2 ? (op1.m o value2) : 0); \
4112 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4116 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4117 static bool name(Expression exp, Operand op1, Operand op2) \
4120 exp.type = constantExp; \
4121 exp.string = p(op1.m o value2); \
4123 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4127 #define UNARY(o, name, m, t, p) \
4128 static bool name(Expression exp, Operand op1) \
4130 exp.type = constantExp; \
4131 exp.string = p((t)(o op1.m)); \
4133 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4137 #define OPERATOR_ALL(macro, o, name) \
4138 macro(o, Int##name, i, int, PrintInt) \
4139 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4140 macro(o, Int64##name, i64, int64, PrintInt64) \
4141 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4142 macro(o, Short##name, s, short, PrintShort) \
4143 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4144 macro(o, Char##name, c, char, PrintChar) \
4145 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4146 macro(o, Float##name, f, float, PrintFloat) \
4147 macro(o, Double##name, d, double, PrintDouble)
4149 #define OPERATOR_INTTYPES(macro, o, name) \
4150 macro(o, Int##name, i, int, PrintInt) \
4151 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4152 macro(o, Int64##name, i64, int64, PrintInt64) \
4153 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4154 macro(o, Short##name, s, short, PrintShort) \
4155 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4156 macro(o, Char##name, c, char, PrintChar) \
4157 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4159 #define OPERATOR_REALTYPES(macro, o, name) \
4160 macro(o, Float##name, f, float, PrintFloat) \
4161 macro(o, Double##name, d, double, PrintDouble)
4163 // binary arithmetic
4164 OPERATOR_ALL(BINARY, +, Add)
4165 OPERATOR_ALL(BINARY, -, Sub)
4166 OPERATOR_ALL(BINARY, *, Mul)
4167 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4168 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4169 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4172 OPERATOR_ALL(UNARY, -, Neg)
4174 // unary arithmetic increment and decrement
4175 OPERATOR_ALL(UNARY, ++, Inc)
4176 OPERATOR_ALL(UNARY, --, Dec)
4178 // binary arithmetic assignment
4179 OPERATOR_ALL(BINARY, =, Asign)
4180 OPERATOR_ALL(BINARY, +=, AddAsign)
4181 OPERATOR_ALL(BINARY, -=, SubAsign)
4182 OPERATOR_ALL(BINARY, *=, MulAsign)
4183 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4184 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4185 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4188 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4189 OPERATOR_INTTYPES(BINARY, |, BitOr)
4190 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4191 OPERATOR_INTTYPES(BINARY, <<, LShift)
4192 OPERATOR_INTTYPES(BINARY, >>, RShift)
4195 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4197 // binary bitwise assignment
4198 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4199 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4200 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4201 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4202 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4204 // unary logical negation
4205 OPERATOR_INTTYPES(UNARY, !, Not)
4207 // binary logical equality
4208 OPERATOR_ALL(BINARY, ==, Equ)
4209 OPERATOR_ALL(BINARY, !=, Nqu)
4212 OPERATOR_ALL(BINARY, &&, And)
4213 OPERATOR_ALL(BINARY, ||, Or)
4215 // binary logical relational
4216 OPERATOR_ALL(BINARY, >, Grt)
4217 OPERATOR_ALL(BINARY, <, Sma)
4218 OPERATOR_ALL(BINARY, >=, GrtEqu)
4219 OPERATOR_ALL(BINARY, <=, SmaEqu)
4221 // tertiary condition operator
4222 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4224 //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
4225 #define OPERATOR_TABLE_ALL(name, type) \
4226 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4228 type##Inc, type##Dec, \
4229 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4230 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4232 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4234 type##Equ, type##Nqu, \
4235 type##And, type##Or, \
4236 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4239 #define OPERATOR_TABLE_INTTYPES(name, type) \
4240 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4242 type##Inc, type##Dec, \
4243 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4244 null, null, null, null, null, \
4246 null, null, null, null, null, \
4248 type##Equ, type##Nqu, \
4249 type##And, type##Or, \
4250 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4253 OPERATOR_TABLE_ALL(int, Int)
4254 OPERATOR_TABLE_ALL(uint, UInt)
4255 OPERATOR_TABLE_ALL(int64, Int64)
4256 OPERATOR_TABLE_ALL(uint64, UInt64)
4257 OPERATOR_TABLE_ALL(short, Short)
4258 OPERATOR_TABLE_ALL(ushort, UShort)
4259 OPERATOR_TABLE_INTTYPES(float, Float)
4260 OPERATOR_TABLE_INTTYPES(double, Double)
4261 OPERATOR_TABLE_ALL(char, Char)
4262 OPERATOR_TABLE_ALL(uchar, UChar)
4264 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4265 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4266 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4267 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4268 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4269 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4270 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4271 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4273 public void ReadString(char * output, char * string)
4275 int len = strlen(string);
4277 bool quoted = false, escaped = false;
4278 for(c = 0; c<len; c++)
4280 char ch = string[c];
4285 case 'n': output[d] = '\n'; break;
4286 case 't': output[d] = '\t'; break;
4287 case 'a': output[d] = '\a'; break;
4288 case 'b': output[d] = '\b'; break;
4289 case 'f': output[d] = '\f'; break;
4290 case 'r': output[d] = '\r'; break;
4291 case 'v': output[d] = '\v'; break;
4292 case '\\': output[d] = '\\'; break;
4293 case '\"': output[d] = '\"'; break;
4294 case '\'': output[d] = '\''; break;
4295 default: output[d] = ch;
4316 // String Unescape Copy
4318 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4319 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4320 public int UnescapeString(char * d, char * s, int len)
4324 while(j < len && (ch = s[j]))
4329 switch((ch = s[++j]))
4331 case 'n': d[k] = '\n'; break;
4332 case 't': d[k] = '\t'; break;
4333 case 'a': d[k] = '\a'; break;
4334 case 'b': d[k] = '\b'; break;
4335 case 'f': d[k] = '\f'; break;
4336 case 'r': d[k] = '\r'; break;
4337 case 'v': d[k] = '\v'; break;
4338 case '\\': d[k] = '\\'; break;
4339 case '\"': d[k] = '\"'; break;
4340 case '\'': d[k] = '\''; break;
4341 default: d[k] = '\\'; d[k] = ch;
4353 public char * OffsetEscapedString(char * s, int len, int offset)
4357 while(j < len && k < offset && (ch = s[j]))
4362 return (k == offset) ? s + j : null;
4365 public Operand GetOperand(Expression exp)
4368 Type type = exp.expType;
4371 while(type.kind == classType &&
4372 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4374 if(!type._class.registered.dataType)
4375 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4376 type = type._class.registered.dataType;
4379 if(exp.type == stringExp && op.kind == pointerType)
4381 op.ui64 = (uint64)exp.string;
4382 op.kind = pointerType;
4385 else if(exp.isConstant && exp.type == constantExp)
4387 op.kind = type.kind;
4388 op.type = exp.expType;
4395 if(exp.constant[0] == '\'')
4397 op.c = exp.constant[1];
4400 else if(type.isSigned)
4402 op.c = (char)strtol(exp.constant, null, 0);
4407 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4415 op.s = (short)strtol(exp.constant, null, 0);
4420 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4428 op.i = (int)strtol(exp.constant, null, 0);
4433 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4441 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4446 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4449 op.kind = int64Type;
4454 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4459 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4462 op.kind = int64Type;
4467 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4472 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4475 op.kind = int64Type;
4478 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4479 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4480 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4481 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4483 op.f = (float)strtod(exp.constant, null);
4487 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4488 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4489 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4490 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4492 op.d = (double)strtod(exp.constant, null);
4495 //case classType: For when we have operator overloading...
4496 // Pointer additions
4497 //case functionType:
4501 op.ui64 = _strtoui64(exp.constant, null, 0);
4502 op.kind = pointerType;
4512 static __attribute__((unused)) void UnusedFunction()
4515 a.OnGetString(0,0,0);
4518 extern int __ecereVMethodID_class_OnGetString;
4521 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4523 DataMember dataMember;
4524 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4526 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4527 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4531 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4533 void * ptr = inst.data + dataMember.offset + offset;
4534 char * result = null;
4535 exp.loc = member.loc = inst.loc;
4536 ((Identifier)member.identifiers->first).loc = inst.loc;
4538 if(!dataMember.dataType)
4539 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4540 type = dataMember.dataType;
4541 if(type.kind == classType)
4543 Class _class = type._class.registered;
4544 if(_class.type == enumClass)
4546 Class enumClass = eSystem_FindClass(privateModule, "enum");
4549 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4551 for(item = e.values.first; item; item = item.next)
4553 if((int)item.data == *(int *)ptr)
4561 exp.identifier = MkIdentifier(result);
4562 exp.type = identifierExp;
4563 exp.destType = MkClassType(_class.fullName);
4564 ProcessExpressionType(exp);
4568 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4570 if(!_class.dataType)
4571 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4572 type = _class.dataType;
4581 FreeExpContents(exp);
4583 exp.constant = PrintFloat(*(float*)ptr);
4584 exp.type = constantExp;
4589 FreeExpContents(exp);
4591 exp.constant = PrintDouble(*(double*)ptr);
4592 exp.type = constantExp;
4597 FreeExpContents(exp);
4599 exp.constant = PrintInt(*(int*)ptr);
4600 exp.type = constantExp;
4605 FreeExpContents(exp);
4607 exp.constant = PrintInt64(*(int64*)ptr);
4608 exp.type = constantExp;
4613 FreeExpContents(exp);
4614 // TODO: This should probably use proper type
4615 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4616 exp.type = constantExp;
4621 FreeExpContents(exp);
4622 // TODO: This should probably use proper type
4623 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4624 exp.type = constantExp;
4628 Compiler_Error($"Unhandled type populating instance\n");
4631 ListAdd(memberList, member);
4634 if(parentDataMember.type == unionMember)
4639 void PopulateInstance(Instantiation inst)
4641 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4642 Class _class = classSym.registered;
4643 DataMember dataMember;
4644 OldList * memberList = MkList();
4645 // Added this check and ->Add to prevent memory leaks on bad code
4647 inst.members = MkListOne(MkMembersInitList(memberList));
4649 inst.members->Add(MkMembersInitList(memberList));
4650 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4652 if(!dataMember.isProperty)
4654 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4655 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4659 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4661 void * ptr = inst.data + dataMember.offset;
4662 char * result = null;
4664 exp.loc = member.loc = inst.loc;
4665 ((Identifier)member.identifiers->first).loc = inst.loc;
4667 if(!dataMember.dataType)
4668 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4669 type = dataMember.dataType;
4670 if(type.kind == classType)
4672 Class _class = type._class.registered;
4673 if(_class.type == enumClass)
4675 Class enumClass = eSystem_FindClass(privateModule, "enum");
4678 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4680 for(item = e.values.first; item; item = item.next)
4682 if((int)item.data == *(int *)ptr)
4691 exp.identifier = MkIdentifier(result);
4692 exp.type = identifierExp;
4693 exp.destType = MkClassType(_class.fullName);
4694 ProcessExpressionType(exp);
4697 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4699 if(!_class.dataType)
4700 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4701 type = _class.dataType;
4710 exp.constant = PrintFloat(*(float*)ptr);
4711 exp.type = constantExp;
4716 exp.constant = PrintDouble(*(double*)ptr);
4717 exp.type = constantExp;
4722 exp.constant = PrintInt(*(int*)ptr);
4723 exp.type = constantExp;
4728 exp.constant = PrintInt64(*(int64*)ptr);
4729 exp.type = constantExp;
4734 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4735 exp.type = constantExp;
4739 Compiler_Error($"Unhandled type populating instance\n");
4742 ListAdd(memberList, member);
4748 void ComputeInstantiation(Expression exp)
4750 Instantiation inst = exp.instance;
4751 MembersInit members;
4752 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4753 Class _class = classSym ? classSym.registered : null;
4754 DataMember curMember = null;
4755 Class curClass = null;
4756 DataMember subMemberStack[256];
4757 int subMemberStackPos = 0;
4760 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4762 // Don't recompute the instantiation...
4763 // Non Simple classes will have become constants by now
4767 if(_class.type == normalClass || _class.type == noHeadClass)
4769 inst.data = (byte *)eInstance_New(_class);
4770 if(_class.type == normalClass)
4771 ((Instance)inst.data)._refCount++;
4774 inst.data = new0 byte[_class.structSize];
4779 for(members = inst.members->first; members; members = members.next)
4781 switch(members.type)
4783 case dataMembersInit:
4785 if(members.dataMembers)
4788 for(member = members.dataMembers->first; member; member = member.next)
4790 Identifier ident = member.identifiers ? member.identifiers->first : null;
4793 Property prop = null;
4794 DataMember dataMember = null;
4795 Method method = null;
4796 uint dataMemberOffset;
4800 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4803 if(curMember.isProperty)
4804 prop = (Property)curMember;
4807 dataMember = curMember;
4809 // CHANGED THIS HERE
4810 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4812 // 2013/17/29 -- It seems that this was missing here!
4813 if(_class.type == normalClass)
4814 dataMemberOffset += _class.base.structSize;
4815 // dataMemberOffset = dataMember.offset;
4822 prop = eClass_FindProperty(_class, ident.string, privateModule);
4826 if(prop.memberAccess == publicAccess)
4828 curMember = (DataMember)prop;
4829 curClass = prop._class;
4834 DataMember _subMemberStack[256];
4835 int _subMemberStackPos = 0;
4837 // FILL MEMBER STACK
4838 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4843 if(dataMember.memberAccess == publicAccess)
4845 curMember = dataMember;
4846 curClass = dataMember._class;
4847 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4848 subMemberStackPos = _subMemberStackPos;
4854 if(found && member.initializer && member.initializer.type == expInitializer)
4856 Expression value = member.initializer.exp;
4858 bool deepMember = false;
4861 type = prop.dataType;
4865 if(!dataMember.dataType)
4866 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4868 type = dataMember.dataType;
4871 if(ident && ident.next)
4875 // for(; ident && type; ident = ident.next)
4876 for(ident = ident.next; ident && type; ident = ident.next)
4878 if(type.kind == classType)
4880 prop = eClass_FindProperty(type._class.registered,
4881 ident.string, privateModule);
4883 type = prop.dataType;
4886 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4887 ident.string, &dataMemberOffset, privateModule, null, null);
4889 type = dataMember.dataType;
4892 else if(type.kind == structType || type.kind == unionType)
4895 for(memberType = type.members.first; memberType; memberType = memberType.next)
4897 if(!strcmp(memberType.name, ident.string))
4908 FreeType(value.destType);
4909 value.destType = type;
4910 if(type) type.refCount++;
4911 ComputeExpression(value);
4913 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4915 if(type.kind == classType)
4917 Class _class = type._class.registered;
4918 if(_class.type == bitClass || _class.type == unitClass ||
4919 _class.type == enumClass)
4921 if(!_class.dataType)
4922 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4923 type = _class.dataType;
4929 void * ptr = inst.data + dataMemberOffset;
4931 if(value.type == constantExp)
4937 GetInt(value, (int*)ptr);
4942 GetInt64(value, (int64*)ptr);
4947 GetIntPtr(value, (intptr*)ptr);
4952 GetIntSize(value, (intsize*)ptr);
4957 GetFloat(value, (float*)ptr);
4962 GetDouble(value, (double *)ptr);
4967 else if(value.type == instanceExp)
4969 if(type.kind == classType)
4971 Class _class = type._class.registered;
4972 if(_class.type == structClass)
4974 ComputeTypeSize(type);
4975 if(value.instance.data)
4976 memcpy(ptr, value.instance.data, type.size);
4983 if(value.type == instanceExp && value.instance.data)
4985 if(type.kind == classType)
4987 Class _class = type._class.registered;
4988 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
4990 void (*Set)(void *, void *) = (void *)prop.Set;
4991 Set(inst.data, value.instance.data);
4992 PopulateInstance(inst);
4996 else if(value.type == constantExp)
5002 void (*Set)(void *, double) = (void *)prop.Set;
5003 Set(inst.data, strtod(value.constant, null) );
5008 void (*Set)(void *, float) = (void *)prop.Set;
5009 Set(inst.data, (float)(strtod(value.constant, null)));
5014 void (*Set)(void *, int) = (void *)prop.Set;
5015 Set(inst.data, (int)strtol(value.constant, null, 0));
5020 void (*Set)(void *, int64) = (void *)prop.Set;
5021 Set(inst.data, _strtoi64(value.constant, null, 0));
5026 void (*Set)(void *, intptr) = (void *)prop.Set;
5027 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5032 void (*Set)(void *, intsize) = (void *)prop.Set;
5033 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5038 else if(value.type == stringExp)
5041 ReadString(temp, value.string);
5042 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5046 else if(!deepMember && type && _class.type == unitClass)
5050 // Only support converting units to units for now...
5051 if(value.type == constantExp)
5053 if(type.kind == classType)
5055 Class _class = type._class.registered;
5056 if(_class.type == unitClass)
5058 if(!_class.dataType)
5059 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5060 type = _class.dataType;
5063 // TODO: Assuming same base type for units...
5069 float (*Set)(float) = (void *)prop.Set;
5070 GetFloat(member.initializer.exp, &fValue);
5071 exp.constant = PrintFloat(Set(fValue));
5072 exp.type = constantExp;
5078 double (*Set)(double) = (void *)prop.Set;
5079 GetDouble(member.initializer.exp, &dValue);
5080 exp.constant = PrintDouble(Set(dValue));
5081 exp.type = constantExp;
5088 else if(!deepMember && type && _class.type == bitClass)
5092 if(value.type == instanceExp && value.instance.data)
5094 unsigned int (*Set)(void *) = (void *)prop.Set;
5095 bits = Set(value.instance.data);
5097 else if(value.type == constantExp)
5103 BitMember bitMember = (BitMember) dataMember;
5106 bits = (bits & ~bitMember.mask);
5107 if(!bitMember.dataType)
5108 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5109 type = bitMember.dataType;
5110 if(type.kind == classType && type._class && type._class.registered)
5112 if(!type._class.registered.dataType)
5113 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5114 type = type._class.registered.dataType;
5119 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5120 case shortType: { uint16 v; type.isSigned ? GetShort(value, (uint16 *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5122 case longType: { uint v; type.isSigned ? GetInt(value, (uint *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5123 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (uint64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5124 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (uintptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5125 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (uintsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5127 bits |= part << bitMember.pos;
5133 if(_class && _class.type == unitClass)
5135 ComputeExpression(member.initializer.exp);
5136 exp.constant = member.initializer.exp.constant;
5137 exp.type = constantExp;
5139 member.initializer.exp.constant = null;
5149 if(_class && _class.type == bitClass)
5151 exp.constant = PrintHexUInt(bits);
5152 exp.type = constantExp;
5154 if(exp.type != instanceExp)
5160 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5162 bool result = false;
5166 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5167 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5171 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5172 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5175 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5176 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5177 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5180 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5181 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5182 result = GetOpFloat(op, &op.f);
5185 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5186 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5187 result = GetOpDouble(op, &op.d);
5190 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5191 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5192 result = GetOpUIntPtr(op, &op.ui64);
5195 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5196 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5197 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5200 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5201 result = isSigned ? GetOpIntPtr(op, &op.i64) : GetOpUIntPtr(op, &op.i64);
5204 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5205 result = isSigned ? GetOpIntSize(op, &op.ui64) : GetOpUIntSize(op, &op.ui64);
5211 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5213 if(exp.op.op == SIZEOF)
5215 FreeExpContents(exp);
5216 exp.type = constantExp;
5217 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5228 // Provide default unary +
5229 Expression exp2 = exp.op.exp2;
5231 FreeExpContents(exp);
5232 FreeType(exp.expType);
5233 FreeType(exp.destType);
5239 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5241 // unary arithmetic increment and decrement
5242 //OPERATOR_ALL(UNARY, ++, Inc)
5243 //OPERATOR_ALL(UNARY, --, Dec)
5246 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5248 // unary logical negation
5250 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5256 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5258 if(Promote(op2, op1.kind, op1.type.isSigned))
5259 op2.kind = op1.kind, op2.ops = op1.ops;
5260 else if(Promote(op1, op2.kind, op2.type.isSigned))
5261 op1.kind = op2.kind, op1.ops = op2.ops;
5265 // binary arithmetic
5267 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5270 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5273 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5276 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5279 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5281 // binary arithmetic assignment
5282 //OPERATOR_ALL(BINARY, =, Asign)
5283 //OPERATOR_ALL(BINARY, +=, AddAsign)
5284 //OPERATOR_ALL(BINARY, -=, SubAsign)
5285 //OPERATOR_ALL(BINARY, *=, MulAsign)
5286 //OPERATOR_ALL(BINARY, /=, DivAsign)
5287 //OPERATOR_ALL(BINARY, %=, ModAsign)
5292 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5296 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5299 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5302 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5305 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5307 // binary bitwise assignment
5308 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5309 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5310 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5311 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5312 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5313 // binary logical equality
5315 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5318 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5322 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5325 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5327 // binary logical relational
5329 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5332 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5335 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5338 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5345 void ComputeExpression(Expression exp)
5347 char expString[10240];
5348 expString[0] = '\0';
5350 PrintExpression(exp, expString);
5357 ComputeInstantiation(exp);
5366 Expression exp1, exp2 = null;
5370 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5373 Expression e = exp.op.exp2;
5375 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5377 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5379 if(e.type == extensionCompoundExp)
5380 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5385 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5387 if(e.type == stringExp && e.string)
5389 char * string = e.string;
5390 int len = strlen(string);
5391 char * tmp = new char[len-2+1];
5392 len = UnescapeString(tmp, string + 1, len - 2);
5394 FreeExpContents(exp);
5395 exp.type = constantExp;
5396 exp.constant = PrintUInt(len + 1);
5400 Type type = e.expType;
5402 FreeExpContents(exp);
5403 exp.type = constantExp;
5404 exp.constant = PrintUInt(ComputeTypeSize(type));
5410 ComputeExpression(exp.op.exp2);
5414 ComputeExpression(exp.op.exp1);
5417 op1 = GetOperand(exp1);
5418 if(op1.type) op1.type.refCount++;
5421 op2 = GetOperand(exp2);
5422 if(op2.type) op2.type.refCount++;
5428 op1 = GetOperand(exp1);
5429 if(op1.type) op1.type.refCount++;
5432 CallOperator(exp, exp1, exp2, op1, op2);
5439 if(exp.op.exp1 && exp.op.exp2)
5444 FreeExpContents(exp);
5445 op1.ops.BitAnd(exp, op1, op2);
5454 FreeExpContents(exp);
5455 op1.ops.Mul(exp, op1, op2);
5464 FreeExpContents(exp);
5465 op1.ops.Add(exp, op1, op2);
5470 // Provide default unary +
5471 Expression exp2 = exp.op.exp2;
5473 FreeExpContents(exp);
5474 FreeType(exp.expType);
5475 FreeType(exp.destType);
5486 FreeExpContents(exp);
5487 op1.ops.Sub(exp, op1, op2);
5494 FreeExpContents(exp);
5495 op1.ops.Neg(exp, op1);
5502 FreeExpContents(exp);
5503 op1.ops.BitNot(exp, op1);
5509 FreeExpContents(exp);
5510 op1.ops.Not(exp, op1);
5513 // Binary only operators
5517 FreeExpContents(exp);
5518 op1.ops.Div(exp, op1, op2);
5524 FreeExpContents(exp);
5525 op1.ops.Mod(exp, op1, op2);
5537 FreeExpContents(exp);
5538 op1.ops.Sma(exp, op1, op2);
5547 FreeExpContents(exp);
5548 op1.ops.Grt(exp, op1, op2);
5557 FreeExpContents(exp);
5558 op1.ops.SmaEqu(exp, op1, op2);
5567 FreeExpContents(exp);
5568 op1.ops.GrtEqu(exp, op1, op2);
5577 FreeExpContents(exp);
5578 op1.ops.Equ(exp, op1, op2);
5587 FreeExpContents(exp);
5588 op1.ops.Nqu(exp, op1, op2);
5595 FreeExpContents(exp);
5596 op1.ops.BitOr(exp, op1, op2);
5602 FreeExpContents(exp);
5603 op1.ops.BitXor(exp, op1, op2);
5611 FreeExpContents(exp);
5612 exp.type = constantExp;
5613 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5617 if(op1.type) FreeType(op1.type);
5618 if(op2.type) FreeType(op2.type);
5622 case extensionExpressionExp:
5625 for(e = exp.list->first; e; e = n)
5630 OldList * list = exp.list;
5631 Expression prev = exp.prev;
5632 Expression next = exp.next;
5633 ComputeExpression(e);
5634 //FreeExpContents(exp);
5635 FreeType(exp.expType);
5636 FreeType(exp.destType);
5655 exp.isConstant = true;
5657 ComputeExpression(exp.index.exp);
5658 if(!exp.index.exp.isConstant)
5659 exp.isConstant = false;
5661 for(e = exp.index.index->first; e; e = e.next)
5663 ComputeExpression(e);
5666 // Check if this type is int
5669 exp.isConstant = false;
5671 exp.expType = Dereference(exp.index.exp.expType);
5677 Expression memberExp = exp.member.exp;
5678 Identifier memberID = exp.member.member;
5681 ComputeExpression(exp.member.exp);
5682 type = exp.member.exp.expType;
5685 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);
5686 Property prop = null;
5687 DataMember member = null;
5688 Class convertTo = null;
5689 if(type.kind == subClassType && exp.member.exp.type == classExp)
5690 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5697 PrintTypeNoConst(type, string, false, true);
5698 classSym = FindClass(string);
5699 _class = classSym ? classSym.registered : null;
5702 if(exp.member.member)
5704 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5706 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5708 if(!prop && !member && _class && exp.member.member)
5710 Symbol classSym = FindClass(exp.member.member.string);
5712 _class = classSym ? classSym.registered : null;
5713 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5720 Type type = prop.dataType;
5721 // TODO: Assuming same base type for units...
5722 if(_class.type == unitClass)
5724 if(type.kind == classType)
5726 Class _class = type._class.registered;
5727 if(_class.type == unitClass)
5729 if(!_class.dataType)
5730 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5731 type = _class.dataType;
5739 float (*Get)(float) = (void *)prop.Get;
5740 GetFloat(exp.member.exp, &value);
5741 exp.constant = PrintFloat(Get ? Get(value) : value);
5742 exp.type = constantExp;
5748 double (*Get)(double);
5749 GetDouble(exp.member.exp, &value);
5752 Get = (void *)prop.Set;
5754 Get = (void *)prop.Get;
5755 exp.constant = PrintDouble(Get ? Get(value) : value);
5756 exp.type = constantExp;
5765 Expression value = exp.member.exp;
5768 ProcessPropertyType(prop);
5770 type = prop.dataType;
5773 // printf("Investigate this\n");
5775 else if(_class.type == structClass)
5781 Class propertyClass = type._class.registered;
5782 if(propertyClass.type == structClass && value.type == instanceExp)
5784 void (*Set)(void *, void *) = (void *)prop.Set;
5785 exp.instance = Instantiation { };
5786 exp.instance.data = new0 byte[_class.structSize];
5787 exp.instance._class = MkSpecifierName(_class.fullName);
5788 exp.instance.loc = exp.loc;
5789 exp.type = instanceExp;
5790 Set(exp.instance.data, value.instance.data);
5791 PopulateInstance(exp.instance);
5798 void (*Set)(void *, int) = (void *)prop.Set;
5800 exp.instance = Instantiation { };
5801 exp.instance.data = new0 byte[_class.structSize];
5802 exp.instance._class = MkSpecifierName(_class.fullName);
5803 exp.instance.loc = exp.loc;
5804 exp.type = instanceExp;
5806 GetInt(value, &intValue);
5808 Set(exp.instance.data, intValue);
5809 PopulateInstance(exp.instance);
5815 void (*Set)(void *, int64) = (void *)prop.Set;
5817 exp.instance = Instantiation { };
5818 exp.instance.data = new0 byte[_class.structSize];
5819 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5820 exp.instance.loc = exp.loc;
5821 exp.type = instanceExp;
5823 GetInt64(value, &intValue);
5825 Set(exp.instance.data, intValue);
5826 PopulateInstance(exp.instance);
5833 void (*Set)(void *, intptr) = (void *)prop.Set;
5835 exp.instance = Instantiation { };
5836 exp.instance.data = new0 byte[_class.structSize];
5837 exp.instance._class = MkSpecifierName(_class.fullName);
5838 exp.instance.loc = exp.loc;
5839 exp.type = instanceExp;
5841 GetIntPtr(value, &intValue);
5843 Set(exp.instance.data, intValue);
5844 PopulateInstance(exp.instance);
5851 void (*Set)(void *, intsize) = (void *)prop.Set;
5853 exp.instance = Instantiation { };
5854 exp.instance.data = new0 byte[_class.structSize];
5855 exp.instance._class = MkSpecifierName(_class.fullName);
5856 exp.instance.loc = exp.loc;
5857 exp.type = instanceExp;
5859 GetIntSize(value, &intValue);
5861 Set(exp.instance.data, intValue);
5862 PopulateInstance(exp.instance);
5868 void (*Set)(void *, float) = (void *)prop.Set;
5870 exp.instance = Instantiation { };
5871 exp.instance.data = new0 byte[_class.structSize];
5872 exp.instance._class = MkSpecifierName(_class.fullName);
5873 exp.instance.loc = exp.loc;
5874 exp.type = instanceExp;
5876 GetFloat(value, &floatValue);
5878 Set(exp.instance.data, floatValue);
5879 PopulateInstance(exp.instance);
5885 void (*Set)(void *, double) = (void *)prop.Set;
5887 exp.instance = Instantiation { };
5888 exp.instance.data = new0 byte[_class.structSize];
5889 exp.instance._class = MkSpecifierName(_class.fullName);
5890 exp.instance.loc = exp.loc;
5891 exp.type = instanceExp;
5893 GetDouble(value, &doubleValue);
5895 Set(exp.instance.data, doubleValue);
5896 PopulateInstance(exp.instance);
5901 else if(_class.type == bitClass)
5907 Class propertyClass = type._class.registered;
5908 if(propertyClass.type == structClass && value.instance.data)
5910 unsigned int (*Set)(void *) = (void *)prop.Set;
5911 unsigned int bits = Set(value.instance.data);
5912 exp.constant = PrintHexUInt(bits);
5913 exp.type = constantExp;
5916 else if(_class.type == bitClass)
5919 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5922 GetUInt(exp.member.exp, &value);
5924 exp.constant = PrintHexUInt(bits);
5925 exp.type = constantExp;
5933 if(_class.type == bitClass)
5936 GetUInt(exp.member.exp, &value);
5942 Class _class = type._class.registered;
5943 if(_class.type == structClass)
5945 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5947 exp.instance = Instantiation { };
5948 exp.instance.data = new0 byte[_class.structSize];
5949 exp.instance._class = MkSpecifierName(_class.fullName);
5950 exp.instance.loc = exp.loc;
5951 //exp.instance.fullSet = true;
5952 exp.type = instanceExp;
5953 Get(value, exp.instance.data);
5954 PopulateInstance(exp.instance);
5956 else if(_class.type == bitClass)
5958 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5959 uint64 bits = Get(value);
5960 exp.constant = PrintHexUInt64(bits);
5961 exp.type = constantExp;
5967 else if(_class.type == structClass)
5969 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5974 Class _class = type._class.registered;
5975 if(_class.type == structClass && value)
5977 void (*Get)(void *, void *) = (void *)prop.Get;
5979 exp.instance = Instantiation { };
5980 exp.instance.data = new0 byte[_class.structSize];
5981 exp.instance._class = MkSpecifierName(_class.fullName);
5982 exp.instance.loc = exp.loc;
5983 //exp.instance.fullSet = true;
5984 exp.type = instanceExp;
5985 Get(value, exp.instance.data);
5986 PopulateInstance(exp.instance);
5994 char * value = exp.member.exp.instance.data;
5999 Class _class = type._class.registered;
6000 if(_class.type == normalClass)
6002 void *(*Get)(void *) = (void *)prop.Get;
6004 exp.instance = Instantiation { };
6005 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6006 exp.type = instanceExp;
6007 exp.instance.data = Get(value, exp.instance.data);
6019 exp.isConstant = false;
6027 if(exp.type != ExpressionType::memberExp)
6029 FreeExpression(memberExp);
6030 FreeIdentifier(memberID);
6036 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6037 FreeExpContents(exp);
6038 exp.constant = PrintUInt(ComputeTypeSize(type));
6039 exp.type = constantExp;
6045 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6046 if(classSym && classSym.registered)
6048 if(classSym.registered.fixed)
6050 FreeSpecifier(exp._class);
6051 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6052 exp.type = constantExp;
6056 char className[1024];
6057 strcpy(className, "__ecereClass_");
6058 FullClassNameCat(className, classSym.string, true);
6059 MangleClassName(className);
6061 DeclareClass(classSym, className);
6063 FreeExpContents(exp);
6064 exp.type = pointerExp;
6065 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6066 exp.member.member = MkIdentifier("structSize");
6076 if(exp.type == castExp)
6079 ComputeExpression(exp.cast.exp);
6082 if(e && exp.expType)
6085 type = exp.destType;
6088 if(type.kind == classType)
6090 Class _class = type._class.registered;
6091 if(_class && (_class.type == unitClass || _class.type == bitClass))
6093 if(!_class.dataType)
6094 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6095 type = _class.dataType;
6106 if(GetChar(e, &value))
6108 FreeExpContents(exp);
6109 exp.constant = PrintChar(value);
6110 exp.type = constantExp;
6115 unsigned char value = 0;
6116 if(GetUChar(e, &value))
6118 FreeExpContents(exp);
6119 exp.constant = PrintUChar(value);
6120 exp.type = constantExp;
6128 if(GetShort(e, &value))
6130 FreeExpContents(exp);
6131 exp.constant = PrintShort(value);
6132 exp.type = constantExp;
6137 unsigned short value = 0;
6138 if(GetUShort(e, &value))
6140 FreeExpContents(exp);
6141 exp.constant = PrintUShort(value);
6142 exp.type = constantExp;
6150 if(GetInt(e, &value))
6152 FreeExpContents(exp);
6153 exp.constant = PrintInt(value);
6154 exp.type = constantExp;
6159 unsigned int value = 0;
6160 if(GetUInt(e, &value))
6162 FreeExpContents(exp);
6163 exp.constant = PrintUInt(value);
6164 exp.type = constantExp;
6172 if(GetInt64(e, &value))
6174 FreeExpContents(exp);
6175 exp.constant = PrintInt64(value);
6176 exp.type = constantExp;
6182 if(GetUInt64(e, &value))
6184 FreeExpContents(exp);
6185 exp.constant = PrintUInt64(value);
6186 exp.type = constantExp;
6194 if(GetIntPtr(e, &value))
6196 FreeExpContents(exp);
6197 exp.constant = PrintInt64((int64)value);
6198 exp.type = constantExp;
6204 if(GetUIntPtr(e, &value))
6206 FreeExpContents(exp);
6207 exp.constant = PrintUInt64((uint64)value);
6208 exp.type = constantExp;
6216 if(GetIntSize(e, &value))
6218 FreeExpContents(exp);
6219 exp.constant = PrintInt64((int64)value);
6220 exp.type = constantExp;
6226 if(GetUIntSize(e, &value))
6228 FreeExpContents(exp);
6229 exp.constant = PrintUInt64((uint64)value);
6230 exp.type = constantExp;
6237 if(GetFloat(e, &value))
6239 FreeExpContents(exp);
6240 exp.constant = PrintFloat(value);
6241 exp.type = constantExp;
6248 if(GetDouble(e, &value))
6250 FreeExpContents(exp);
6251 exp.constant = PrintDouble(value);
6252 exp.type = constantExp;
6267 // Caring only about last expression for now...
6268 ComputeExpression(exp.cond.exp->last);
6269 if(exp.cond.elseExp)
6270 ComputeExpression(exp.cond.elseExp);
6272 ComputeExpression(exp.cond.cond);
6274 op1 = GetOperand(exp.cond.cond);
6275 if(op1.type) op1.type.refCount++;
6276 op2 = GetOperand(exp.cond.exp->last);
6277 if(op2.type) op2.type.refCount++;
6278 op3 = GetOperand(exp.cond.elseExp);
6279 if(op3.type) op3.type.refCount++;
6281 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6282 if(op1.type) FreeType(op1.type);
6283 if(op2.type) FreeType(op2.type);
6284 if(op3.type) FreeType(op3.type);
6290 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
6295 OldList converts { };
6298 if(destType.kind == voidType)
6301 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
6305 // for(convert = converts.last; convert; convert = convert.prev)
6306 for(convert = converts.first; convert; convert = convert.next)
6308 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6311 Expression newExp { };
6312 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6314 // TODO: Check this...
6318 newExp.destType = null;
6323 exp.type = memberExp;
6324 exp.addedThis = true;
6325 exp.member.exp = newExp;
6326 FreeType(exp.member.exp.expType);
6328 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6329 exp.member.exp.expType.classObjectType = objectType;
6330 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6331 exp.member.memberType = propertyMember;
6332 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6333 // TESTING THIS... for (int)degrees
6334 exp.needCast = true;
6335 if(exp.expType) exp.expType.refCount++;
6336 ApplyAnyObjectLogic(exp.member.exp);
6341 /*if(exp.isConstant)
6343 // Color { ColorRGB = [exp] };
6344 exp.type = instanceExp;
6345 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6346 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6347 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6351 // If not constant, don't turn it yet into an instantiation
6352 // (Go through the deep members system first)
6353 exp.type = memberExp;
6354 exp.addedThis = true;
6355 exp.member.exp = newExp;
6357 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6358 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6359 newExp.expType._class.registered.type == noHeadClass)
6361 newExp.byReference = true;
6364 FreeType(exp.member.exp.expType);
6365 /*exp.member.exp.expType = convert.convert.dataType;
6366 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6367 exp.member.exp.expType = null;
6368 if(convert.convert.dataType)
6370 exp.member.exp.expType = { };
6371 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6372 exp.member.exp.expType.refCount = 1;
6373 exp.member.exp.expType.classObjectType = objectType;
6374 ApplyAnyObjectLogic(exp.member.exp);
6377 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6378 exp.member.memberType = reverseConversionMember;
6379 exp.expType = convert.resultType ? convert.resultType :
6380 MkClassType(convert.convert._class.fullName);
6381 exp.needCast = true;
6382 if(convert.resultType) convert.resultType.refCount++;
6388 FreeType(exp.expType);
6391 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6392 exp.needCast = true;
6393 if(exp.expType) exp.expType.refCount++;
6397 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6398 exp.needCast = true;
6399 if(convert.resultType)
6400 convert.resultType.refCount++;
6404 if(exp.isConstant && inCompiler)
6405 ComputeExpression(exp);
6407 converts.Free(FreeConvert);
6410 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6412 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6414 if(!result && exp.expType && exp.destType)
6416 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6417 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6418 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6419 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6423 // if(result) CheckTemplateTypes(exp);
6427 void CheckTemplateTypes(Expression exp)
6429 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6431 Expression newExp { };
6434 if(exp.destType) exp.destType.refCount++;
6435 if(exp.expType) exp.expType.refCount++;
6439 switch(exp.expType.kind)
6442 if(exp.destType.classObjectType)
6444 // We need to pass the address, just pass it along (Undo what was done above)
6445 if(exp.destType) exp.destType.refCount--;
6446 if(exp.expType) exp.expType.refCount--;
6451 // If we're looking for value:
6452 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6454 OldList * unionDefs = MkList();
6455 OldList * statements = MkList();
6456 context = PushContext();
6457 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6458 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6459 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6460 exp.type = extensionCompoundExp;
6461 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6462 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6463 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6464 exp.compound.compound.context = context;
6465 PopContext(context);
6470 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6471 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6475 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6477 Expression newExp { };
6481 if(exp.destType) exp.destType.refCount++;
6482 if(exp.expType) exp.expType.refCount++;
6486 switch(exp.expType.kind)
6489 if(exp.destType.classObjectType)
6491 // We need to pass the address, just pass it along (Undo what was done above)
6492 if(exp.destType) exp.destType.refCount--;
6493 if(exp.expType) exp.expType.refCount--;
6498 // If we're looking for value:
6499 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6501 OldList * unionDefs = MkList();
6502 OldList * statements = MkList();
6503 context = PushContext();
6504 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6505 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6506 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6507 exp.type = extensionCompoundExp;
6508 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6509 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6510 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6511 exp.compound.compound.context = context;
6512 PopContext(context);
6517 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6519 exp.type = bracketsExp;
6520 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6521 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6522 ProcessExpressionType(exp.list->first);
6527 exp.type = bracketsExp;
6528 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6529 newExp.needCast = true;
6530 ProcessExpressionType(exp.list->first);
6536 if(exp.expType.kind == templateType)
6538 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6541 FreeType(exp.destType);
6542 FreeType(exp.expType);
6547 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6552 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6553 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6557 char typeString[1024];
6559 OldList * specs = MkList();
6560 typeString[0] = '\0';
6561 PrintType(exp.expType, typeString, false, false);
6562 decl = SpecDeclFromString(typeString, specs, null);
6565 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6566 exp.cast.typeName = MkTypeName(specs, decl);
6567 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6568 exp.cast.exp.needCast = true;
6575 // TODO: The Symbol tree should be reorganized by namespaces
6577 // - Tree of all symbols within (stored without namespace)
6578 // - Tree of sub-namespaces
6580 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6582 int nsLen = strlen(nameSpace);
6584 // Start at the name space prefix
6585 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6587 char * s = symbol.string;
6588 if(!strncmp(s, nameSpace, nsLen))
6590 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6593 for(c = strlen(s)-1; c >= 0; c--)
6598 if(!strcmp(namePart, name))
6600 // TODO: Error on ambiguity
6610 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6613 char nameSpace[1024];
6615 bool gotColon = false;
6617 nameSpace[0] = '\0';
6618 for(c = strlen(name)-1; c >= 0; c--)
6625 namePart = name+c+1;
6626 while(c >= 0 && name[c] == ':') c--;
6629 // Try an exact match first
6630 Symbol symbol = (Symbol)tree.FindString(name);
6634 // Namespace specified
6635 memcpy(nameSpace, name, c + 1);
6638 return ScanWithNameSpace(tree, nameSpace, namePart);
6642 // Looking for a global symbol, e.g. ::Sleep()
6643 Symbol symbol = (Symbol)tree.FindString(namePart);
6648 // Name only (no namespace specified)
6649 Symbol symbol = (Symbol)tree.FindString(namePart);
6652 return ScanWithNameSpace(tree, "", namePart);
6657 static void ProcessDeclaration(Declaration decl);
6659 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6662 //Time startTime = GetTime();
6664 // Optimize this later? Do this before/less?
6666 Symbol symbol = null;
6667 // First, check if the identifier is declared inside the function
6668 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6670 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6672 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6678 strcpy(curName, thisNameSpace);
6679 strcat(curName, "::");
6680 strcat(curName, name);
6681 // Try to resolve in current namespace first
6682 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6685 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6688 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6690 if(symbol || ctx == endContext) break;
6692 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6694 if(symbol.pointerExternal.type == functionExternal)
6696 FunctionDefinition function = symbol.pointerExternal.function;
6698 // Modified this recently...
6699 Context tmpContext = curContext;
6701 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6702 curContext = tmpContext;
6704 symbol.pointerExternal.symbol = symbol;
6707 DeclareType(symbol.type, true, true);
6709 ast->Insert(curExternal.prev, symbol.pointerExternal);
6711 symbol.id = curExternal.symbol.idCode;
6714 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6716 ast->Move(symbol.pointerExternal, curExternal.prev);
6717 symbol.id = curExternal.symbol.idCode;
6721 //findSymbolTotalTime += GetTime() - startTime;
6726 static void GetTypeSpecs(Type type, OldList * specs)
6728 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6733 if(type._class.registered)
6735 if(!type._class.registered.dataType)
6736 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6737 GetTypeSpecs(type._class.registered.dataType, specs);
6741 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6742 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6743 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6744 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6745 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6746 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6747 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6748 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6751 ListAdd(specs, MkSpecifier(INT)); break;
6755 static void PrintArraySize(Type arrayType, char * string)
6760 if(arrayType.enumClass)
6761 strcat(size, arrayType.enumClass.string);
6762 else if(arrayType.arraySizeExp)
6763 PrintExpression(arrayType.arraySizeExp, size);
6765 strcat(string, size);
6768 // WARNING : This function expects a null terminated string since it recursively concatenate...
6769 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6773 if(printConst && type.constant)
6774 strcat(string, "const ");
6779 Symbol c = type._class;
6780 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6781 // look into merging with thisclass ?
6782 if(type.classObjectType == typedObject)
6783 strcat(string, "typed_object");
6784 else if(type.classObjectType == anyObject)
6785 strcat(string, "any_object");
6789 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6791 if(type.byReference)
6792 strcat(string, " &");
6795 case voidType: strcat(string, "void"); break;
6796 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6797 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6798 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6799 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6800 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6801 case _BoolType: strcat(string, "_Bool"); break;
6802 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6803 case floatType: strcat(string, "float"); break;
6804 case doubleType: strcat(string, "double"); break;
6808 strcat(string, "struct ");
6809 strcat(string, type.enumName);
6811 else if(type.typeName)
6812 strcat(string, type.typeName);
6816 strcat(string, "struct { ");
6817 for(member = type.members.first; member; member = member.next)
6819 PrintType(member, string, true, fullName);
6820 strcat(string,"; ");
6828 strcat(string, "union ");
6829 strcat(string, type.enumName);
6831 else if(type.typeName)
6832 strcat(string, type.typeName);
6835 strcat(string, "union ");
6836 strcat(string,"(unnamed)");
6842 strcat(string, "enum ");
6843 strcat(string, type.enumName);
6845 else if(type.typeName)
6846 strcat(string, type.typeName);
6848 strcat(string, "int"); // "enum");
6851 strcat(string, "...");
6854 strcat(string, "subclass(");
6855 strcat(string, type._class ? type._class.string : "int");
6856 strcat(string, ")");
6859 strcat(string, type.templateParameter.identifier.string);
6862 strcat(string, "thisclass");
6865 strcat(string, "__builtin_va_list");
6871 static void PrintName(Type type, char * string, bool fullName)
6873 if(type.name && type.name[0])
6876 strcat(string, type.name);
6879 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6880 if(name) name += 2; else name = type.name;
6881 strcat(string, name);
6886 static void PrintAttribs(Type type, char * string)
6890 if(type.dllExport) strcat(string, "dllexport ");
6891 if(type.attrStdcall) strcat(string, "stdcall ");
6895 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
6897 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6899 Type attrType = null;
6900 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
6901 PrintAttribs(type, string);
6902 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
6903 strcat(string, " const");
6904 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
6905 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6906 strcat(string, " (");
6907 if(type.kind == pointerType)
6909 if(type.type.kind == functionType || type.type.kind == methodType)
6910 PrintAttribs(type.type, string);
6912 if(type.kind == pointerType)
6914 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
6915 strcat(string, "*");
6917 strcat(string, " *");
6919 if(printConst && type.constant && type.kind == pointerType)
6920 strcat(string, " const");
6923 PrintTypeSpecs(type, string, fullName, printConst);
6926 static void PostPrintType(Type type, char * string, bool fullName)
6928 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6929 strcat(string, ")");
6930 if(type.kind == arrayType)
6931 PrintArraySize(type, string);
6932 else if(type.kind == functionType)
6935 strcat(string, "(");
6936 for(param = type.params.first; param; param = param.next)
6938 PrintType(param, string, true, fullName);
6939 if(param.next) strcat(string, ", ");
6941 strcat(string, ")");
6943 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6944 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
6948 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6950 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
6952 PrePrintType(type, string, fullName, null, printConst);
6954 if(type.thisClass || (printName && type.name && type.name[0]))
6955 strcat(string, " ");
6956 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
6958 Symbol _class = type.thisClass;
6959 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
6961 if(type.classObjectType == classPointer)
6962 strcat(string, "class");
6964 strcat(string, type.byReference ? "typed_object&" : "typed_object");
6966 else if(_class && _class.string)
6968 String s = _class.string;
6973 char * name = RSearchString(s, "::", strlen(s), true, false);
6974 if(name) name += 2; else name = s;
6975 strcat(string, name);
6978 strcat(string, "::");
6981 if(printName && type.name)
6982 PrintName(type, string, fullName);
6983 PostPrintType(type, string, fullName);
6984 if(type.bitFieldCount)
6987 sprintf(count, ":%d", type.bitFieldCount);
6988 strcat(string, count);
6992 void PrintType(Type type, char * string, bool printName, bool fullName)
6994 _PrintType(type, string, printName, fullName, true);
6997 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
6999 _PrintType(type, string, printName, fullName, false);
7002 static Type FindMember(Type type, char * string)
7005 for(memberType = type.members.first; memberType; memberType = memberType.next)
7007 if(!memberType.name)
7009 Type subType = FindMember(memberType, string);
7013 else if(!strcmp(memberType.name, string))
7019 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7022 for(memberType = type.members.first; memberType; memberType = memberType.next)
7024 if(!memberType.name)
7026 Type subType = FindMember(memberType, string);
7029 *offset += memberType.offset;
7033 else if(!strcmp(memberType.name, string))
7035 *offset += memberType.offset;
7042 public bool GetParseError() { return parseError; }
7044 Expression ParseExpressionString(char * expression)
7048 fileInput = TempFile { };
7049 fileInput.Write(expression, 1, strlen(expression));
7050 fileInput.Seek(0, start);
7053 parsedExpression = null;
7055 expression_yyparse();
7058 return parsedExpression;
7061 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7063 Identifier id = exp.identifier;
7064 Method method = null;
7065 Property prop = null;
7066 DataMember member = null;
7067 ClassProperty classProp = null;
7069 if(_class && _class.type == enumClass)
7071 NamedLink value = null;
7072 Class enumClass = eSystem_FindClass(privateModule, "enum");
7076 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7078 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7079 for(value = e.values.first; value; value = value.next)
7081 if(!strcmp(value.name, id.string))
7088 FreeExpContents(exp);
7090 exp.type = constantExp;
7091 exp.isConstant = true;
7092 if(!strcmp(baseClass.dataTypeString, "int"))
7093 sprintf(constant, "%d",(int)value.data);
7095 sprintf(constant, "0x%X",(int)value.data);
7096 exp.constant = CopyString(constant);
7097 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7098 exp.expType = MkClassType(baseClass.fullName);
7106 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7108 ProcessMethodType(method);
7115 // TOCHECK: Put it back to what it was...
7116 // methodClass = _class;
7117 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7122 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7125 ProcessPropertyType(prop);
7126 exp.expType = prop.dataType;
7127 if(prop.dataType) prop.dataType.refCount++;
7130 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7132 if(!member.dataType)
7133 member.dataType = ProcessTypeString(member.dataTypeString, false);
7134 exp.expType = member.dataType;
7135 if(member.dataType) member.dataType.refCount++;
7138 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7140 if(!classProp.dataType)
7141 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7143 if(classProp.constant)
7145 FreeExpContents(exp);
7147 exp.isConstant = true;
7148 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7150 //char constant[256];
7151 exp.type = stringExp;
7152 exp.constant = QMkString((char *)classProp.Get(_class));
7157 exp.type = constantExp;
7158 sprintf(constant, "%d", (int)classProp.Get(_class));
7159 exp.constant = CopyString(constant);
7167 exp.expType = classProp.dataType;
7168 if(classProp.dataType) classProp.dataType.refCount++;
7174 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7176 BinaryTree * tree = &nameSpace.functions;
7177 GlobalData data = (GlobalData)tree->FindString(name);
7181 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7183 data = ScanGlobalData(child, name);
7191 static GlobalData FindGlobalData(char * name)
7194 NameSpace * nameSpace;
7195 nameSpace = globalData;
7196 for(c = 0; name[c]; c++)
7198 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7200 NameSpace * newSpace;
7201 char * spaceName = new char[c - start + 1];
7202 strncpy(spaceName, name + start, c - start);
7203 spaceName[c-start] = '\0';
7204 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7208 nameSpace = newSpace;
7209 if(name[c] == ':') c++;
7215 return ScanGlobalData(nameSpace, name + start);
7220 static int definedExpStackPos;
7221 static void * definedExpStack[512];
7223 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7224 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7226 Expression prev = checkedExp.prev, next = checkedExp.next;
7228 FreeExpContents(checkedExp);
7229 FreeType(checkedExp.expType);
7230 FreeType(checkedExp.destType);
7232 *checkedExp = *newExp;
7236 checkedExp.prev = prev;
7237 checkedExp.next = next;
7240 void ApplyAnyObjectLogic(Expression e)
7242 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7244 char debugExpString[4096];
7245 debugExpString[0] = '\0';
7246 PrintExpression(e, debugExpString);
7249 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7251 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7252 //ellipsisDestType = destType;
7255 Type type = e.expType;
7256 Class _class = null;
7257 //Type destType = e.destType;
7259 if(type.kind == classType && type._class && type._class.registered)
7261 _class = type._class.registered;
7263 else if(type.kind == subClassType)
7265 _class = FindClass("ecere::com::Class").registered;
7269 char string[1024] = "";
7272 PrintTypeNoConst(type, string, false, true);
7273 classSym = FindClass(string);
7274 if(classSym) _class = classSym.registered;
7277 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...
7278 (!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))) ||
7279 destType.byReference)))
7281 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7283 Expression checkedExp = e, newExp;
7285 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7287 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7289 if(checkedExp.type == extensionCompoundExp)
7291 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7294 checkedExp = checkedExp.list->last;
7296 else if(checkedExp.type == castExp)
7297 checkedExp = checkedExp.cast.exp;
7300 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7302 newExp = checkedExp.op.exp2;
7303 checkedExp.op.exp2 = null;
7304 FreeExpContents(checkedExp);
7306 if(e.expType && e.expType.passAsTemplate)
7309 ComputeTypeSize(e.expType);
7310 sprintf(size, "%d", e.expType.size);
7311 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7312 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7313 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7316 ReplaceExpContents(checkedExp, newExp);
7317 e.byReference = true;
7319 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7321 Expression checkedExp; //, newExp;
7324 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7326 e.type == identifierExp ||
7327 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7328 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7329 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7332 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7334 Context context = PushContext();
7336 OldList * specs = MkList();
7337 char typeString[1024];
7338 Expression newExp { };
7340 typeString[0] = '\0';
7343 //if(e.destType) e.destType.refCount++;
7344 // if(exp.expType) exp.expType.refCount++;
7347 newExp.expType = null;
7349 PrintTypeNoConst(e.expType, typeString, false, true);
7350 decl = SpecDeclFromString(typeString, specs, null);
7351 newExp.destType = ProcessType(specs, decl);
7353 curContext = context;
7355 // We need a current compound for this
7359 OldList * stmts = MkList();
7360 e.type = extensionCompoundExp;
7361 sprintf(name, "__internalValue%03X", internalValueCounter++);
7362 if(!curCompound.compound.declarations)
7363 curCompound.compound.declarations = MkList();
7364 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7365 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7366 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7367 e.compound = MkCompoundStmt(null, stmts);
7370 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7373 e.compound = MkCompoundStmt(
7374 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7375 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7377 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7381 Type type = e.destType;
7383 CopyTypeInto(e.destType, type);
7384 e.destType.refCount = 1;
7385 e.destType.classObjectType = none;
7389 e.compound.compound.context = context;
7390 PopContext(context);
7391 curContext = context.parent;
7395 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7397 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7399 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7401 if(checkedExp.type == extensionCompoundExp)
7403 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7406 checkedExp = checkedExp.list->last;
7408 else if(checkedExp.type == castExp)
7409 checkedExp = checkedExp.cast.exp;
7412 Expression operand { };
7413 operand = *checkedExp;
7414 checkedExp.destType = null;
7415 checkedExp.expType = null;
7417 checkedExp.type = opExp;
7418 checkedExp.op.op = '&';
7419 checkedExp.op.exp1 = null;
7420 checkedExp.op.exp2 = operand;
7422 //newExp = MkExpOp(null, '&', checkedExp);
7424 //ReplaceExpContents(checkedExp, newExp);
7431 // If expression type is a simple class, make it an address
7432 // FixReference(e, true);
7435 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7436 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7437 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7439 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"))
7441 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7445 Expression thisExp { };
7448 thisExp.prev = null;
7449 thisExp.next = null;
7452 e.type = bracketsExp;
7453 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7454 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7455 ((Expression)e.list->first).byReference = true;
7457 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7459 e.expType = thisExp.expType;
7460 e.expType.refCount++;
7465 CopyTypeInto(e.expType, thisExp.expType);
7466 e.expType.byReference = false;
7467 e.expType.refCount = 1;
7469 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7470 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7472 e.expType.classObjectType = none;
7477 // TOFIX: Try this for a nice IDE crash!
7479 // The other way around
7482 if(destType && e.expType &&
7483 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7484 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7485 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7487 if(destType.kind == ellipsisType)
7489 Compiler_Error($"Unspecified type\n");
7491 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7493 bool byReference = e.expType.byReference;
7494 Expression thisExp { };
7496 OldList * specs = MkList();
7497 char typeString[1024]; // Watch buffer overruns
7499 ClassObjectType backupClassObjectType;
7500 bool backupByReference;
7502 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7507 backupClassObjectType = type.classObjectType;
7508 backupByReference = type.byReference;
7510 type.classObjectType = none;
7511 type.byReference = false;
7513 typeString[0] = '\0';
7514 PrintType(type, typeString, false, true);
7515 decl = SpecDeclFromString(typeString, specs, null);
7517 type.classObjectType = backupClassObjectType;
7518 type.byReference = backupByReference;
7521 thisExp.prev = null;
7522 thisExp.next = null;
7525 if( ( type.kind == classType && type._class && type._class.registered &&
7526 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7527 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7528 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7529 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7534 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7537 CopyTypeInto(e.expType, type);
7538 e.expType.byReference = false;
7539 e.expType.refCount = 1;
7544 e.cast.typeName = MkTypeName(specs, decl);
7545 e.cast.exp = thisExp;
7546 e.byReference = true;
7550 e.destType = destType;
7551 destType.refCount++;
7556 void ProcessExpressionType(Expression exp)
7558 bool unresolved = false;
7559 Location oldyylloc = yylloc;
7560 bool notByReference = false;
7562 char debugExpString[4096];
7563 debugExpString[0] = '\0';
7564 PrintExpression(exp, debugExpString);
7566 if(!exp || exp.expType)
7569 //eSystem_Logf("%s\n", expString);
7571 // Testing this here
7577 Identifier id = exp.identifier;
7578 if(!id || !topContext) return;
7580 // DOING THIS LATER NOW...
7581 if(id._class && id._class.name)
7583 id.classSym = id._class.symbol; // FindClass(id._class.name);
7584 /* TODO: Name Space Fix ups
7586 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7590 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7592 exp.expType = ProcessTypeString("Module", true);
7595 else */if(strstr(id.string, "__ecereClass") == id.string)
7597 exp.expType = ProcessTypeString("ecere::com::Class", true);
7600 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7602 // Added this here as well
7603 ReplaceClassMembers(exp, thisClass);
7604 if(exp.type != identifierExp)
7606 ProcessExpressionType(exp);
7610 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7615 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7616 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7617 if(!symbol/* && exp.destType*/)
7619 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7625 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7626 if(exp.type != identifierExp)
7628 ProcessExpressionType(exp);
7632 // Static methods called from inside the _class
7633 else if(currentClass && !id._class)
7635 if(ResolveIdWithClass(exp, currentClass, true))
7638 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7642 // If we manage to resolve this symbol
7645 Type type = symbol.type;
7646 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7648 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7650 Context context = SetupTemplatesContext(_class);
7651 type = ReplaceThisClassType(_class);
7652 FinishTemplatesContext(context);
7653 if(type) type.refCount = 0; // We'll be incrementing it right below...
7656 FreeSpecifier(id._class);
7659 id.string = CopyString(symbol.string);
7666 // Commented this out, it was making non-constant enum parameters seen as constant
7667 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7668 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7669 // Add missing cases here... enum Classes...
7670 exp.isConstant = true;
7672 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7673 if(symbol.isParam || !strcmp(id.string, "this"))
7675 if(_class && _class.type == structClass && !type.declaredWithStruct)
7676 exp.byReference = true;
7678 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7679 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7680 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7681 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7683 Identifier id = exp.identifier;
7684 exp.type = bracketsExp;
7685 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7689 if(symbol.isIterator)
7691 if(symbol.isIterator == 3)
7693 exp.type = bracketsExp;
7694 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7695 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7697 ProcessExpressionType(exp);
7699 else if(symbol.isIterator != 4)
7701 exp.type = memberExp;
7702 exp.member.exp = MkExpIdentifier(exp.identifier);
7703 exp.member.exp.expType = exp.expType;
7704 /*if(symbol.isIterator == 6)
7705 exp.member.member = MkIdentifier("key");
7707 exp.member.member = MkIdentifier("data");
7709 ProcessExpressionType(exp);
7716 DefinedExpression definedExp = null;
7717 if(thisNameSpace && !(id._class && !id._class.name))
7720 strcpy(name, thisNameSpace);
7722 strcat(name, id.string);
7723 definedExp = eSystem_FindDefine(privateModule, name);
7726 definedExp = eSystem_FindDefine(privateModule, id.string);
7730 for(c = 0; c<definedExpStackPos; c++)
7731 if(definedExpStack[c] == definedExp)
7733 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7735 Location backupYylloc = yylloc;
7736 File backInput = fileInput;
7737 definedExpStack[definedExpStackPos++] = definedExp;
7739 fileInput = TempFile { };
7740 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7741 fileInput.Seek(0, start);
7744 parsedExpression = null;
7746 expression_yyparse();
7749 fileInput = backInput;
7751 yylloc = backupYylloc;
7753 if(parsedExpression)
7756 exp.type = bracketsExp;
7757 exp.list = MkListOne(parsedExpression);
7758 parsedExpression.loc = yylloc;
7759 ProcessExpressionType(exp);
7760 definedExpStackPos--;
7763 definedExpStackPos--;
7769 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7775 GlobalData data = null;
7776 if(thisNameSpace && !(id._class && !id._class.name))
7779 strcpy(name, thisNameSpace);
7781 strcat(name, id.string);
7782 data = FindGlobalData(name);
7785 data = FindGlobalData(id.string);
7788 DeclareGlobalData(data);
7789 exp.expType = data.dataType;
7790 if(data.dataType) data.dataType.refCount++;
7793 id.string = CopyString(data.fullName);
7794 FreeSpecifier(id._class);
7801 GlobalFunction function = null;
7802 if(thisNameSpace && !(id._class && !id._class.name))
7805 strcpy(name, thisNameSpace);
7807 strcat(name, id.string);
7808 function = eSystem_FindFunction(privateModule, name);
7811 function = eSystem_FindFunction(privateModule, id.string);
7816 id.string = CopyString(function.name);
7819 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7820 strcpy(name, "__ecereFunction_");
7821 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7822 if(DeclareFunction(function, name))
7825 id.string = CopyString(name);
7827 exp.expType = function.dataType;
7828 if(function.dataType) function.dataType.refCount++;
7830 FreeSpecifier(id._class);
7847 if(!exp.instance._class)
7849 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7851 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7855 //classSym = FindClass(exp.instance._class.fullName);
7856 //_class = classSym ? classSym.registered : null;
7858 ProcessInstantiationType(exp.instance);
7859 exp.isConstant = exp.instance.isConstant;
7862 if(_class.type == unitClass && _class.base.type != systemClass)
7865 Type destType = exp.destType;
7867 exp.destType = MkClassType(_class.base.fullName);
7868 exp.expType = MkClassType(_class.fullName);
7869 CheckExpressionType(exp, exp.destType, true);
7871 exp.destType = destType;
7873 exp.expType = MkClassType(_class.fullName);
7876 if(exp.instance._class)
7878 exp.expType = MkClassType(exp.instance._class.name);
7879 /*if(exp.expType._class && exp.expType._class.registered &&
7880 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7881 exp.expType.byReference = true;*/
7889 char * constant = exp.constant;
7897 if(constant[0] == '\'')
7899 if((int)((byte *)constant)[1] > 127)
7902 unichar ch = UTF8GetChar(constant + 1, &nb);
7903 if(nb < 2) ch = constant[1];
7905 exp.constant = PrintUInt(ch);
7906 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7907 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7908 type._class = FindClass("unichar");
7910 type.isSigned = false;
7914 type.kind = charType;
7915 type.isSigned = true;
7920 char * dot = strchr(constant, '.');
7921 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
7925 exponent = strchr(constant, 'p');
7926 if(!exponent) exponent = strchr(constant, 'P');
7930 exponent = strchr(constant, 'e');
7931 if(!exponent) exponent = strchr(constant, 'E');
7936 if(strchr(constant, 'f') || strchr(constant, 'F'))
7937 type.kind = floatType;
7939 type.kind = doubleType;
7940 type.isSigned = true;
7944 bool isSigned = constant[0] == '-';
7946 int64 i64 = strtoll(constant, &endP, 0);
7947 uint64 ui64 = strtoull(constant, &endP, 0);
7948 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
7961 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
7965 else if(constant[0] != '0' || !constant[1])
7968 type.kind = is64Bit ? int64Type : intType;
7969 type.isSigned = isSigned;
7972 exp.isConstant = true;
7973 if(exp.destType && exp.destType.kind == doubleType)
7974 type.kind = doubleType;
7975 else if(exp.destType && exp.destType.kind == floatType)
7976 type.kind = floatType;
7977 else if(exp.destType && exp.destType.kind == int64Type)
7978 type.kind = int64Type;
7984 exp.isConstant = true; // Why wasn't this constant?
8001 ProcessExpressionType(exp._new.size);
8006 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8008 DeclareType(exp.expType.type, false, false);
8012 ProcessExpressionType(exp._renew.size);
8013 ProcessExpressionType(exp._renew.exp);
8018 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8020 DeclareType(exp.expType.type, false, false);
8024 bool assign = false, boolResult = false, boolOps = false;
8025 Type type1 = null, type2 = null;
8026 bool useDestType = false, useSideType = false;
8027 Location oldyylloc = yylloc;
8028 bool useSideUnit = false;
8029 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8031 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8040 // Assignment Operators
8054 // boolean Operators
8056 // Expect boolean operators
8058 //boolResult = true;
8062 // Expect boolean operands
8073 // Gives boolean result
8105 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8111 /*// Implement speed etc.
8117 if(exp.op.op == '&')
8119 // Added this here earlier for Iterator address as key
8120 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8122 Identifier id = exp.op.exp2.identifier;
8123 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8124 if(symbol && symbol.isIterator == 2)
8126 exp.type = memberExp;
8127 exp.member.exp = exp.op.exp2;
8128 exp.member.member = MkIdentifier("key");
8130 exp.op.exp2.expType = symbol.type;
8131 symbol.type.refCount++;
8132 ProcessExpressionType(exp);
8136 // exp.op.exp2.usage.usageRef = true;
8140 //dummy.kind = TypeDummy;
8143 // Added this check here to use the dest type only for units derived from the base unit
8144 // So that untyped units will use the side unit as opposed to the untyped destination unit
8145 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8146 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8147 useDestType = false;
8149 if(destClass && useDestType &&
8150 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8152 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8154 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8155 exp.op.exp1.destType = exp.destType;
8156 exp.op.exp1.opDestType = true;
8158 exp.destType.refCount++;
8162 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8163 exp.op.exp1.destType = dummy;
8167 // TESTING THIS HERE...
8168 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8169 ProcessExpressionType(exp.op.exp1);
8170 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8172 exp.op.exp1.opDestType = false;
8174 // Fix for unit and ++ / --
8175 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8176 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8178 exp.op.exp2 = MkExpConstant("1");
8179 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8183 if(exp.op.exp1.destType == dummy)
8186 exp.op.exp1.destType = null;
8188 type1 = exp.op.exp1.expType;
8193 char expString[10240];
8194 expString[0] = '\0';
8195 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8199 exp.op.exp2.destType = exp.op.exp1.expType;
8200 if(exp.op.exp1.expType)
8201 exp.op.exp1.expType.refCount++;
8205 exp.op.exp2.destType = exp.destType;
8206 if(!exp.op.exp1 || exp.op.op != '&')
8207 exp.op.exp2.opDestType = true;
8209 exp.destType.refCount++;
8212 if(type1) type1.refCount++;
8213 exp.expType = type1;
8218 PrintExpression(exp.op.exp2, expString);
8220 if(type1 && type1.kind == pointerType)
8222 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 ||
8223 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8224 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8225 else if(exp.op.op == '=')
8227 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8228 exp.op.exp2.destType = type1;
8235 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8236 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/* ||
8237 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8240 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8241 exp.op.exp2.destType = type1;
8246 if(type1) type1.refCount++;
8247 exp.expType = type1;
8249 else if(destClass &&
8250 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8251 (destClass.type == enumClass && useDestType)))
8253 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8254 exp.op.exp2.destType = exp.destType;
8255 if(exp.op.op != '&')
8256 exp.op.exp2.opDestType = true;
8258 exp.destType.refCount++;
8262 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8263 exp.op.exp2.destType = dummy;
8267 // TESTING THIS HERE... (DANGEROUS)
8268 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8269 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8271 FreeType(exp.op.exp2.destType);
8272 exp.op.exp2.destType = type1;
8275 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8276 // Cannot lose the cast on a sizeof
8277 if(exp.op.op == SIZEOF)
8279 Expression e = exp.op.exp2;
8280 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8282 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8284 if(e.type == extensionCompoundExp)
8285 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8290 if(e.type == castExp && e.cast.exp)
8291 e.cast.exp.needCast = true;
8293 ProcessExpressionType(exp.op.exp2);
8294 exp.op.exp2.opDestType = false;
8295 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8297 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8299 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)
8301 if(exp.op.op != '=' && type1.type.kind == voidType)
8302 Compiler_Error($"void *: unknown size\n");
8304 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||
8305 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8306 (exp.op.exp2.expType._class.registered.type == normalClass ||
8307 exp.op.exp2.expType._class.registered.type == structClass ||
8308 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8310 if(exp.op.op == ADD_ASSIGN)
8311 Compiler_Error($"cannot add two pointers\n");
8313 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8314 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8316 if(exp.op.op == ADD_ASSIGN)
8317 Compiler_Error($"cannot add two pointers\n");
8321 char type1String[1024];
8322 char type2String[1024];
8323 type1String[0] = '\0';
8324 type2String[0] = '\0';
8326 PrintType(exp.op.exp2.expType, type1String, false, true);
8327 PrintType(type1, type2String, false, true);
8328 ChangeCh(expString, '\n', ' ');
8329 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8333 if(exp.op.exp2.destType == dummy)
8336 exp.op.exp2.destType = null;
8339 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8343 CopyTypeInto(type2, exp.op.exp2.expType);
8344 type2.isSigned = true;
8346 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8348 type2 = { kind = intType };
8350 type2.isSigned = true;
8354 type2 = exp.op.exp2.expType;
8355 if(type2) type2.refCount++;
8359 dummy.kind = voidType;
8361 if(exp.op.op == SIZEOF)
8368 exp.isConstant = true;
8370 // Get type of dereferenced pointer
8371 else if(exp.op.op == '*' && !exp.op.exp1)
8373 exp.expType = Dereference(type2);
8374 if(type2 && type2.kind == classType)
8375 notByReference = true;
8377 else if(exp.op.op == '&' && !exp.op.exp1)
8378 exp.expType = Reference(type2);
8385 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8386 exp.op.exp1.destType = MkClassType("bool");
8387 exp.op.exp1.destType.truth = true;
8388 if(!exp.op.exp1.expType)
8389 ProcessExpressionType(exp.op.exp1);
8391 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8392 FreeType(exp.op.exp1.expType);
8393 exp.op.exp1.expType = MkClassType("bool");
8394 exp.op.exp1.expType.truth = true;
8398 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8399 exp.op.exp2.destType = MkClassType("bool");
8400 exp.op.exp2.destType.truth = true;
8401 if(!exp.op.exp2.expType)
8402 ProcessExpressionType(exp.op.exp2);
8404 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8405 FreeType(exp.op.exp2.expType);
8406 exp.op.exp2.expType = MkClassType("bool");
8407 exp.op.exp2.expType.truth = true;
8410 else if(exp.op.exp1 && exp.op.exp2 &&
8413 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8414 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8415 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8416 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8418 if(type1 && type2 &&
8419 // If either both are class or both are not class
8420 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8422 // Added this check for enum subtraction to result in an int type:
8423 if(exp.op.op == '-' &&
8424 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8425 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8428 if(!type1._class.registered.dataType)
8429 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8430 if(!type2._class.registered.dataType)
8431 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8433 intType = ProcessTypeString(
8434 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8436 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8437 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8438 exp.op.exp1.destType = intType;
8439 exp.op.exp2.destType = intType;
8444 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8445 exp.op.exp2.destType = type1;
8447 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8448 exp.op.exp1.destType = type2;
8452 // Warning here for adding Radians + Degrees with no destination type
8453 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8454 type1._class.registered && type1._class.registered.type == unitClass &&
8455 type2._class.registered && type2._class.registered.type == unitClass &&
8456 type1._class.registered != type2._class.registered)
8457 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8458 type1._class.string, type2._class.string, type1._class.string);
8460 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8462 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8465 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8467 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8468 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8471 ProcessExpressionType(exp.op.exp1);
8473 if(type2.kind != pointerType)
8475 ProcessExpressionType(classExp);
8477 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8478 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8479 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8481 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8484 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8485 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8486 MkPointer(null, null), null)))),
8487 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8489 if(!exp.op.exp2.expType)
8493 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8497 ProcessExpressionType(exp.op.exp2);
8502 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)))
8504 if(type1.kind != classType && type1.type.kind == voidType)
8505 Compiler_Error($"void *: unknown size\n");
8506 exp.expType = type1;
8507 if(type1) type1.refCount++;
8509 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)))
8511 if(type2.kind != classType && type2.type.kind == voidType)
8512 Compiler_Error($"void *: unknown size\n");
8513 exp.expType = type2;
8514 if(type2) type2.refCount++;
8516 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8517 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8519 Compiler_Warning($"different levels of indirection\n");
8523 bool success = false;
8524 if(type1.kind == pointerType && type2.kind == pointerType)
8526 if(exp.op.op == '+')
8527 Compiler_Error($"cannot add two pointers\n");
8528 else if(exp.op.op == '-')
8530 // Pointer Subtraction gives integer
8531 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8540 if(type1.type.kind == templateType)
8542 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8545 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8547 ProcessExpressionType(classExp);
8549 exp.type = bracketsExp;
8550 exp.list = MkListOne(MkExpOp(
8551 MkExpBrackets(MkListOne(MkExpOp(
8552 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8554 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8556 //MkExpMember(classExp, MkIdentifier("typeSize"))
8558 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8559 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8561 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8564 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8565 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8566 MkPointer(null, null), null)))),
8567 MkExpMember(classExp, MkIdentifier("typeSize")))))
8572 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8581 if(!success && exp.op.exp1.type == constantExp)
8583 // If first expression is constant, try to match that first
8584 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8586 if(exp.expType) FreeType(exp.expType);
8587 exp.expType = exp.op.exp1.destType;
8588 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8591 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8593 if(exp.expType) FreeType(exp.expType);
8594 exp.expType = exp.op.exp2.destType;
8595 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8601 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8603 if(exp.expType) FreeType(exp.expType);
8604 exp.expType = exp.op.exp2.destType;
8605 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8608 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8610 if(exp.expType) FreeType(exp.expType);
8611 exp.expType = exp.op.exp1.destType;
8612 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8618 char expString1[10240];
8619 char expString2[10240];
8622 expString1[0] = '\0';
8623 expString2[0] = '\0';
8628 PrintExpression(exp.op.exp1, expString1);
8629 ChangeCh(expString1, '\n', ' ');
8630 PrintExpression(exp.op.exp2, expString2);
8631 ChangeCh(expString2, '\n', ' ');
8632 PrintType(exp.op.exp1.expType, type1, false, true);
8633 PrintType(exp.op.exp2.expType, type2, false, true);
8636 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8640 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8641 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8643 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8644 // Convert e.g. / 4 into / 4.0
8645 exp.op.exp1.destType = type2._class.registered.dataType;
8646 if(type2._class.registered.dataType)
8647 type2._class.registered.dataType.refCount++;
8648 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8649 exp.expType = type2;
8650 if(type2) type2.refCount++;
8652 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8654 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8655 // Convert e.g. / 4 into / 4.0
8656 exp.op.exp2.destType = type1._class.registered.dataType;
8657 if(type1._class.registered.dataType)
8658 type1._class.registered.dataType.refCount++;
8659 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8660 exp.expType = type1;
8661 if(type1) type1.refCount++;
8667 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8669 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8671 if(!type1._class.registered.dataType)
8672 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8673 exp.op.exp2.destType = type1._class.registered.dataType;
8674 exp.op.exp2.destType.refCount++;
8676 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8679 type2 = exp.op.exp2.destType;
8680 if(type2) type2.refCount++;
8682 exp.expType = type2;
8686 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8688 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8690 if(!type2._class.registered.dataType)
8691 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8692 exp.op.exp1.destType = type2._class.registered.dataType;
8693 exp.op.exp1.destType.refCount++;
8695 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8696 type1 = exp.op.exp1.destType;
8697 exp.expType = type1;
8701 // TESTING THIS NEW CODE
8702 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8704 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8705 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8706 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8708 // Convert the enum to an int instead for these operators
8709 if(op1IsEnum && exp.op.exp2.expType)
8711 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8713 if(exp.expType) FreeType(exp.expType);
8714 exp.expType = exp.op.exp2.expType;
8715 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8719 else if(op2IsEnum && exp.op.exp1.expType)
8721 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8723 if(exp.expType) FreeType(exp.expType);
8724 exp.expType = exp.op.exp1.expType;
8725 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8732 if(op1IsEnum && exp.op.exp2.expType)
8734 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8736 if(exp.expType) FreeType(exp.expType);
8737 exp.expType = exp.op.exp1.expType;
8738 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8742 else if(op2IsEnum && exp.op.exp1.expType)
8744 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8746 if(exp.expType) FreeType(exp.expType);
8747 exp.expType = exp.op.exp2.expType;
8748 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8757 // 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
8758 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8759 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8761 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8762 exp.op.exp1.destType = type2;
8765 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8767 if(exp.expType) FreeType(exp.expType);
8768 exp.expType = exp.op.exp1.destType;
8769 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8774 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8775 exp.op.exp2.destType = type1;
8779 // Maybe this was meant to be an enum...
8780 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8782 Type oldType = exp.op.exp2.expType;
8783 exp.op.exp2.expType = null;
8784 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8787 exp.op.exp2.expType = oldType;
8792 // TESTING THIS HERE... LATEST ADDITION
8793 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8795 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8796 exp.op.exp2.destType = type2._class.registered.dataType;
8797 if(type2._class.registered.dataType)
8798 type2._class.registered.dataType.refCount++;
8799 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8801 //exp.expType = type2._class.registered.dataType; //type2;
8802 //if(type2) type2.refCount++;
8805 // TESTING THIS HERE... LATEST ADDITION
8806 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8808 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8809 exp.op.exp1.destType = type1._class.registered.dataType;
8810 if(type1._class.registered.dataType)
8811 type1._class.registered.dataType.refCount++;
8812 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8813 exp.expType = type1._class.registered.dataType; //type1;
8814 if(type1) type1.refCount++;
8818 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8820 if(exp.expType) FreeType(exp.expType);
8821 exp.expType = exp.op.exp2.destType;
8822 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8824 else if(type1 && type2)
8826 char expString1[10240];
8827 char expString2[10240];
8828 char type1String[1024];
8829 char type2String[1024];
8830 expString1[0] = '\0';
8831 expString2[0] = '\0';
8832 type1String[0] = '\0';
8833 type2String[0] = '\0';
8836 PrintExpression(exp.op.exp1, expString1);
8837 ChangeCh(expString1, '\n', ' ');
8838 PrintExpression(exp.op.exp2, expString2);
8839 ChangeCh(expString2, '\n', ' ');
8840 PrintType(exp.op.exp1.expType, type1String, false, true);
8841 PrintType(exp.op.exp2.expType, type2String, false, true);
8844 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8846 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8848 exp.expType = exp.op.exp1.expType;
8849 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8851 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8853 exp.expType = exp.op.exp2.expType;
8854 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8862 // Maybe this was meant to be an enum...
8863 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8865 Type oldType = exp.op.exp1.expType;
8866 exp.op.exp1.expType = null;
8867 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8870 exp.op.exp1.expType = oldType;
8873 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8874 exp.op.exp1.destType = type2;
8877 // TESTING THIS HERE... LATEST ADDITION
8878 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8880 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8881 exp.op.exp1.destType = type1._class.registered.dataType;
8882 if(type1._class.registered.dataType)
8883 type1._class.registered.dataType.refCount++;
8886 // TESTING THIS HERE... LATEST ADDITION
8887 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8889 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8890 exp.op.exp2.destType = type2._class.registered.dataType;
8891 if(type2._class.registered.dataType)
8892 type2._class.registered.dataType.refCount++;
8896 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8898 if(exp.expType) FreeType(exp.expType);
8899 exp.expType = exp.op.exp1.destType;
8900 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8904 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8906 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8908 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8909 // Convert e.g. / 4 into / 4.0
8910 exp.op.exp1.destType = type2._class.registered.dataType;
8911 if(type2._class.registered.dataType)
8912 type2._class.registered.dataType.refCount++;
8913 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8915 if(exp.op.op == '!')
8917 exp.expType = MkClassType("bool");
8918 exp.expType.truth = true;
8922 exp.expType = type2;
8923 if(type2) type2.refCount++;
8926 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8928 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8930 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8931 // Convert e.g. / 4 into / 4.0
8932 exp.op.exp2.destType = type1._class.registered.dataType;
8933 if(type1._class.registered.dataType)
8934 type1._class.registered.dataType.refCount++;
8935 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8937 exp.expType = type1;
8938 if(type1) type1.refCount++;
8943 if(exp.op.exp1 && !exp.op.exp1.expType)
8945 char expString[10000];
8946 expString[0] = '\0';
8949 PrintExpression(exp.op.exp1, expString);
8950 ChangeCh(expString, '\n', ' ');
8953 Compiler_Error($"couldn't determine type of %s\n", expString);
8955 if(exp.op.exp2 && !exp.op.exp2.expType)
8957 char expString[10240];
8958 expString[0] = '\0';
8961 PrintExpression(exp.op.exp2, expString);
8962 ChangeCh(expString, '\n', ' ');
8965 Compiler_Error($"couldn't determine type of %s\n", expString);
8970 FreeType(exp.expType);
8971 exp.expType = MkClassType("bool");
8972 exp.expType.truth = true;
8975 if(exp.op.op != SIZEOF)
8976 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8977 (!exp.op.exp2 || exp.op.exp2.isConstant);
8979 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8981 DeclareType(exp.op.exp2.expType, false, false);
8992 case extensionExpressionExp:
8995 exp.isConstant = true;
8996 for(e = exp.list->first; e; e = e.next)
9001 FreeType(e.destType);
9002 e.opDestType = exp.opDestType;
9003 e.destType = exp.destType;
9004 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
9006 ProcessExpressionType(e);
9008 exp.destType.count--;
9009 if(!exp.expType && !e.next)
9011 exp.expType = e.expType;
9012 if(e.expType) e.expType.refCount++;
9015 exp.isConstant = false;
9018 // In case a cast became a member...
9019 e = exp.list->first;
9020 if(!e.next && e.type == memberExp)
9022 // Preserve prev, next
9023 Expression next = exp.next, prev = exp.prev;
9026 FreeType(exp.expType);
9027 FreeType(exp.destType);
9037 ProcessExpressionType(exp);
9044 exp.isConstant = true;
9046 ProcessExpressionType(exp.index.exp);
9047 if(!exp.index.exp.isConstant)
9048 exp.isConstant = false;
9050 if(exp.index.exp.expType)
9052 Type source = exp.index.exp.expType;
9053 if(source.kind == classType && source._class && source._class.registered)
9055 Class _class = source._class.registered;
9056 Class c = _class.templateClass ? _class.templateClass : _class;
9057 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9059 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9061 if(exp.index.index && exp.index.index->last)
9063 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9069 for(e = exp.index.index->first; e; e = e.next)
9071 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9073 if(e.destType) FreeType(e.destType);
9074 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9076 ProcessExpressionType(e);
9079 // Check if this type is int
9082 exp.isConstant = false;
9086 exp.expType = Dereference(exp.index.exp.expType);
9088 DeclareType(exp.expType, false, false);
9095 Type methodType = null;
9101 PrintExpression(exp.call.exp, name);
9102 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9104 //exp.call.exp.expType = null;
9105 PrintExpression(exp.call.exp, name);
9108 if(exp.call.exp.type == identifierExp)
9110 Expression idExp = exp.call.exp;
9111 Identifier id = idExp.identifier;
9112 if(!strcmp(id.string, "__builtin_frame_address"))
9114 exp.expType = ProcessTypeString("void *", true);
9115 if(exp.call.arguments && exp.call.arguments->first)
9116 ProcessExpressionType(exp.call.arguments->first);
9119 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9121 exp.expType = ProcessTypeString("int", true);
9122 if(exp.call.arguments && exp.call.arguments->first)
9123 ProcessExpressionType(exp.call.arguments->first);
9126 else if(!strcmp(id.string, "Max") ||
9127 !strcmp(id.string, "Min") ||
9128 !strcmp(id.string, "Sgn") ||
9129 !strcmp(id.string, "Abs"))
9131 Expression a = null;
9132 Expression b = null;
9133 Expression tempExp1 = null, tempExp2 = null;
9134 if((!strcmp(id.string, "Max") ||
9135 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9137 a = exp.call.arguments->first;
9138 b = exp.call.arguments->last;
9142 else if(exp.call.arguments->count == 1)
9144 a = exp.call.arguments->first;
9150 exp.call.arguments->Clear();
9151 idExp.identifier = null;
9153 FreeExpContents(exp);
9155 ProcessExpressionType(a);
9157 ProcessExpressionType(b);
9159 exp.type = bracketsExp;
9160 exp.list = MkList();
9162 if(a.expType && (!b || b.expType))
9164 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9166 // Use the simpleStruct name/ids for now...
9169 OldList * specs = MkList();
9170 OldList * decls = MkList();
9172 char temp1[1024], temp2[1024];
9174 GetTypeSpecs(a.expType, specs);
9176 if(a && !a.isConstant && a.type != identifierExp)
9178 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9179 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9180 tempExp1 = QMkExpId(temp1);
9181 tempExp1.expType = a.expType;
9183 a.expType.refCount++;
9184 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9186 if(b && !b.isConstant && b.type != identifierExp)
9188 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9189 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9190 tempExp2 = QMkExpId(temp2);
9191 tempExp2.expType = b.expType;
9193 b.expType.refCount++;
9194 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9197 decl = MkDeclaration(specs, decls);
9198 if(!curCompound.compound.declarations)
9199 curCompound.compound.declarations = MkList();
9200 curCompound.compound.declarations->Insert(null, decl);
9205 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9207 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9209 MkExpCondition(MkExpBrackets(MkListOne(
9210 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9211 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9212 exp.expType = a.expType;
9214 a.expType.refCount++;
9216 else if(!strcmp(id.string, "Abs"))
9219 MkExpCondition(MkExpBrackets(MkListOne(
9220 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9221 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9222 exp.expType = a.expType;
9224 a.expType.refCount++;
9226 else if(!strcmp(id.string, "Sgn"))
9228 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9230 MkExpCondition(MkExpBrackets(MkListOne(
9231 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9232 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9233 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9234 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9235 exp.expType = ProcessTypeString("int", false);
9238 FreeExpression(tempExp1);
9239 if(tempExp2) FreeExpression(tempExp2);
9253 if(!exp.call.exp.destType)
9255 exp.call.exp.destType = dummy;
9258 ProcessExpressionType(exp.call.exp);
9259 if(exp.call.exp.destType == dummy)
9262 exp.call.exp.destType = null;
9267 // Check argument types against parameter types
9268 functionType = exp.call.exp.expType;
9270 if(functionType && functionType.kind == TypeKind::methodType)
9272 methodType = functionType;
9273 functionType = methodType.method.dataType;
9275 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9276 // TOCHECK: Instead of doing this here could this be done per param?
9277 if(exp.call.exp.expType.usedClass)
9279 char typeString[1024];
9280 typeString[0] = '\0';
9282 Symbol back = functionType.thisClass;
9283 // Do not output class specifier here (thisclass was added to this)
9284 functionType.thisClass = null;
9285 PrintType(functionType, typeString, true, true);
9286 functionType.thisClass = back;
9288 if(strstr(typeString, "thisclass"))
9290 OldList * specs = MkList();
9293 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9295 decl = SpecDeclFromString(typeString, specs, null);
9297 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9298 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9299 exp.call.exp.expType.usedClass))
9300 thisClassParams = false;
9302 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9304 Class backupThisClass = thisClass;
9305 thisClass = exp.call.exp.expType.usedClass;
9306 ProcessDeclarator(decl);
9307 thisClass = backupThisClass;
9310 thisClassParams = true;
9312 functionType = ProcessType(specs, decl);
9313 functionType.refCount = 0;
9314 FinishTemplatesContext(context);
9317 FreeList(specs, FreeSpecifier);
9318 FreeDeclarator(decl);
9322 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9324 Type type = functionType.type;
9325 if(!functionType.refCount)
9327 functionType.type = null;
9328 FreeType(functionType);
9330 //methodType = functionType;
9331 functionType = type;
9333 if(functionType && functionType.kind != TypeKind::functionType)
9335 Compiler_Error($"called object %s is not a function\n", name);
9337 else if(functionType)
9339 bool emptyParams = false, noParams = false;
9340 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9341 Type type = functionType.params.first;
9342 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9344 Location oldyylloc = yylloc;
9346 if(!type) emptyParams = true;
9349 if(functionType.extraParam && e && functionType.thisClass)
9351 e.destType = MkClassType(functionType.thisClass.string);
9355 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9356 // Fixed #141 by adding '&& !functionType.extraParam'
9357 if(!functionType.staticMethod && !functionType.extraParam)
9359 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9360 memberExp.member.exp.expType._class)
9362 type = MkClassType(memberExp.member.exp.expType._class.string);
9367 type = functionType.params.first;
9372 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9374 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9375 type.byReference = functionType.byReference;
9376 type.typedByReference = functionType.typedByReference;
9379 // Allow manually passing a class for typed object
9380 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9384 type = functionType.params.first;
9392 if(type && type.kind == voidType)
9395 if(!type.refCount) FreeType(type);
9399 for( ; e; e = e.next)
9401 if(!type && !emptyParams)
9404 if(methodType && methodType.methodClass)
9405 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9406 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9407 noParams ? 0 : functionType.params.count);
9409 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9410 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9411 noParams ? 0 : functionType.params.count);
9415 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9417 Type templatedType = null;
9418 Class _class = methodType.usedClass;
9419 ClassTemplateParameter curParam = null;
9421 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9424 for(sClass = _class; sClass; sClass = sClass.base)
9426 if(sClass.templateClass) sClass = sClass.templateClass;
9428 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9430 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9433 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9435 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9436 id += nextClass.templateParams.count;
9445 if(curParam && _class.templateArgs[id].dataTypeString)
9447 ClassTemplateArgument arg = _class.templateArgs[id];
9449 Context context = SetupTemplatesContext(_class);
9452 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9453 templatedType = ProcessTypeString(arg.dataTypeString, false);
9454 FinishTemplatesContext(context);
9456 e.destType = templatedType;
9459 templatedType.passAsTemplate = true;
9460 // templatedType.refCount++;
9466 if(type) type.refCount++;
9471 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9473 e.destType = type.prev;
9474 e.destType.refCount++;
9479 if(type) type.refCount++;
9482 // Don't reach the end for the ellipsis
9483 if(type && type.kind != ellipsisType)
9485 Type next = type.next;
9486 if(!type.refCount) FreeType(type);
9491 if(type && type.kind != ellipsisType)
9493 if(methodType && methodType.methodClass)
9494 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9495 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9496 functionType.params.count + extra);
9498 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9499 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9500 functionType.params.count + extra);
9503 if(type && !type.refCount) FreeType(type);
9510 kind = TypeKind::functionType;
9513 if(exp.call.exp.type == identifierExp)
9515 char * string = exp.call.exp.identifier.string;
9519 Location oldyylloc = yylloc;
9521 yylloc = exp.call.exp.identifier.loc;
9522 if(strstr(string, "__builtin_") == string)
9526 functionType.returnType = exp.destType;
9527 exp.destType.refCount++;
9531 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9532 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9533 globalContext.symbols.Add((BTNode)symbol);
9534 if(strstr(symbol.string, "::"))
9535 globalContext.hasNameSpace = true;
9540 else if(exp.call.exp.type == memberExp)
9542 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9543 exp.call.exp.member.member.string);*/
9546 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9548 if(!functionType.returnType)
9550 functionType.returnType = Type
9557 if(functionType && functionType.kind == TypeKind::functionType)
9559 exp.expType = functionType.returnType;
9561 if(functionType.returnType)
9562 functionType.returnType.refCount++;
9564 if(!functionType.refCount)
9565 FreeType(functionType);
9568 if(exp.call.arguments)
9570 for(e = exp.call.arguments->first; e; e = e.next)
9572 Type destType = e.destType;
9573 ProcessExpressionType(e);
9581 Location oldyylloc = yylloc;
9583 Expression checkExp = exp.member.exp;
9586 if(checkExp.type == castExp)
9587 checkExp = checkExp.cast.exp;
9588 else if(checkExp.type == bracketsExp)
9589 checkExp = checkExp.list ? checkExp.list->first : null;
9594 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9595 exp.thisPtr = thisPtr;
9597 // DOING THIS LATER NOW...
9598 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9600 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9601 /* TODO: Name Space Fix ups
9602 if(!exp.member.member.classSym)
9603 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9607 ProcessExpressionType(exp.member.exp);
9608 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9609 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9611 exp.isConstant = false;
9614 exp.isConstant = exp.member.exp.isConstant;
9615 type = exp.member.exp.expType;
9619 if(type && (type.kind == templateType))
9621 Class _class = thisClass ? thisClass : currentClass;
9622 ClassTemplateParameter param = null;
9625 for(param = _class.templateParams.first; param; param = param.next)
9627 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9631 if(param && param.defaultArg.member)
9633 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9636 Expression expMember = exp.member.exp;
9638 OldList * specs = MkList();
9639 char thisClassTypeString[1024];
9641 FreeIdentifier(exp.member.member);
9643 ProcessExpressionType(argExp);
9646 char * colon = strstr(param.defaultArg.memberString, "::");
9649 char className[1024];
9652 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9653 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9656 strcpy(thisClassTypeString, _class.fullName);
9659 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9661 exp.expType = ProcessType(specs, decl);
9662 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9664 Class expClass = exp.expType._class.registered;
9665 Class cClass = null;
9670 char templateString[1024];
9671 ClassTemplateParameter param;
9672 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9673 for(cClass = expClass; cClass; cClass = cClass.base)
9676 for(param = cClass.templateParams.first; param; param = param.next)
9680 ClassTemplateArgument arg;
9681 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9682 arg = expClass.templateArgs[id];
9684 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9686 ClassTemplateParameter cParam;
9687 //int p = numParams - sClass.templateParams.count;
9690 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9692 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9694 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9696 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9698 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9699 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9711 strcat(argument, arg.name.string);
9712 strcat(argument, " = ");
9718 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9719 char expString[1024];
9720 OldList * specs = MkList();
9721 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9723 char * string = PrintHexUInt64(arg.expression.ui64);
9724 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9727 ProcessExpressionType(exp);
9728 ComputeExpression(exp);
9729 expString[0] = '\0';
9730 PrintExpression(exp, expString);
9731 strcat(argument, expString);
9733 FreeExpression(exp);
9738 strcat(argument, arg.member.name);
9741 case TemplateParameterType::type:
9743 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9745 if(!strcmp(arg.dataTypeString, "thisclass"))
9746 strcat(argument, thisClassTypeString);
9748 strcat(argument, arg.dataTypeString);
9755 if(paramCount) strcat(templateString, ", ");
9756 if(lastParam != p - 1)
9758 strcat(templateString, param.name);
9759 strcat(templateString, " = ");
9761 strcat(templateString, argument);
9770 int len = strlen(templateString);
9771 if(templateString[len-1] == '>') templateString[len++] = ' ';
9772 templateString[len++] = '>';
9773 templateString[len++] = '\0';
9776 Context context = SetupTemplatesContext(_class);
9777 FreeType(exp.expType);
9778 exp.expType = ProcessTypeString(templateString, false);
9779 FinishTemplatesContext(context);
9783 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9784 exp.type = bracketsExp;
9785 exp.list = MkListOne(MkExpOp(null, '*',
9790 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9791 MkExpBrackets(MkListOne(
9792 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9794 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9796 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9801 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9802 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9804 type = ProcessTemplateParameterType(type.templateParameter);
9807 // TODO: *** This seems to be where we should add method support for all basic types ***
9808 if(type && (type.kind == templateType));
9809 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9810 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
9811 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9812 (type.kind == pointerType && type.type.kind == charType)))
9814 Identifier id = exp.member.member;
9815 TypeKind typeKind = type.kind;
9816 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9817 if(typeKind == subClassType && exp.member.exp.type == classExp)
9819 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9820 typeKind = classType;
9825 if(typeKind == intType || typeKind == enumType)
9826 _class = eSystem_FindClass(privateModule, "int");
9829 if(type.kind == classType && type._class && type._class.registered)
9831 _class = type._class.registered;
9833 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
9835 _class = FindClass("char *").registered;
9837 else if(type.kind == pointerType)
9839 _class = eSystem_FindClass(privateModule, "uintptr");
9840 FreeType(exp.expType);
9841 exp.expType = ProcessTypeString("uintptr", false);
9842 exp.byReference = true;
9846 char string[1024] = "";
9848 PrintTypeNoConst(type, string, false, true);
9849 classSym = FindClass(string);
9850 if(classSym) _class = classSym.registered;
9858 (exp.member.exp.type == identifierExp &&
9859 !strcmp(exp.member.exp.identifier.string, "this"));*/
9860 Property prop = null;
9861 Method method = null;
9862 DataMember member = null;
9863 Property revConvert = null;
9864 ClassProperty classProp = null;
9866 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9867 exp.member.memberType = propertyMember;
9869 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9870 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9872 if(typeKind != subClassType)
9874 // Prioritize data members over properties for "this"
9875 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9877 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9878 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9880 prop = eClass_FindProperty(_class, id.string, privateModule);
9884 if(!member && !prop)
9885 prop = eClass_FindProperty(_class, id.string, privateModule);
9886 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9887 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9888 exp.member.thisPtr = true;
9890 // Prioritize properties over data members otherwise
9893 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9896 prop = eClass_FindProperty(_class, id.string, null);
9897 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9898 member = eClass_FindDataMember(_class, id.string, null, null, null);
9901 if(!prop && !member)
9903 method = eClass_FindMethod(_class, id.string, null);
9906 prop = eClass_FindProperty(_class, id.string, privateModule);
9907 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9908 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9914 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9921 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
9922 method = eClass_FindMethod(_class, id.string, privateModule);
9923 if(!prop && !member && !method)
9925 if(typeKind == subClassType)
9927 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9930 exp.member.memberType = classPropertyMember;
9931 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9935 // Assume this is a class_data member
9936 char structName[1024];
9937 Identifier id = exp.member.member;
9938 Expression classExp = exp.member.exp;
9941 FreeType(classExp.expType);
9942 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9944 strcpy(structName, "__ecereClassData_");
9945 FullClassNameCat(structName, type._class.string, false);
9946 exp.type = pointerExp;
9947 exp.member.member = id;
9949 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9950 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9951 MkExpBrackets(MkListOne(MkExpOp(
9952 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9953 MkExpMember(classExp, MkIdentifier("data"))), '+',
9954 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9959 ProcessExpressionType(exp);
9965 // Check for reverse conversion
9966 // (Convert in an instantiation later, so that we can use
9967 // deep properties system)
9968 Symbol classSym = FindClass(id.string);
9971 Class convertClass = classSym.registered;
9973 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9980 exp.member.memberType = propertyMember;
9982 ProcessPropertyType(prop);
9983 exp.expType = prop.dataType;
9984 if(prop.dataType) prop.dataType.refCount++;
9988 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9990 FreeExpContents(exp);
9991 exp.type = identifierExp;
9992 exp.identifier = MkIdentifier("class");
9993 ProcessExpressionType(exp);
9997 exp.member.memberType = dataMember;
9998 DeclareStruct(_class.fullName, false);
9999 if(!member.dataType)
10001 Context context = SetupTemplatesContext(_class);
10002 member.dataType = ProcessTypeString(member.dataTypeString, false);
10003 FinishTemplatesContext(context);
10005 exp.expType = member.dataType;
10006 if(member.dataType) member.dataType.refCount++;
10008 else if(revConvert)
10010 exp.member.memberType = reverseConversionMember;
10011 exp.expType = MkClassType(revConvert._class.fullName);
10019 exp.type = identifierExp;
10020 exp.identifier = exp.member.member;
10023 exp.member.memberType = methodMember;
10025 if(!method.dataType)
10026 ProcessMethodType(method);
10034 // Tricky spot here... To use instance versus class virtual table
10035 // Put it back to what it was... What did we break?
10037 // Had to put it back for overriding Main of Thread global instance
10039 //exp.expType.methodClass = _class;
10040 exp.expType.methodClass = (id && id._class) ? _class : null;
10042 // Need the actual class used for templated classes
10043 exp.expType.usedClass = _class;
10045 else if(!classProp)
10047 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10049 FreeExpContents(exp);
10050 exp.type = identifierExp;
10051 exp.identifier = MkIdentifier("class");
10052 FreeType(exp.expType);
10053 exp.expType = MkClassType("ecere::com::Class");
10056 yylloc = exp.member.member.loc;
10057 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10059 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10062 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10067 while(tClass && !tClass.templateClass) tClass = tClass.base;
10069 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10072 ClassTemplateParameter curParam = null;
10075 for(sClass = tClass; sClass; sClass = sClass.base)
10078 if(sClass.templateClass) sClass = sClass.templateClass;
10079 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10081 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10083 for(sClass = sClass.base; sClass; sClass = sClass.base)
10084 id += sClass.templateParams.count;
10089 if(curParam) break;
10092 if(curParam && tClass.templateArgs[id].dataTypeString)
10094 ClassTemplateArgument arg = tClass.templateArgs[id];
10095 Context context = SetupTemplatesContext(tClass);
10096 /*if(!arg.dataType)
10097 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10098 FreeType(exp.expType);
10099 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10102 if(exp.expType.kind == thisClassType)
10104 FreeType(exp.expType);
10105 exp.expType = ReplaceThisClassType(_class);
10108 if(tClass.templateClass)
10109 exp.expType.passAsTemplate = true;
10110 //exp.expType.refCount++;
10113 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10114 //exp.destType.refCount++;
10116 if(exp.destType.kind == thisClassType)
10118 FreeType(exp.destType);
10119 exp.destType = ReplaceThisClassType(_class);
10123 FinishTemplatesContext(context);
10126 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10127 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10130 ClassTemplateParameter curParam = null;
10133 for(sClass = tClass; sClass; sClass = sClass.base)
10136 if(sClass.templateClass) sClass = sClass.templateClass;
10137 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10139 if(curParam.type == TemplateParameterType::type &&
10140 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10142 for(sClass = sClass.base; sClass; sClass = sClass.base)
10143 id += sClass.templateParams.count;
10148 if(curParam) break;
10153 ClassTemplateArgument arg = tClass.templateArgs[id];
10154 Context context = SetupTemplatesContext(tClass);
10156 /*if(!arg.dataType)
10157 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10159 basicType = ProcessTypeString(arg.dataTypeString, false);
10162 if(basicType.kind == thisClassType)
10164 FreeType(basicType);
10165 basicType = ReplaceThisClassType(_class);
10168 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10169 if(tClass.templateClass)
10170 basicType.passAsTemplate = true;
10173 FreeType(exp.expType);
10175 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10176 //exp.expType.refCount++;
10179 exp.destType = exp.expType;
10180 exp.destType.refCount++;
10184 Expression newExp { };
10185 OldList * specs = MkList();
10187 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10189 if(exp.destType) exp.destType.refCount++;
10190 if(exp.expType) exp.expType.refCount++;
10191 exp.type = castExp;
10192 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10193 exp.cast.exp = newExp;
10194 //FreeType(exp.expType);
10195 //exp.expType = null;
10196 //ProcessExpressionType(sourceExp);
10199 FinishTemplatesContext(context);
10202 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10204 Class expClass = exp.expType._class.registered;
10207 Class cClass = null;
10210 int paramCount = 0;
10211 int lastParam = -1;
10212 char templateString[1024];
10213 ClassTemplateParameter param;
10214 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10215 while(cClass != expClass)
10218 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10221 for(param = cClass.templateParams.first; param; param = param.next)
10223 Class cClassCur = null;
10226 ClassTemplateParameter paramCur = null;
10227 ClassTemplateArgument arg;
10228 while(cClassCur != tClass && !paramCur)
10231 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10232 cClassCur = sClassCur;
10234 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10236 if(!strcmp(paramCur.name, param.name))
10244 if(paramCur && paramCur.type == TemplateParameterType::type)
10245 arg = tClass.templateArgs[cp];
10247 arg = expClass.templateArgs[p];
10250 char argument[256];
10251 argument[0] = '\0';
10254 strcat(argument, arg.name.string);
10255 strcat(argument, " = ");
10261 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10262 char expString[1024];
10263 OldList * specs = MkList();
10264 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10266 char * string = PrintHexUInt64(arg.expression.ui64);
10267 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10270 ProcessExpressionType(exp);
10271 ComputeExpression(exp);
10272 expString[0] = '\0';
10273 PrintExpression(exp, expString);
10274 strcat(argument, expString);
10276 FreeExpression(exp);
10281 strcat(argument, arg.member.name);
10284 case TemplateParameterType::type:
10286 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10287 strcat(argument, arg.dataTypeString);
10293 if(paramCount) strcat(templateString, ", ");
10294 if(lastParam != p - 1)
10296 strcat(templateString, param.name);
10297 strcat(templateString, " = ");
10299 strcat(templateString, argument);
10308 int len = strlen(templateString);
10309 if(templateString[len-1] == '>') templateString[len++] = ' ';
10310 templateString[len++] = '>';
10311 templateString[len++] = '\0';
10314 FreeType(exp.expType);
10316 Context context = SetupTemplatesContext(tClass);
10317 exp.expType = ProcessTypeString(templateString, false);
10318 FinishTemplatesContext(context);
10325 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10327 else if(type && (type.kind == structType || type.kind == unionType))
10329 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10332 exp.expType = memberType;
10334 memberType.refCount++;
10339 char expString[10240];
10340 expString[0] = '\0';
10341 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10342 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10345 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10347 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10349 Identifier id = exp.member.member;
10350 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10353 FreeType(exp.expType);
10354 exp.expType = ReplaceThisClassType(_class);
10358 yylloc = oldyylloc;
10361 // Convert x->y into (*x).y
10364 Type destType = exp.destType;
10366 // DOING THIS LATER NOW...
10367 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10369 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10370 /* TODO: Name Space Fix ups
10371 if(!exp.member.member.classSym)
10372 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10376 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10377 exp.type = memberExp;
10380 ProcessExpressionType(exp);
10387 //ComputeExpression(exp);
10389 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10390 if(classSym && classSym.registered)
10392 if(classSym.registered.type == noHeadClass)
10396 DeclareStruct(classSym.string, false);
10397 FreeSpecifier(exp._class);
10398 exp.type = typeSizeExp;
10399 FullClassNameCat(name, classSym.string, false);
10400 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10404 if(classSym.registered.fixed)
10406 FreeSpecifier(exp._class);
10407 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10408 exp.type = constantExp;
10412 char className[1024];
10413 strcpy(className, "__ecereClass_");
10414 FullClassNameCat(className, classSym.string, true);
10415 MangleClassName(className);
10417 DeclareClass(classSym, className);
10419 FreeExpContents(exp);
10420 exp.type = pointerExp;
10421 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10422 exp.member.member = MkIdentifier("structSize");
10430 kind = intSizeType;
10432 // exp.isConstant = true;
10437 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10442 kind = intSizeType;
10444 exp.isConstant = true;
10446 DeclareType(type, false, false);
10452 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10454 FreeType(exp.cast.exp.destType);
10455 exp.cast.exp.destType = type;
10457 ProcessExpressionType(exp.cast.exp);
10459 exp.expType = type;
10462 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10463 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10465 void * prev = exp.prev, * next = exp.next;
10466 Type expType = exp.cast.exp.destType;
10467 Expression castExp = exp.cast.exp;
10468 Type destType = exp.destType;
10470 if(expType) expType.refCount++;
10472 //FreeType(exp.destType);
10473 FreeType(exp.expType);
10474 FreeTypeName(exp.cast.typeName);
10477 FreeType(exp.expType);
10478 FreeType(exp.destType);
10480 exp.expType = expType;
10481 exp.destType = destType;
10491 exp.isConstant = exp.cast.exp.isConstant;
10496 case extensionInitializerExp:
10498 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10499 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10500 // ProcessInitializer(exp.initializer.initializer, type);
10501 exp.expType = type;
10506 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10507 ProcessExpressionType(exp.vaArg.exp);
10508 exp.expType = type;
10514 exp.isConstant = true;
10516 FreeType(exp.cond.cond.destType);
10517 exp.cond.cond.destType = MkClassType("bool");
10518 exp.cond.cond.destType.truth = true;
10519 ProcessExpressionType(exp.cond.cond);
10520 if(!exp.cond.cond.isConstant)
10521 exp.isConstant = false;
10522 for(e = exp.cond.exp->first; e; e = e.next)
10526 FreeType(e.destType);
10527 e.destType = exp.destType;
10528 if(e.destType) e.destType.refCount++;
10530 ProcessExpressionType(e);
10533 exp.expType = e.expType;
10534 if(e.expType) e.expType.refCount++;
10537 exp.isConstant = false;
10540 FreeType(exp.cond.elseExp.destType);
10541 // Added this check if we failed to find an expType
10542 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10545 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10547 if(exp.cond.elseExp.destType)
10548 exp.cond.elseExp.destType.refCount++;
10549 ProcessExpressionType(exp.cond.elseExp);
10551 // FIXED THIS: Was done before calling process on elseExp
10552 if(!exp.cond.elseExp.isConstant)
10553 exp.isConstant = false;
10556 case extensionCompoundExp:
10558 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10560 Statement last = exp.compound.compound.statements->last;
10561 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10563 ((Expression)last.expressions->last).destType = exp.destType;
10565 exp.destType.refCount++;
10567 ProcessStatement(exp.compound);
10568 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10570 exp.expType.refCount++;
10576 Specifier spec = exp._classExp.specifiers->first;
10577 if(spec && spec.type == nameSpecifier)
10579 exp.expType = MkClassType(spec.name);
10580 exp.expType.kind = subClassType;
10581 exp.byReference = true;
10585 exp.expType = MkClassType("ecere::com::Class");
10586 exp.byReference = true;
10592 Class _class = thisClass ? thisClass : currentClass;
10595 Identifier id = exp.classData.id;
10596 char structName[1024];
10597 Expression classExp;
10598 strcpy(structName, "__ecereClassData_");
10599 FullClassNameCat(structName, _class.fullName, false);
10600 exp.type = pointerExp;
10601 exp.member.member = id;
10602 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10603 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10605 classExp = MkExpIdentifier(MkIdentifier("class"));
10607 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10608 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10609 MkExpBrackets(MkListOne(MkExpOp(
10610 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10611 MkExpMember(classExp, MkIdentifier("data"))), '+',
10612 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10615 ProcessExpressionType(exp);
10623 char * typeString = null;
10624 char typeStringBuf[1024];
10625 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10626 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10628 Class templateClass = exp.destType._class.registered;
10629 typeString = templateClass.templateArgs[2].dataTypeString;
10633 // Guess type from expressions in the array
10635 for(e = exp.list->first; e; e = e.next)
10637 ProcessExpressionType(e);
10640 if(!type) { type = e.expType; type.refCount++; }
10643 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10644 if(!MatchTypeExpression(e, type, null, false))
10650 e = exp.list->first;
10651 ProcessExpressionType(e);
10654 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10655 if(!MatchTypeExpression(e, type, null, false))
10657 FreeType(e.expType);
10668 FreeType(e.expType);
10675 typeStringBuf[0] = '\0';
10676 PrintTypeNoConst(type, typeStringBuf, false, true);
10677 typeString = typeStringBuf;
10685 (Container)& (struct BuiltInContainer)
10687 ._vTbl = class(BuiltInContainer)._vTbl,
10688 ._class = class(BuiltInContainer),
10690 .data = (int[]){ 1, 7, 3, 4, 5 },
10692 .type = class(int),
10695 char templateString[1024];
10696 OldList * initializers = MkList();
10697 OldList * structInitializers = MkList();
10698 OldList * specs = MkList();
10700 Declarator decl = SpecDeclFromString(typeString, specs, null);
10701 sprintf(templateString, "Container<%s>", typeString);
10706 type = ProcessTypeString(typeString, false);
10707 while(e = exp.list->first)
10709 exp.list->Remove(e);
10712 ProcessExpressionType(e);
10713 ListAdd(initializers, MkInitializerAssignment(e));
10719 DeclareStruct("ecere::com::BuiltInContainer", false);
10721 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10722 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10723 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10724 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10725 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10726 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10727 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10728 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10729 MkInitializerList(initializers))));
10730 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10731 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10732 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10733 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10734 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10735 exp.expType = ProcessTypeString(templateString, false);
10736 exp.type = bracketsExp;
10737 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10739 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10740 MkInitializerList(structInitializers)))));
10741 ProcessExpressionType(expExt);
10745 exp.expType = ProcessTypeString("Container", false);
10746 Compiler_Error($"Couldn't determine type of array elements\n");
10752 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10754 FreeType(exp.expType);
10755 exp.expType = ReplaceThisClassType(thisClass);
10758 // Resolve structures here
10759 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10761 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10762 // TODO: Fix members reference...
10765 if(exp.expType.kind != enumType)
10768 String enumName = CopyString(exp.expType.enumName);
10770 // Fixed a memory leak on self-referencing C structs typedefs
10771 // by instantiating a new type rather than simply copying members
10772 // into exp.expType
10773 FreeType(exp.expType);
10774 exp.expType = Type { };
10775 exp.expType.kind = symbol.type.kind;
10776 exp.expType.refCount++;
10777 exp.expType.enumName = enumName;
10779 exp.expType.members = symbol.type.members;
10780 for(member = symbol.type.members.first; member; member = member.next)
10786 for(member = symbol.type.members.first; member; member = member.next)
10788 NamedLink value { name = CopyString(member.name) };
10789 exp.expType.members.Add(value);
10796 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10797 else if(exp.destType && !exp.destType.keepCast)
10799 if(!CheckExpressionType(exp, exp.destType, false))
10801 if(!exp.destType.count || unresolved)
10806 if(exp.destType.kind != ellipsisType)
10812 char expString[10240];
10813 expString[0] = '\0';
10815 PrintType(exp.destType, type2, false, true);
10817 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10819 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10820 else if(exp.type != dummyExp)
10821 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10826 char expString[10240] ;
10827 expString[0] = '\0';
10828 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10831 Compiler_Error($"unresolved identifier %s\n", expString);
10832 else if(exp.type != dummyExp)
10833 Compiler_Error($"couldn't determine type of %s\n", expString);
10844 PrintType(exp.expType, type1, false, true);
10845 PrintType(exp.destType, type2, false, true);
10848 //CheckExpressionType(exp, exp.destType, false);
10850 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10851 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10852 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10855 char expString[10240];
10856 expString[0] = '\0';
10857 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10860 CheckExpressionType(exp, exp.destType, false);
10862 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10863 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10864 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10866 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10867 FreeType(exp.expType);
10868 exp.destType.refCount++;
10869 exp.expType = exp.destType;
10874 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10876 Expression newExp { };
10877 char typeString[1024];
10878 OldList * specs = MkList();
10881 typeString[0] = '\0';
10885 if(exp.expType) exp.expType.refCount++;
10886 if(exp.expType) exp.expType.refCount++;
10887 exp.type = castExp;
10888 newExp.destType = exp.expType;
10890 PrintType(exp.expType, typeString, false, false);
10891 decl = SpecDeclFromString(typeString, specs, null);
10893 exp.cast.typeName = MkTypeName(specs, decl);
10894 exp.cast.exp = newExp;
10897 else if(unresolved)
10899 if(exp.identifier._class && exp.identifier._class.name)
10900 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10901 else if(exp.identifier.string && exp.identifier.string[0])
10902 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10904 else if(!exp.expType && exp.type != dummyExp)
10906 char expString[10240];
10907 expString[0] = '\0';
10908 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10909 Compiler_Error($"couldn't determine type of %s\n", expString);
10912 // Let's try to support any_object & typed_object here:
10914 ApplyAnyObjectLogic(exp);
10916 // Mark nohead classes as by reference, unless we're casting them to an integral type
10917 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10918 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
10919 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
10920 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
10922 exp.byReference = true;
10924 yylloc = oldyylloc;
10927 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10929 // THIS CODE WILL FIND NEXT MEMBER...
10932 *curMember = (*curMember).next;
10934 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10936 *curMember = subMemberStack[--(*subMemberStackPos)];
10937 *curMember = (*curMember).next;
10940 // SKIP ALL PROPERTIES HERE...
10941 while((*curMember) && (*curMember).isProperty)
10942 *curMember = (*curMember).next;
10944 if(subMemberStackPos)
10946 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10948 subMemberStack[(*subMemberStackPos)++] = *curMember;
10950 *curMember = (*curMember).members.first;
10951 while(*curMember && (*curMember).isProperty)
10952 *curMember = (*curMember).next;
10960 if(subMemberStackPos && *subMemberStackPos)
10962 *curMember = subMemberStack[--(*subMemberStackPos)];
10963 *curMember = (*curMember).next;
10967 Class lastCurClass = *curClass;
10969 if(*curClass == _class) break; // REACHED THE END
10971 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10972 *curMember = (*curClass).membersAndProperties.first;
10975 while((*curMember) && (*curMember).isProperty)
10976 *curMember = (*curMember).next;
10977 if(subMemberStackPos)
10979 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10981 subMemberStack[(*subMemberStackPos)++] = *curMember;
10983 *curMember = (*curMember).members.first;
10984 while(*curMember && (*curMember).isProperty)
10985 *curMember = (*curMember).next;
10993 static void ProcessInitializer(Initializer init, Type type)
10997 case expInitializer:
10998 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11000 // TESTING THIS FOR SHUTTING = 0 WARNING
11001 if(init.exp && !init.exp.destType)
11003 FreeType(init.exp.destType);
11004 init.exp.destType = type;
11005 if(type) type.refCount++;
11009 ProcessExpressionType(init.exp);
11010 init.isConstant = init.exp.isConstant;
11016 Expression exp = init.exp;
11017 Instantiation inst = exp.instance;
11018 MembersInit members;
11020 init.type = listInitializer;
11021 init.list = MkList();
11025 for(members = inst.members->first; members; members = members.next)
11027 if(members.type == dataMembersInit)
11030 for(member = members.dataMembers->first; member; member = member.next)
11032 ListAdd(init.list, member.initializer);
11033 member.initializer = null;
11036 // Discard all MembersInitMethod
11039 FreeExpression(exp);
11041 case listInitializer:
11044 Type initializerType = null;
11045 Class curClass = null;
11046 DataMember curMember = null;
11047 DataMember subMemberStack[256];
11048 int subMemberStackPos = 0;
11050 if(type && type.kind == arrayType)
11051 initializerType = Dereference(type);
11052 else if(type && (type.kind == structType || type.kind == unionType))
11053 initializerType = type.members.first;
11055 for(i = init.list->first; i; i = i.next)
11057 if(type && type.kind == classType && type._class && type._class.registered)
11059 // 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)
11060 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11061 // TODO: Generate error on initializing a private data member this way from another module...
11064 if(!curMember.dataType)
11065 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11066 initializerType = curMember.dataType;
11069 ProcessInitializer(i, initializerType);
11070 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11071 initializerType = initializerType.next;
11073 init.isConstant = false;
11076 if(type && type.kind == arrayType)
11077 FreeType(initializerType);
11079 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11081 Compiler_Error($"Assigning list initializer to non list\n");
11088 static void ProcessSpecifier(Specifier spec, bool declareStruct)
11092 case baseSpecifier:
11094 if(spec.specifier == THISCLASS)
11098 spec.type = nameSpecifier;
11099 spec.name = ReplaceThisClass(thisClass);
11100 spec.symbol = FindClass(spec.name);
11101 ProcessSpecifier(spec, declareStruct);
11106 case nameSpecifier:
11108 Symbol symbol = FindType(curContext, spec.name);
11110 DeclareType(symbol.type, true, true);
11111 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
11112 DeclareStruct(spec.name, false);
11115 case enumSpecifier:
11120 for(e = spec.list->first; e; e = e.next)
11123 ProcessExpressionType(e.exp);
11128 case structSpecifier:
11129 case unionSpecifier:
11131 if(spec.definitions)
11134 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11136 ProcessClass(spec.definitions, symbol);
11139 for(def = spec.definitions->first; def; def = def.next)
11141 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11142 ProcessDeclaration(def.decl);
11149 case classSpecifier:
11151 Symbol classSym = FindClass(spec.name);
11152 if(classSym && classSym.registered && classSym.registered.type == structClass)
11153 DeclareStruct(spec.name, false);
11161 static void ProcessDeclarator(Declarator decl)
11165 case identifierDeclarator:
11166 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11168 FreeSpecifier(decl.identifier._class);
11169 decl.identifier._class = null;
11172 case arrayDeclarator:
11174 ProcessExpressionType(decl.array.exp);
11175 case structDeclarator:
11176 case bracketsDeclarator:
11177 case functionDeclarator:
11178 case pointerDeclarator:
11179 case extendedDeclarator:
11180 case extendedDeclaratorEnd:
11181 if(decl.declarator)
11182 ProcessDeclarator(decl.declarator);
11183 if(decl.type == functionDeclarator)
11185 Identifier id = GetDeclId(decl);
11186 if(id && id._class)
11190 qualifiers = MkListOne(id._class);
11193 if(!decl.function.parameters)
11194 decl.function.parameters = MkList();
11195 decl.function.parameters->Insert(null, param);
11198 if(decl.function.parameters)
11202 for(param = decl.function.parameters->first; param; param = param.next)
11204 if(param.qualifiers && param.qualifiers->first)
11206 Specifier spec = param.qualifiers->first;
11207 if(spec && spec.specifier == TYPED_OBJECT)
11209 Declarator d = param.declarator;
11212 qualifiers = MkListOne(MkSpecifier(VOID));
11213 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11216 FreeList(param.qualifiers, FreeSpecifier);
11218 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11219 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11221 decl.function.parameters->Insert(param, newParam);
11224 else if(spec && spec.specifier == ANY_OBJECT)
11226 Declarator d = param.declarator;
11228 FreeList(param.qualifiers, FreeSpecifier);
11230 param.qualifiers = MkListOne(MkSpecifier(VOID));
11231 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11233 else if(spec.specifier == THISCLASS)
11237 spec.type = nameSpecifier;
11238 spec.name = ReplaceThisClass(thisClass);
11239 spec.symbol = FindClass(spec.name);
11240 ProcessSpecifier(spec, false);
11245 if(param.declarator)
11246 ProcessDeclarator(param.declarator);
11254 static void ProcessDeclaration(Declaration decl)
11259 case initDeclaration:
11261 bool declareStruct = false;
11263 lineNum = decl.pos.line;
11264 column = decl.pos.col;
11267 if(decl.declarators)
11271 for(d = decl.declarators->first; d; d = d.next)
11273 Type type, subType;
11274 ProcessDeclarator(d.declarator);
11276 type = ProcessType(decl.specifiers, d.declarator);
11280 ProcessInitializer(d.initializer, type);
11282 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11284 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11285 d.initializer.exp.type == instanceExp)
11287 if(type.kind == classType && type._class ==
11288 d.initializer.exp.expType._class)
11290 Instantiation inst = d.initializer.exp.instance;
11291 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11293 d.initializer.exp.instance = null;
11294 if(decl.specifiers)
11295 FreeList(decl.specifiers, FreeSpecifier);
11296 FreeList(decl.declarators, FreeInitDeclarator);
11300 decl.type = instDeclaration;
11305 for(subType = type; subType;)
11307 if(subType.kind == classType)
11309 declareStruct = true;
11312 else if(subType.kind == pointerType)
11314 else if(subType.kind == arrayType)
11315 subType = subType.arrayType;
11325 if(decl.specifiers)
11328 for(s = decl.specifiers->first; s; s = s.next)
11330 ProcessSpecifier(s, declareStruct);
11335 case instDeclaration:
11337 ProcessInstantiationType(decl.inst);
11340 case structDeclaration:
11344 bool declareStruct = false;
11346 if(decl.declarators)
11348 for(d = decl.declarators->first; d; d = d.next)
11350 Type type = ProcessType(decl.specifiers, d.declarator);
11352 ProcessDeclarator(d);
11353 for(subType = type; subType;)
11355 if(subType.kind == classType)
11357 declareStruct = true;
11360 else if(subType.kind == pointerType)
11362 else if(subType.kind == arrayType)
11363 subType = subType.arrayType;
11370 if(decl.specifiers)
11372 for(spec = decl.specifiers->first; spec; spec = spec.next)
11373 ProcessSpecifier(spec, declareStruct);
11380 static FunctionDefinition curFunction;
11382 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11384 char propName[1024], propNameM[1024];
11385 char getName[1024], setName[1024];
11388 DeclareProperty(prop, setName, getName);
11390 // eInstance_FireWatchers(object, prop);
11391 strcpy(propName, "__ecereProp_");
11392 FullClassNameCat(propName, prop._class.fullName, false);
11393 strcat(propName, "_");
11394 // strcat(propName, prop.name);
11395 FullClassNameCat(propName, prop.name, true);
11396 MangleClassName(propName);
11398 strcpy(propNameM, "__ecerePropM_");
11399 FullClassNameCat(propNameM, prop._class.fullName, false);
11400 strcat(propNameM, "_");
11401 // strcat(propNameM, prop.name);
11402 FullClassNameCat(propNameM, prop.name, true);
11403 MangleClassName(propNameM);
11405 if(prop.isWatchable)
11408 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11409 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11410 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11413 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11414 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11415 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11421 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11422 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11423 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11426 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11427 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11428 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11431 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11432 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11433 curFunction.propSet.fireWatchersDone = true;
11436 static void ProcessStatement(Statement stmt)
11440 lineNum = stmt.pos.line;
11441 column = stmt.pos.col;
11446 ProcessStatement(stmt.labeled.stmt);
11449 // This expression should be constant...
11450 if(stmt.caseStmt.exp)
11452 FreeType(stmt.caseStmt.exp.destType);
11453 stmt.caseStmt.exp.destType = curSwitchType;
11454 if(curSwitchType) curSwitchType.refCount++;
11455 ProcessExpressionType(stmt.caseStmt.exp);
11456 ComputeExpression(stmt.caseStmt.exp);
11458 if(stmt.caseStmt.stmt)
11459 ProcessStatement(stmt.caseStmt.stmt);
11463 if(stmt.compound.context)
11468 Statement prevCompound = curCompound;
11469 Context prevContext = curContext;
11471 if(!stmt.compound.isSwitch)
11472 curCompound = stmt;
11473 curContext = stmt.compound.context;
11475 if(stmt.compound.declarations)
11477 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11478 ProcessDeclaration(decl);
11480 if(stmt.compound.statements)
11482 for(s = stmt.compound.statements->first; s; s = s.next)
11483 ProcessStatement(s);
11486 curContext = prevContext;
11487 curCompound = prevCompound;
11491 case expressionStmt:
11494 if(stmt.expressions)
11496 for(exp = stmt.expressions->first; exp; exp = exp.next)
11497 ProcessExpressionType(exp);
11505 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11506 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11507 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11508 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11510 ProcessExpressionType(exp);
11512 if(stmt.ifStmt.stmt)
11513 ProcessStatement(stmt.ifStmt.stmt);
11514 if(stmt.ifStmt.elseStmt)
11515 ProcessStatement(stmt.ifStmt.elseStmt);
11520 Type oldSwitchType = curSwitchType;
11521 if(stmt.switchStmt.exp)
11524 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11534 e.exp.destType = destType;
11537 ProcessExpressionType(exp);
11540 curSwitchType = exp.expType;
11543 ProcessStatement(stmt.switchStmt.stmt);
11544 curSwitchType = oldSwitchType;
11549 if(stmt.whileStmt.exp)
11553 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11554 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11555 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11556 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11558 ProcessExpressionType(exp);
11561 if(stmt.whileStmt.stmt)
11562 ProcessStatement(stmt.whileStmt.stmt);
11567 if(stmt.doWhile.exp)
11571 if(stmt.doWhile.exp->last)
11573 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11574 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11575 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11577 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11579 ProcessExpressionType(exp);
11582 if(stmt.doWhile.stmt)
11583 ProcessStatement(stmt.doWhile.stmt);
11589 if(stmt.forStmt.init)
11590 ProcessStatement(stmt.forStmt.init);
11592 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11594 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11595 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11596 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11599 if(stmt.forStmt.check)
11600 ProcessStatement(stmt.forStmt.check);
11601 if(stmt.forStmt.increment)
11603 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11604 ProcessExpressionType(exp);
11607 if(stmt.forStmt.stmt)
11608 ProcessStatement(stmt.forStmt.stmt);
11613 Identifier id = stmt.forEachStmt.id;
11614 OldList * exp = stmt.forEachStmt.exp;
11615 OldList * filter = stmt.forEachStmt.filter;
11616 Statement block = stmt.forEachStmt.stmt;
11617 char iteratorType[1024];
11620 bool isBuiltin = exp && exp->last &&
11621 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11622 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11623 Expression arrayExp;
11624 char * typeString = null;
11625 int builtinCount = 0;
11627 for(e = exp ? exp->first : null; e; e = e.next)
11631 FreeType(e.destType);
11632 e.destType = ProcessTypeString("Container", false);
11634 if(!isBuiltin || e.next)
11635 ProcessExpressionType(e);
11638 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11639 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11640 eClass_IsDerived(source._class.registered, containerClass)))
11642 Class _class = source ? source._class.registered : null;
11644 Expression expIt = null;
11645 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
11646 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11647 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11648 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11649 stmt.type = compoundStmt;
11651 stmt.compound.context = Context { };
11652 stmt.compound.context.parent = curContext;
11653 curContext = stmt.compound.context;
11655 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11657 Class mapClass = eSystem_FindClass(privateModule, "Map");
11658 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11659 isCustomAVLTree = true;
11660 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
11662 else */if(eClass_IsDerived(source._class.registered, mapClass))
11665 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11666 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11668 Class listClass = eSystem_FindClass(privateModule, "List");
11670 isList = eClass_IsDerived(source._class.registered, listClass);
11676 OldList * specs = MkList();
11677 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11678 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11679 stmt.compound.declarations = MkListOne(
11680 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11681 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11682 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11683 MkInitializerAssignment(MkExpBrackets(exp))))));
11688 char typeStringBuf[1024];
11690 // TODO: Merge this code?
11691 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11692 if(((Expression)exp->last).type == castExp)
11694 TypeName typeName = ((Expression)exp->last).cast.typeName;
11696 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11699 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11700 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11701 arrayExp.destType._class.registered.templateArgs)
11703 Class templateClass = arrayExp.destType._class.registered;
11704 typeString = templateClass.templateArgs[2].dataTypeString;
11706 else if(arrayExp.list)
11708 // Guess type from expressions in the array
11710 for(e = arrayExp.list->first; e; e = e.next)
11712 ProcessExpressionType(e);
11715 if(!type) { type = e.expType; type.refCount++; }
11718 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11719 if(!MatchTypeExpression(e, type, null, false))
11725 e = arrayExp.list->first;
11726 ProcessExpressionType(e);
11729 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11730 if(!MatchTypeExpression(e, type, null, false))
11732 FreeType(e.expType);
11743 FreeType(e.expType);
11750 typeStringBuf[0] = '\0';
11751 PrintType(type, typeStringBuf, false, true);
11752 typeString = typeStringBuf;
11758 OldList * initializers = MkList();
11760 OldList * specs = MkList();
11765 builtinCount = arrayExp.list->count;
11766 type = ProcessTypeString(typeString, false);
11767 while(e = arrayExp.list->first)
11769 arrayExp.list->Remove(e);
11772 ProcessExpressionType(e);
11773 ListAdd(initializers, MkInitializerAssignment(e));
11776 delete arrayExp.list;
11778 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11779 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11780 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11782 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
11784 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
11785 ), MkInitializerList(initializers)))));
11786 FreeList(exp, FreeExpression);
11790 arrayExp.expType = ProcessTypeString("Container", false);
11791 Compiler_Error($"Couldn't determine type of array elements\n");
11796 OldList * specs = MkList();
11798 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11799 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11800 stmt.compound.declarations = MkListOne(
11801 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11802 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11803 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11804 MkInitializerAssignment(MkExpBrackets(exp))))));
11807 else if(isLinkList && !isList)
11810 OldList * specs = MkList();
11811 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11812 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11813 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11814 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11815 MkInitializerAssignment(MkExpBrackets(exp))))));
11817 /*else if(isCustomAVLTree)
11820 OldList * specs = MkList();
11821 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11822 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11823 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11824 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11825 MkInitializerAssignment(MkExpBrackets(exp))))));
11827 else if(_class.templateArgs)
11830 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11832 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11834 stmt.compound.declarations = MkListOne(
11835 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11836 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11837 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11839 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11843 // Reparent sub-contexts in this statement
11847 if(block.compound.context)
11848 block.compound.context.parent = stmt.compound.context;
11851 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
11852 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
11853 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
11854 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
11857 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
11858 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
11861 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
11862 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
11865 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
11866 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
11869 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
11870 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
11873 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
11874 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
11876 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
11879 case expressionStmt:
11885 case badDeclarationStmt:
11886 case fireWatchersStmt:
11887 case stopWatchingStmt:
11894 block = MkIfStmt(filter, block, null);
11898 stmt.compound.statements = MkListOne(MkForStmt(
11899 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11900 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11901 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11902 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11904 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11905 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11906 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11911 //OldList * specs = MkList();
11912 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11914 sprintf(count, "%d", builtinCount);
11916 stmt.compound.statements = MkListOne(MkForStmt(
11917 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11918 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11919 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11920 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11924 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11925 stmt.compound.statements = MkListOne(MkForStmt(
11926 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11927 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11928 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11929 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11932 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11933 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11934 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11936 else if(isLinkList && !isList)
11938 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11939 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11940 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11941 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11943 stmt.compound.statements = MkListOne(MkForStmt(
11944 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11945 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11946 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11951 OldList * specs = MkList();
11952 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11953 stmt.compound.statements = MkListOne(MkForStmt(
11954 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11955 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11956 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11957 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11958 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11961 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11962 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11963 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11965 /*else if(isCustomAVLTree)
11967 stmt.compound.statements = MkListOne(MkForStmt(
11968 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11969 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11970 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11971 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11974 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11975 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11976 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11980 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11981 MkIdentifier("Next")), null)), block));
11983 ProcessExpressionType(expIt);
11984 if(stmt.compound.declarations->first)
11985 ProcessDeclaration(stmt.compound.declarations->first);
11988 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11990 ProcessStatement(stmt);
11991 curContext = stmt.compound.context.parent;
11996 Compiler_Error($"Expression is not a container\n");
12009 if(stmt.expressions)
12011 for(exp = stmt.expressions->first; exp; exp = exp.next)
12015 if(curFunction && !curFunction.type)
12016 curFunction.type = ProcessType(
12017 curFunction.specifiers, curFunction.declarator);
12018 FreeType(exp.destType);
12019 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12020 if(exp.destType) exp.destType.refCount++;
12022 ProcessExpressionType(exp);
12027 case badDeclarationStmt:
12029 ProcessDeclaration(stmt.decl);
12035 if(stmt.asmStmt.inputFields)
12037 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12038 if(field.expression)
12039 ProcessExpressionType(field.expression);
12041 if(stmt.asmStmt.outputFields)
12043 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12044 if(field.expression)
12045 ProcessExpressionType(field.expression);
12047 if(stmt.asmStmt.clobberedFields)
12049 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12051 if(field.expression)
12052 ProcessExpressionType(field.expression);
12059 PropertyWatch propWatch;
12060 OldList * watches = stmt._watch.watches;
12061 Expression object = stmt._watch.object;
12062 Expression watcher = stmt._watch.watcher;
12064 ProcessExpressionType(watcher);
12066 ProcessExpressionType(object);
12070 if(watcher || thisClass)
12072 External external = curExternal;
12073 Context context = curContext;
12075 stmt.type = expressionStmt;
12076 stmt.expressions = MkList();
12078 curExternal = external.prev;
12080 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12082 ClassFunction func;
12083 char watcherName[1024];
12084 Class watcherClass = watcher ?
12085 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12086 External createdExternal;
12088 // Create a declaration above
12089 External externalDecl = MkExternalDeclaration(null);
12090 ast->Insert(curExternal.prev, externalDecl);
12092 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12093 if(propWatch.deleteWatch)
12094 strcat(watcherName, "_delete");
12098 for(propID = propWatch.properties->first; propID; propID = propID.next)
12100 strcat(watcherName, "_");
12101 strcat(watcherName, propID.string);
12105 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12107 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
12108 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12109 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
12110 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12111 ProcessClassFunctionBody(func, propWatch.compound);
12112 propWatch.compound = null;
12114 //afterExternal = afterExternal ? afterExternal : curExternal;
12116 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
12117 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12119 createdExternal.symbol.idCode = external.symbol.idCode;
12121 curExternal = createdExternal;
12122 ProcessFunction(createdExternal.function);
12125 // Create a declaration above
12127 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
12128 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
12129 externalDecl.declaration = decl;
12130 if(decl.symbol && !decl.symbol.pointerExternal)
12131 decl.symbol.pointerExternal = externalDecl;
12134 if(propWatch.deleteWatch)
12136 OldList * args = MkList();
12137 ListAdd(args, CopyExpression(object));
12138 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12139 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12140 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12144 Class _class = object.expType._class.registered;
12147 for(propID = propWatch.properties->first; propID; propID = propID.next)
12149 char propName[1024];
12150 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12153 char getName[1024], setName[1024];
12154 OldList * args = MkList();
12156 DeclareProperty(prop, setName, getName);
12158 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12159 strcpy(propName, "__ecereProp_");
12160 FullClassNameCat(propName, prop._class.fullName, false);
12161 strcat(propName, "_");
12162 // strcat(propName, prop.name);
12163 FullClassNameCat(propName, prop.name, true);
12165 ListAdd(args, CopyExpression(object));
12166 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12167 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12168 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12170 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12173 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12178 Compiler_Error($"Invalid watched object\n");
12181 curExternal = external;
12182 curContext = context;
12185 FreeExpression(watcher);
12187 FreeExpression(object);
12188 FreeList(watches, FreePropertyWatch);
12191 Compiler_Error($"No observer specified and not inside a _class\n");
12195 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12197 ProcessStatement(propWatch.compound);
12203 case fireWatchersStmt:
12205 OldList * watches = stmt._watch.watches;
12206 Expression object = stmt._watch.object;
12208 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12209 // printf("%X\n", watches);
12210 // printf("%X\n", stmt._watch.watches);
12212 ProcessExpressionType(object);
12217 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12223 stmt.type = expressionStmt;
12224 stmt.expressions = MkList();
12226 // Check if we're inside a property set
12227 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12229 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12233 //Compiler_Error($"No property specified and not inside a property set\n");
12237 for(propID = watches->first; propID; propID = propID.next)
12239 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12242 CreateFireWatcher(prop, object, stmt);
12245 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12250 // Fire all properties!
12253 for(base = _class; base; base = base.base)
12255 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12257 if(prop.isProperty && prop.isWatchable)
12259 CreateFireWatcher(prop, object, stmt);
12266 FreeExpression(object);
12267 FreeList(watches, FreeIdentifier);
12270 Compiler_Error($"Invalid object specified and not inside a class\n");
12274 case stopWatchingStmt:
12276 OldList * watches = stmt._watch.watches;
12277 Expression object = stmt._watch.object;
12278 Expression watcher = stmt._watch.watcher;
12281 ProcessExpressionType(object);
12283 ProcessExpressionType(watcher);
12286 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12288 if(watcher || thisClass)
12294 stmt.type = expressionStmt;
12295 stmt.expressions = MkList();
12300 // eInstance_StopWatching(object, null, watcher);
12302 ListAdd(args, CopyExpression(object));
12303 ListAdd(args, MkExpConstant("0"));
12304 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12305 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12309 for(propID = watches->first; propID; propID = propID.next)
12311 char propName[1024];
12312 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12315 char getName[1024], setName[1024];
12316 OldList * args = MkList();
12318 DeclareProperty(prop, setName, getName);
12320 // eInstance_StopWatching(object, prop, watcher);
12321 strcpy(propName, "__ecereProp_");
12322 FullClassNameCat(propName, prop._class.fullName, false);
12323 strcat(propName, "_");
12324 // strcat(propName, prop.name);
12325 FullClassNameCat(propName, prop.name, true);
12326 MangleClassName(propName);
12328 ListAdd(args, CopyExpression(object));
12329 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12330 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12331 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12334 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12339 FreeExpression(object);
12341 FreeExpression(watcher);
12342 FreeList(watches, FreeIdentifier);
12345 Compiler_Error($"Invalid object specified and not inside a class\n");
12348 Compiler_Error($"No observer specified and not inside a class\n");
12355 static void ProcessFunction(FunctionDefinition function)
12357 Identifier id = GetDeclId(function.declarator);
12358 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12359 Type type = symbol ? symbol.type : null;
12360 Class oldThisClass = thisClass;
12361 Context oldTopContext = topContext;
12363 yylloc = function.loc;
12364 // Process thisClass
12366 if(type && type.thisClass)
12368 Symbol classSym = type.thisClass;
12369 Class _class = type.thisClass.registered;
12370 char className[1024];
12371 char structName[1024];
12372 Declarator funcDecl;
12375 bool typedObject = false;
12377 if(_class && !_class.base)
12379 _class = currentClass;
12380 if(_class && !_class.symbol)
12381 _class.symbol = FindClass(_class.fullName);
12382 classSym = _class ? _class.symbol : null;
12383 typedObject = true;
12386 thisClass = _class;
12388 if(inCompiler && _class)
12390 if(type.kind == functionType)
12392 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12394 //TypeName param = symbol.type.params.first;
12395 Type param = symbol.type.params.first;
12396 symbol.type.params.Remove(param);
12397 //FreeTypeName(param);
12400 if(type.classObjectType != classPointer)
12402 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12403 symbol.type.staticMethod = true;
12404 symbol.type.thisClass = null;
12406 // HIGH DANGER: VERIFYING THIS...
12407 symbol.type.extraParam = false;
12411 strcpy(className, "__ecereClass_");
12412 FullClassNameCat(className, _class.fullName, true);
12414 MangleClassName(className);
12417 FullClassNameCat(structName, _class.fullName, false);
12422 funcDecl = GetFuncDecl(function.declarator);
12425 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12427 TypeName param = funcDecl.function.parameters->first;
12428 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12430 funcDecl.function.parameters->Remove(param);
12431 FreeTypeName(param);
12435 // DANGER: Watch for this... Check if it's a Conversion?
12436 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12438 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12439 if(!function.propertyNoThis)
12441 TypeName thisParam;
12443 if(type.classObjectType != classPointer)
12445 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12446 if(!funcDecl.function.parameters)
12447 funcDecl.function.parameters = MkList();
12448 funcDecl.function.parameters->Insert(null, thisParam);
12453 if(type.classObjectType != classPointer)
12455 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12456 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12459 thisParam = TypeName
12461 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12462 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12464 funcDecl.function.parameters->Insert(null, thisParam);
12469 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12471 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12472 funcDecl = GetFuncDecl(initDecl.declarator);
12475 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12477 TypeName param = funcDecl.function.parameters->first;
12478 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12480 funcDecl.function.parameters->Remove(param);
12481 FreeTypeName(param);
12485 if(type.classObjectType != classPointer)
12487 // DANGER: Watch for this... Check if it's a Conversion?
12488 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12490 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12492 if(!funcDecl.function.parameters)
12493 funcDecl.function.parameters = MkList();
12494 funcDecl.function.parameters->Insert(null, thisParam);
12501 // Add this to the context
12504 if(type.classObjectType != classPointer)
12506 thisSymbol = Symbol
12508 string = CopyString("this");
12509 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12511 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12513 if(typedObject && thisSymbol.type)
12515 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12516 thisSymbol.type.byReference = type.byReference;
12517 thisSymbol.type.typedByReference = type.byReference;
12519 thisSymbol = Symbol { string = CopyString("class") };
12520 function.body.compound.context.symbols.Add(thisSymbol);
12526 // Pointer to class data
12528 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12530 DataMember member = null;
12533 for(base = _class; base && base.type != systemClass; base = base.next)
12535 for(member = base.membersAndProperties.first; member; member = member.next)
12536 if(!member.isProperty)
12542 for(member = _class.membersAndProperties.first; member; member = member.next)
12543 if(!member.isProperty)
12547 char pointerName[1024];
12550 Initializer initializer;
12551 Expression exp, bytePtr;
12553 strcpy(pointerName, "__ecerePointer_");
12554 FullClassNameCat(pointerName, _class.fullName, false);
12556 char className[1024];
12557 strcpy(className, "__ecereClass_");
12558 FullClassNameCat(className, classSym.string, true);
12559 MangleClassName(className);
12562 DeclareClass(classSym, className);
12566 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12571 sprintf(string, "%d", _class.offset);
12572 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12576 // ([bytePtr] + [className]->offset)
12577 exp = QBrackets(MkExpOp(bytePtr, '+',
12578 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12581 // (this ? [exp] : 0)
12582 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12586 kind = pointerType;
12587 type = Type { refCount = 1, kind = voidType };
12592 yylloc = function.body.loc;
12593 // ([structName] *) [exp]
12594 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12595 initializer = MkInitializerAssignment(
12596 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12598 // [structName] * [pointerName] = [initializer];
12599 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12602 Context prevContext = curContext;
12603 curContext = function.body.compound.context;
12605 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12606 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12608 curContext = prevContext;
12612 decl.symbol = null;
12614 if(!function.body.compound.declarations)
12615 function.body.compound.declarations = MkList();
12616 function.body.compound.declarations->Insert(null, decl);
12622 // Loop through the function and replace undeclared identifiers
12623 // which are a member of the class (methods, properties or data)
12624 // by "this.[member]"
12631 FreeSpecifier(id._class);
12634 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12636 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12637 id = GetDeclId(initDecl.declarator);
12639 FreeSpecifier(id._class);
12644 topContext = function.body.compound.context;
12646 FunctionDefinition oldFunction = curFunction;
12647 curFunction = function;
12649 ProcessStatement(function.body);
12651 // If this is a property set and no firewatchers has been done yet, add one here
12652 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12654 Statement prevCompound = curCompound;
12655 Context prevContext = curContext;
12657 Statement fireWatchers = MkFireWatchersStmt(null, null);
12658 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12659 ListAdd(function.body.compound.statements, fireWatchers);
12661 curCompound = function.body;
12662 curContext = function.body.compound.context;
12664 ProcessStatement(fireWatchers);
12666 curContext = prevContext;
12667 curCompound = prevCompound;
12671 curFunction = oldFunction;
12674 if(function.declarator)
12676 ProcessDeclarator(function.declarator);
12679 topContext = oldTopContext;
12680 thisClass = oldThisClass;
12683 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12684 static void ProcessClass(OldList definitions, Symbol symbol)
12687 External external = curExternal;
12688 Class regClass = symbol ? symbol.registered : null;
12690 // Process all functions
12691 for(def = definitions.first; def; def = def.next)
12693 if(def.type == functionClassDef)
12695 if(def.function.declarator)
12696 curExternal = def.function.declarator.symbol.pointerExternal;
12698 curExternal = external;
12700 ProcessFunction((FunctionDefinition)def.function);
12702 else if(def.type == declarationClassDef)
12704 if(def.decl.type == instDeclaration)
12706 thisClass = regClass;
12707 ProcessInstantiationType(def.decl.inst);
12713 Class backThisClass = thisClass;
12714 if(regClass) thisClass = regClass;
12715 ProcessDeclaration(def.decl);
12716 thisClass = backThisClass;
12719 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12721 MemberInit defProperty;
12723 // Add this to the context
12724 Symbol thisSymbol = Symbol
12726 string = CopyString("this");
12727 type = regClass ? MkClassType(regClass.fullName) : null;
12729 globalContext.symbols.Add((BTNode)thisSymbol);
12731 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12733 thisClass = regClass;
12734 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12738 globalContext.symbols.Remove((BTNode)thisSymbol);
12739 FreeSymbol(thisSymbol);
12741 else if(def.type == propertyClassDef && def.propertyDef)
12743 PropertyDef prop = def.propertyDef;
12745 // Add this to the context
12747 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12748 globalContext.symbols.Add(thisSymbol);
12751 thisClass = regClass;
12758 string = CopyString("this");
12759 type = MkClassType(regClass.fullName);
12761 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12764 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12765 ProcessStatement(prop.setStmt);
12773 string = CopyString("this");
12774 type = MkClassType(regClass.fullName);
12776 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12779 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12780 ProcessStatement(prop.getStmt);
12788 string = CopyString("this");
12789 type = MkClassType(regClass.fullName);
12791 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12794 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12795 ProcessStatement(prop.issetStmt);
12801 globalContext.symbols.Remove(thisSymbol);
12802 FreeSymbol(thisSymbol);
12805 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12807 PropertyWatch propertyWatch = def.propertyWatch;
12809 thisClass = regClass;
12810 if(propertyWatch.compound)
12814 string = CopyString("this");
12815 type = regClass ? MkClassType(regClass.fullName) : null;
12818 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12820 curExternal = null;
12821 ProcessStatement(propertyWatch.compound);
12828 void DeclareFunctionUtil(String s)
12830 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12835 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12836 strcpy(name, "__ecereFunction_");
12837 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12838 DeclareFunction(function, name);
12842 void ComputeDataTypes()
12846 External after = null;
12848 currentClass = null;
12850 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12852 for(external = ast->first; external; external = external.next)
12854 if(external.type == declarationExternal)
12856 Declaration decl = external.declaration;
12859 OldList * decls = decl.declarators;
12862 InitDeclarator initDecl = decls->first;
12865 Declarator declarator = initDecl.declarator;
12866 if(declarator && declarator.type == identifierDeclarator)
12868 Identifier id = declarator.identifier;
12869 if(id && id.string)
12871 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12873 external.symbol.id = -1001, external.symbol.idCode = -1001;
12884 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12885 ast->Insert(after, temp);
12886 curExternal = temp;
12888 DeclareFunctionUtil("eSystem_New");
12889 DeclareFunctionUtil("eSystem_New0");
12890 DeclareFunctionUtil("eSystem_Renew");
12891 DeclareFunctionUtil("eSystem_Renew0");
12892 DeclareFunctionUtil("eSystem_Delete");
12893 DeclareFunctionUtil("eClass_GetProperty");
12894 DeclareFunctionUtil("eClass_SetProperty");
12895 DeclareFunctionUtil("eInstance_FireSelfWatchers");
12896 DeclareFunctionUtil("eInstance_SetMethod");
12897 DeclareFunctionUtil("eInstance_IncRef");
12898 DeclareFunctionUtil("eInstance_StopWatching");
12899 DeclareFunctionUtil("eInstance_Watch");
12900 DeclareFunctionUtil("eInstance_FireWatchers");
12902 DeclareStruct("ecere::com::Class", false);
12903 DeclareStruct("ecere::com::Instance", false);
12904 DeclareStruct("ecere::com::Property", false);
12905 DeclareStruct("ecere::com::DataMember", false);
12906 DeclareStruct("ecere::com::Method", false);
12907 DeclareStruct("ecere::com::SerialBuffer", false);
12908 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12912 for(external = ast->first; external; external = external.next)
12914 afterExternal = curExternal = external;
12915 if(external.type == functionExternal)
12917 currentClass = external.function._class;
12918 ProcessFunction(external.function);
12920 // There shouldn't be any _class member access here anyways...
12921 else if(external.type == declarationExternal)
12923 currentClass = null;
12924 if(external.declaration)
12925 ProcessDeclaration(external.declaration);
12927 else if(external.type == classExternal)
12929 ClassDefinition _class = external._class;
12930 currentClass = external.symbol.registered;
12931 if(_class.definitions)
12933 ProcessClass(_class.definitions, _class.symbol);
12937 // Free class data...
12938 ast->Remove(external);
12942 else if(external.type == nameSpaceExternal)
12944 thisNameSpace = external.id.string;
12947 currentClass = null;
12948 thisNameSpace = null;
12949 curExternal = null;
12951 delete temp.symbol;