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))
410 int unionMemberOffset = 0;
414 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
415 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
420 member.memberOffset = 0;
421 if(targetBits < sizeof(void *) * 8)
422 member.structAlignment = 0;
424 else if(targetBits < sizeof(void *) * 8)
425 _class.structAlignment = 0;
427 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
428 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
429 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
431 if(!member && _class.destructionWatchOffset)
432 _class.memberOffset += sizeof(OldList);
434 // To avoid reentrancy...
435 //_class.structSize = -1;
438 DataMember dataMember;
439 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
441 if(!dataMember.isProperty)
443 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
445 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
446 /*if(!dataMember.dataType)
447 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
455 DataMember dataMember;
456 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
458 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
460 if(!isMember && _class.type == bitClass && dataMember.dataType)
462 BitMember bitMember = (BitMember) dataMember;
466 ComputeTypeSize(dataMember.dataType);
468 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
469 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
471 _class.memberOffset = bitMember.pos + bitMember.size;
472 for(d = 0; d<bitMember.size; d++)
478 bitMember.mask = mask << bitMember.pos;
480 else if(dataMember.type == normalMember && dataMember.dataType)
485 // Prevent infinite recursion
486 if(dataMember.dataType.kind != classType ||
487 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
488 _class.type != structClass)))
489 ComputeTypeSize(dataMember.dataType);
491 if(dataMember.dataType.bitFieldCount)
493 bitFields += dataMember.dataType.bitFieldCount;
500 int size = (bitFields + 7) / 8;
504 // TESTING THIS PADDING CODE
507 member.structAlignment = Max(member.structAlignment, alignment);
509 if(member.memberOffset % alignment)
510 member.memberOffset += alignment - (member.memberOffset % alignment);
513 dataMember.offset = member.memberOffset;
514 if(member.type == unionMember)
515 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
518 member.memberOffset += size;
523 // TESTING THIS PADDING CODE
526 _class.structAlignment = Max(_class.structAlignment, alignment);
528 if(_class.memberOffset % alignment)
529 _class.memberOffset += alignment - (_class.memberOffset % alignment);
532 dataMember.offset = _class.memberOffset;
533 _class.memberOffset += size;
537 size = dataMember.dataType.size;
538 alignment = dataMember.dataType.alignment;
543 // TESTING THIS PADDING CODE
546 member.structAlignment = Max(member.structAlignment, alignment);
548 if(member.memberOffset % alignment)
549 member.memberOffset += alignment - (member.memberOffset % alignment);
552 dataMember.offset = member.memberOffset;
553 if(member.type == unionMember)
554 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
557 member.memberOffset += size;
562 // TESTING THIS PADDING CODE
565 _class.structAlignment = Max(_class.structAlignment, alignment);
567 if(_class.memberOffset % alignment)
568 _class.memberOffset += alignment - (_class.memberOffset % alignment);
571 dataMember.offset = _class.memberOffset;
572 _class.memberOffset += size;
579 ComputeClassMembers((Class)dataMember, true);
580 alignment = dataMember.structAlignment;
586 if(member.memberOffset % alignment)
587 member.memberOffset += alignment - (member.memberOffset % alignment);
589 member.structAlignment = Max(member.structAlignment, alignment);
591 dataMember.offset = member.memberOffset;
592 if(member.type == unionMember)
593 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
595 member.memberOffset += dataMember.memberOffset;
601 if(_class.memberOffset % alignment)
602 _class.memberOffset += alignment - (_class.memberOffset % alignment);
603 _class.structAlignment = Max(_class.structAlignment, alignment);
605 dataMember.offset = _class.memberOffset;
606 _class.memberOffset += dataMember.memberOffset;
614 int size = (bitFields + 7) / 8;
618 // TESTING THIS PADDING CODE
621 member.structAlignment = Max(member.structAlignment, alignment);
623 if(member.memberOffset % alignment)
624 member.memberOffset += alignment - (member.memberOffset % alignment);
627 if(member.type == unionMember)
628 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
631 member.memberOffset += size;
636 // TESTING THIS PADDING CODE
639 _class.structAlignment = Max(_class.structAlignment, alignment);
641 if(_class.memberOffset % alignment)
642 _class.memberOffset += alignment - (_class.memberOffset % alignment);
644 _class.memberOffset += size;
649 if(member && member.type == unionMember)
651 member.memberOffset = unionMemberOffset;
656 /*if(_class.type == structClass)
657 _class.size = _class.memberOffset;
661 if(_class.type != bitClass)
664 if(_class.structAlignment)
666 if(_class.memberOffset % _class.structAlignment)
667 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
669 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
673 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
675 if(prop.isProperty && prop.isWatchable)
677 prop.watcherOffset = _class.structSize;
678 _class.structSize += sizeof(OldList);
686 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
688 Class deriv = derivative.data;
690 if(deriv.computeSize)
692 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
693 deriv.offset = /*_class.offset + */_class.structSize;
694 deriv.memberOffset = 0;
695 // ----------------------
697 deriv.structSize = deriv.offset;
699 ComputeClassMembers(deriv, false);
707 FinishTemplatesContext(context);
710 public void ComputeModuleClasses(Module module)
715 for(subModule = module.modules.first; subModule; subModule = subModule.next)
716 ComputeModuleClasses(subModule.data);
717 for(_class = module.classes.first; _class; _class = _class.next)
718 ComputeClassMembers(_class, false);
722 public int ComputeTypeSize(Type type)
724 uint size = type ? type.size : 0;
725 if(!size && type && !type.computing)
727 type.computing = true;
730 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
731 case charType: type.alignment = size = sizeof(char); break;
732 case intType: type.alignment = size = sizeof(int); break;
733 case int64Type: type.alignment = size = sizeof(int64); break;
734 case intPtrType: type.alignment = size = targetBits / 8; break;
735 case intSizeType: type.alignment = size = targetBits / 8; break;
736 case longType: type.alignment = size = sizeof(long); break;
737 case shortType: type.alignment = size = sizeof(short); break;
738 case floatType: type.alignment = size = sizeof(float); break;
739 case doubleType: type.alignment = size = sizeof(double); break;
742 Class _class = type._class ? type._class.registered : null;
744 if(_class && _class.type == structClass)
746 // Ensure all members are properly registered
747 ComputeClassMembers(_class, false);
748 type.alignment = _class.structAlignment;
749 size = _class.structSize;
750 if(type.alignment && size % type.alignment)
751 size += type.alignment - (size % type.alignment);
754 else if(_class && (_class.type == unitClass ||
755 _class.type == enumClass ||
756 _class.type == bitClass))
759 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
760 size = type.alignment = ComputeTypeSize(_class.dataType);
763 size = type.alignment = targetBits / 8; // sizeof(Instance *);
766 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */break;
768 if(type.arraySizeExp)
770 ProcessExpressionType(type.arraySizeExp);
771 ComputeExpression(type.arraySizeExp);
772 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType &&
773 type.arraySizeExp.expType.kind != shortType &&
774 type.arraySizeExp.expType.kind != charType &&
775 type.arraySizeExp.expType.kind != longType &&
776 type.arraySizeExp.expType.kind != int64Type &&
777 type.arraySizeExp.expType.kind != intSizeType &&
778 type.arraySizeExp.expType.kind != intPtrType &&
779 type.arraySizeExp.expType.kind != enumType &&
780 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
782 Location oldLoc = yylloc;
783 // bool isConstant = type.arraySizeExp.isConstant;
784 char expression[10240];
785 expression[0] = '\0';
786 type.arraySizeExp.expType = null;
787 yylloc = type.arraySizeExp.loc;
789 PrintExpression(type.arraySizeExp, expression);
790 Compiler_Error($"Array size not constant int (%s)\n", expression);
793 GetInt(type.arraySizeExp, &type.arraySize);
795 else if(type.enumClass)
797 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
799 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
806 // Unimplemented auto size
810 size = ComputeTypeSize(type.type) * type.arraySize;
812 type.alignment = type.type.alignment;
818 for(member = type.members.first; member; member = member.next)
820 uint addSize = ComputeTypeSize(member);
822 member.offset = size;
823 if(member.alignment && size % member.alignment)
824 member.offset += member.alignment - (size % member.alignment);
825 size = member.offset;
827 type.alignment = Max(type.alignment, member.alignment);
830 if(type.alignment && size % type.alignment)
831 size += type.alignment - (size % type.alignment);
837 for(member = type.members.first; member; member = member.next)
839 uint addSize = ComputeTypeSize(member);
841 member.offset = size;
842 if(member.alignment && size % member.alignment)
843 member.offset += member.alignment - (size % member.alignment);
844 size = member.offset;
846 type.alignment = Max(type.alignment, member.alignment);
847 size = Max(size, addSize);
849 if(type.alignment && size % type.alignment)
850 size += type.alignment - (size % type.alignment);
855 TemplateParameter param = type.templateParameter;
856 Type baseType = ProcessTemplateParameterType(param);
859 size = ComputeTypeSize(baseType);
860 type.alignment = baseType.alignment;
863 type.alignment = size = sizeof(uint64);
868 type.alignment = size = sizeof(enum { test });
873 type.alignment = size = targetBits / 8; //sizeof(void *);
878 type.computing = false;
884 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
886 // This function is in need of a major review when implementing private members etc.
887 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;
1018 Context context = isMember ? null : SetupTemplatesContext(_class);
1020 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1021 DeclareMembers(_class.base, false);
1023 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1025 if(!member.isProperty)
1032 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1033 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1034 DeclareStruct(member.dataType._class.string, false);
1036 if(!member.dataType && member.dataTypeString)
1037 member.dataType = ProcessTypeString(member.dataTypeString, false);
1039 DeclareType(member.dataType, false, false);
1045 DeclareMembers((Class)member, true);
1052 FinishTemplatesContext(context);
1054 return topMember ? topMember.memberID : _class.memberID;
1057 void DeclareStruct(char * name, bool skipNoHead)
1059 External external = null;
1060 Symbol classSym = FindClass(name);
1062 if(!inCompiler || !classSym) return;
1064 // We don't need any declaration for bit classes...
1065 if(classSym.registered &&
1066 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1069 /*if(classSym.registered.templateClass)
1070 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1073 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1075 // Add typedef struct
1077 OldList * specifiers, * declarators;
1078 OldList * declarations = null;
1079 char structName[1024];
1080 Specifier spec = null;
1081 external = (classSym.registered && classSym.registered.type == structClass) ?
1082 classSym.pointerExternal : classSym.structExternal;
1084 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1085 // Moved this one up because DeclareClass done later will need it
1087 classSym.declaring++;
1089 if(strchr(classSym.string, '<'))
1091 if(classSym.registered.templateClass)
1093 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1094 classSym.declaring--;
1100 DeclareMembers(classSym.registered, false);
1103 FullClassNameCat(structName, name, false);
1105 if(external && external.declaration && external.declaration.specifiers)
1107 for(spec = external.declaration.specifiers->first; spec; spec = spec.next)
1109 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1115 external = MkExternalDeclaration(null);*/
1117 if(!skipNoHead && (!spec || !spec.definitions))
1119 bool addedPadding = false;
1120 classSym.declaredStructSym = true;
1122 declarations = MkList();
1124 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1126 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1127 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1129 if(!declarations->count || (declarations->count == 1 && addedPadding))
1131 FreeList(declarations, FreeClassDef);
1132 declarations = null;
1135 if(skipNoHead || declarations)
1140 spec.definitions = declarations;
1142 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1145 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1148 if(classSym.structExternal)
1149 ast->Move(classSym.structExternal, curExternal.prev);
1150 ast->Move(classSym.pointerExternal, curExternal.prev);
1152 classSym.id = curExternal.symbol.idCode;
1153 classSym.idCode = curExternal.symbol.idCode;
1154 // external = classSym.pointerExternal;
1155 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1161 external = MkExternalDeclaration(null);
1163 specifiers = MkList();
1164 declarators = MkList();
1165 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1168 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1169 ListAdd(declarators, MkInitDeclarator(d, null));
1171 external.declaration = decl = MkDeclaration(specifiers, declarators);
1172 if(decl.symbol && !decl.symbol.pointerExternal)
1173 decl.symbol.pointerExternal = external;
1175 // For simple classes, keep the declaration as the external to move around
1176 if(classSym.registered && classSym.registered.type == structClass)
1178 char className[1024];
1179 strcpy(className, "__ecereClass_");
1180 FullClassNameCat(className, classSym.string, true);
1181 MangleClassName(className);
1184 DeclareClass(classSym, className);
1186 external.symbol = classSym;
1187 classSym.pointerExternal = external;
1188 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1189 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1193 char className[1024];
1194 strcpy(className, "__ecereClass_");
1195 FullClassNameCat(className, classSym.string, true);
1196 MangleClassName(className);
1198 // TOFIX: TESTING THIS...
1199 classSym.structExternal = external;
1200 DeclareClass(classSym, className);
1201 external.symbol = classSym;
1205 ast->Insert(curExternal ? curExternal.prev : null, external);
1209 classSym.declaring--;
1211 else if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1213 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1214 // Moved this one up because DeclareClass done later will need it
1217 classSym.declaring++;
1221 if(classSym.registered)
1222 DeclareMembers(classSym.registered, false);
1225 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1228 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1231 if(classSym.structExternal)
1232 ast->Move(classSym.structExternal, curExternal.prev);
1233 ast->Move(classSym.pointerExternal, curExternal.prev);
1235 classSym.id = curExternal.symbol.idCode;
1236 classSym.idCode = curExternal.symbol.idCode;
1237 // external = classSym.pointerExternal;
1238 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1241 classSym.declaring--;
1246 void DeclareProperty(Property prop, char * setName, char * getName)
1248 Symbol symbol = prop.symbol;
1249 char propName[1024];
1251 strcpy(setName, "__ecereProp_");
1252 FullClassNameCat(setName, prop._class.fullName, false);
1253 strcat(setName, "_Set_");
1254 // strcat(setName, prop.name);
1255 FullClassNameCat(setName, prop.name, true);
1257 strcpy(getName, "__ecereProp_");
1258 FullClassNameCat(getName, prop._class.fullName, false);
1259 strcat(getName, "_Get_");
1260 FullClassNameCat(getName, prop.name, true);
1261 // strcat(getName, prop.name);
1263 strcpy(propName, "__ecereProp_");
1264 FullClassNameCat(propName, prop._class.fullName, false);
1265 strcat(propName, "_");
1266 FullClassNameCat(propName, prop.name, true);
1267 // strcat(propName, prop.name);
1269 // To support "char *" property
1270 MangleClassName(getName);
1271 MangleClassName(setName);
1272 MangleClassName(propName);
1274 if(prop._class.type == structClass)
1275 DeclareStruct(prop._class.fullName, false);
1277 if(!symbol || curExternal.symbol.idCode < symbol.id)
1279 bool imported = false;
1280 bool dllImport = false;
1281 if(!symbol || symbol._import)
1286 if(!prop._class.symbol)
1287 prop._class.symbol = FindClass(prop._class.fullName);
1288 classSym = prop._class.symbol;
1289 if(classSym && !classSym._import)
1291 ModuleImport module;
1293 if(prop._class.module)
1294 module = FindModule(prop._class.module);
1296 module = mainModule;
1298 classSym._import = ClassImport
1300 name = CopyString(prop._class.fullName);
1301 isRemote = prop._class.isRemote;
1303 module.classes.Add(classSym._import);
1305 symbol = prop.symbol = Symbol { };
1306 symbol._import = (ClassImport)PropertyImport
1308 name = CopyString(prop.name);
1309 isVirtual = false; //prop.isVirtual;
1310 hasSet = prop.Set ? true : false;
1311 hasGet = prop.Get ? true : false;
1314 classSym._import.properties.Add(symbol._import);
1317 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1318 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1319 prop._class.module.importType != staticImport)
1325 Context context = SetupTemplatesContext(prop._class);
1326 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1327 FinishTemplatesContext(context);
1333 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1336 OldList * specifiers, * declarators;
1341 Declarator typeDecl;
1342 bool simple = false;
1344 specifiers = MkList();
1345 declarators = MkList();
1348 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1349 MkDeclaratorIdentifier(MkIdentifier("this"))));
1351 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1354 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1357 Context context = SetupTemplatesContext(prop._class);
1358 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1359 FinishTemplatesContext(context);
1362 // Make sure the simple _class's type is declared
1363 for(spec = specifiers->first; spec; spec = spec.next)
1365 if(spec.type == nameSpecifier /*SpecifierClass*/)
1367 if((!typeDecl || typeDecl.type == identifierDeclarator))
1369 Symbol classSym = spec.symbol; // FindClass(spec.name);
1370 symbol._class = classSym.registered;
1371 if(classSym.registered && classSym.registered.type == structClass)
1373 DeclareStruct(spec.name, false);
1381 d = PlugDeclarator(typeDecl, d);
1384 ListAdd(params, MkTypeName(specifiers,
1385 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1386 specifiers = MkList();
1389 d = MkDeclaratorFunction(d, params);
1393 specifiers->Insert(null, MkSpecifier(EXTERN));
1394 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1395 specifiers->Insert(null, MkSpecifier(STATIC));
1397 ListAdd(specifiers, MkSpecifier(VOID));
1399 ListAdd(declarators, MkInitDeclarator(d, null));
1401 decl = MkDeclaration(specifiers, declarators);
1403 external = MkExternalDeclaration(decl);
1404 ast->Insert(curExternal.prev, external);
1405 external.symbol = symbol;
1406 symbol.externalGet = external;
1408 ReplaceThisClassSpecifiers(specifiers, prop._class);
1411 FreeDeclarator(typeDecl);
1415 // Move declaration higher...
1416 ast->Move(symbol.externalGet, curExternal.prev);
1423 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1426 OldList * specifiers, * declarators;
1431 Declarator typeDecl;
1433 declarators = MkList();
1436 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1437 if(!prop.conversion || prop._class.type == structClass)
1439 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1440 MkDeclaratorIdentifier(MkIdentifier("this"))));
1443 specifiers = MkList();
1446 Context context = SetupTemplatesContext(prop._class);
1447 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1448 MkDeclaratorIdentifier(MkIdentifier("value")));
1449 FinishTemplatesContext(context);
1451 ListAdd(params, MkTypeName(specifiers, d));
1453 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1456 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1457 d = MkDeclaratorFunction(d, params);
1459 // Make sure the simple _class's type is declared
1460 for(spec = specifiers->first; spec; spec = spec.next)
1462 if(spec.type == nameSpecifier /*SpecifierClass*/)
1464 if((!typeDecl || typeDecl.type == identifierDeclarator))
1466 Symbol classSym = spec.symbol; // FindClass(spec.name);
1467 symbol._class = classSym.registered;
1468 if(classSym.registered && classSym.registered.type == structClass)
1469 DeclareStruct(spec.name, false);
1474 ListAdd(declarators, MkInitDeclarator(d, null));
1476 specifiers = MkList();
1479 specifiers->Insert(null, MkSpecifier(EXTERN));
1480 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1481 specifiers->Insert(null, MkSpecifier(STATIC));
1483 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1484 if(!prop.conversion || prop._class.type == structClass)
1485 ListAdd(specifiers, MkSpecifier(VOID));
1487 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1489 decl = MkDeclaration(specifiers, declarators);
1491 external = MkExternalDeclaration(decl);
1492 ast->Insert(curExternal.prev, external);
1493 external.symbol = symbol;
1494 symbol.externalSet = external;
1496 ReplaceThisClassSpecifiers(specifiers, prop._class);
1500 // Move declaration higher...
1501 ast->Move(symbol.externalSet, curExternal.prev);
1505 // Property (for Watchers)
1506 if(!symbol.externalPtr)
1510 OldList * specifiers = MkList();
1513 specifiers->Insert(null, MkSpecifier(EXTERN));
1515 specifiers->Insert(null, MkSpecifier(STATIC));
1517 ListAdd(specifiers, MkSpecifierName("Property"));
1520 OldList * list = MkList();
1521 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1522 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1526 strcpy(propName, "__ecerePropM_");
1527 FullClassNameCat(propName, prop._class.fullName, false);
1528 strcat(propName, "_");
1529 // strcat(propName, prop.name);
1530 FullClassNameCat(propName, prop.name, true);
1532 MangleClassName(propName);
1534 ListAdd(list, MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null),
1535 MkDeclaratorIdentifier(MkIdentifier(propName))), null));
1537 decl = MkDeclaration(specifiers, list);
1540 external = MkExternalDeclaration(decl);
1541 ast->Insert(curExternal.prev, external);
1542 external.symbol = symbol;
1543 symbol.externalPtr = external;
1547 // Move declaration higher...
1548 ast->Move(symbol.externalPtr, curExternal.prev);
1551 symbol.id = curExternal.symbol.idCode;
1555 // ***************** EXPRESSION PROCESSING ***************************
1556 public Type Dereference(Type source)
1561 if(source.kind == pointerType || source.kind == arrayType)
1564 source.type.refCount++;
1566 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1574 // Support dereferencing of no head classes for now...
1575 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1581 Compiler_Error($"cannot dereference type\n");
1586 static Type Reference(Type source)
1602 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1604 Identifier ident = member.identifiers ? member.identifiers->first : null;
1606 DataMember dataMember = null;
1607 Method method = null;
1608 bool freeType = false;
1610 yylloc = member.loc;
1616 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1620 dataMember = *curMember;
1626 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1627 DataMember _subMemberStack[256];
1628 int _subMemberStackPos = 0;
1630 // FILL MEMBER STACK
1632 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1635 dataMember = thisMember;
1636 if(curMember && thisMember.memberAccess == publicAccess)
1638 *curMember = thisMember;
1639 *curClass = thisMember._class;
1640 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1641 *subMemberStackPos = _subMemberStackPos;
1648 method = eClass_FindMethod(_class, ident.string, privateModule);
1649 if(method && method.type == virtualMethod)
1661 if(!dataMember.dataType && dataMember.dataTypeString)
1663 //Context context = SetupTemplatesContext(dataMember._class);
1664 Context context = SetupTemplatesContext(_class);
1665 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1666 FinishTemplatesContext(context);
1668 type = dataMember.dataType;
1672 // This is for destination type...
1673 if(!method.dataType)
1674 ProcessMethodType(method);
1675 //DeclareMethod(method);
1676 // method.dataType = ((Symbol)method.symbol)->type;
1677 type = method.dataType;
1680 if(ident && ident.next)
1682 for(ident = ident.next; ident && type; ident = ident.next)
1684 if(type.kind == classType)
1686 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1688 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1690 type = dataMember.dataType;
1692 else if(type.kind == structType || type.kind == unionType)
1695 for(memberType = type.members.first; memberType; memberType = memberType.next)
1697 if(!strcmp(memberType.name, ident.string))
1707 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1708 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1711 ClassTemplateParameter curParam = null;
1713 for(sClass = _class; sClass; sClass = sClass.base)
1716 if(sClass.templateClass) sClass = sClass.templateClass;
1717 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1719 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1721 for(sClass = sClass.base; sClass; sClass = sClass.base)
1723 if(sClass.templateClass) sClass = sClass.templateClass;
1724 id += sClass.templateParams.count;
1735 ClassTemplateArgument arg = _class.templateArgs[id];
1736 if(arg.dataTypeString)
1739 type = ProcessTypeString(arg.dataTypeString, false);
1741 if(type && _class.templateClass)
1742 type.passAsTemplate = true;
1748 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1749 exp.destType.refCount++;
1755 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1757 Class expClass = type._class.registered;
1758 Class cClass = null;
1763 char templateString[1024];
1764 ClassTemplateParameter param;
1765 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1766 for(cClass = expClass; cClass; cClass = cClass.base)
1769 if(cClass.templateClass) cClass = cClass.templateClass;
1770 for(param = cClass.templateParams.first; param; param = param.next)
1774 ClassTemplateArgument arg;
1775 for(sClass = cClass.base; sClass; sClass = sClass.base)
1777 if(sClass.templateClass) sClass = sClass.templateClass;
1778 id += sClass.templateParams.count;
1780 arg = expClass.templateArgs[id];
1782 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1784 ClassTemplateParameter cParam;
1785 //int p = numParams - sClass.templateParams.count;
1788 if(sClass.templateClass) sClass = sClass.templateClass;
1790 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1792 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1793 p += nextClass.templateParams.count;
1796 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1798 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1800 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1802 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1803 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1815 strcat(argument, arg.name.string);
1816 strcat(argument, " = ");
1822 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1823 char expString[1024];
1824 OldList * specs = MkList();
1825 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1827 char * string = PrintHexUInt64(arg.expression.ui64);
1828 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1831 ProcessExpressionType(exp);
1832 ComputeExpression(exp);
1833 expString[0] = '\0';
1834 PrintExpression(exp, expString);
1835 strcat(argument, expString);
1837 FreeExpression(exp);
1842 strcat(argument, arg.member.name);
1845 case TemplateParameterType::type:
1847 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1848 strcat(argument, arg.dataTypeString);
1854 if(paramCount) strcat(templateString, ", ");
1855 if(lastParam != p - 1)
1857 strcat(templateString, param.name);
1858 strcat(templateString, " = ");
1860 strcat(templateString, argument);
1869 int len = strlen(templateString);
1870 if(templateString[len-1] == '<')
1874 if(templateString[len-1] == '>')
1875 templateString[len++] = ' ';
1876 templateString[len++] = '>';
1878 templateString[len++] = '\0';
1881 Context context = SetupTemplatesContext(_class);
1882 if(freeType) FreeType(type);
1883 type = ProcessTypeString(templateString, false);
1885 FinishTemplatesContext(context);
1889 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1891 ProcessExpressionType(member.initializer.exp);
1892 if(!member.initializer.exp.expType)
1896 char expString[10240];
1897 expString[0] = '\0';
1898 PrintExpression(member.initializer.exp, expString);
1899 ChangeCh(expString, '\n', ' ');
1900 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1903 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1904 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false))
1906 Compiler_Error($"incompatible instance method %s\n", ident.string);
1909 else if(member.initializer)
1912 FreeType(member.exp.destType);
1913 member.exp.destType = type;
1914 if(member.exp.destType)
1915 member.exp.destType.refCount++;
1916 ProcessExpressionType(member.exp);
1919 ProcessInitializer(member.initializer, type);
1921 if(freeType) FreeType(type);
1925 if(_class && _class.type == unitClass)
1927 if(member.initializer)
1930 FreeType(member.exp.destType);
1931 member.exp.destType = MkClassType(_class.fullName);
1932 ProcessExpressionType(member.initializer, type);
1934 Type type = MkClassType(_class.fullName);
1935 ProcessInitializer(member.initializer, type);
1941 if(member.initializer)
1943 //ProcessExpressionType(member.exp);
1944 ProcessInitializer(member.initializer, null);
1950 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
1954 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
1956 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
1960 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
1965 void ProcessInstantiationType(Instantiation inst)
1970 MembersInit members;
1971 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
1974 /*if(!inst._class.symbol)
1975 inst._class.symbol = FindClass(inst._class.name);*/
1976 classSym = inst._class.symbol;
1977 _class = classSym ? classSym.registered : null;
1979 // DANGER: Patch for mutex not declaring its struct when not needed
1980 if(!_class || _class.type != noHeadClass)
1981 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
1983 afterExternal = afterExternal ? afterExternal : curExternal;
1986 ProcessExpressionType(inst.exp);
1988 inst.isConstant = true;
1991 DataMember curMember = null;
1992 Class curClass = null;
1993 DataMember subMemberStack[256];
1994 int subMemberStackPos = 0;
1996 for(members = inst.members->first; members; members = members.next)
1998 switch(members.type)
2000 case methodMembersInit:
2003 static uint instMethodID = 0;
2004 External external = curExternal;
2005 Context context = curContext;
2006 Declarator declarator = members.function.declarator;
2007 Identifier nameID = GetDeclId(declarator);
2008 char * unmangled = nameID ? nameID.string : null;
2010 External createdExternal = null;
2015 //members.function.dontMangle = true;
2016 strcpy(name, "__ecereInstMeth_");
2017 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2019 strcat(name, nameID.string);
2021 sprintf(number, "_%08d", instMethodID++);
2022 strcat(name, number);
2023 nameID.string = CopyString(name);
2026 // Do modifications here...
2029 Symbol symbol = declarator.symbol;
2030 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2032 if(method && method.type == virtualMethod)
2034 symbol.method = method;
2035 ProcessMethodType(method);
2037 if(!symbol.type.thisClass)
2039 if(method.dataType.thisClass && currentClass &&
2040 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2042 if(!currentClass.symbol)
2043 currentClass.symbol = FindClass(currentClass.fullName);
2044 symbol.type.thisClass = currentClass.symbol;
2049 _class.symbol = FindClass(_class.fullName);
2050 symbol.type.thisClass = _class.symbol;
2053 // TESTING THIS HERE:
2054 DeclareType(symbol.type, true, true);
2059 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2060 unmangled, classSym.string);
2064 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2065 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2069 FreeSpecifier(nameID._class);
2070 nameID._class = null;
2076 Type type = declarator.symbol.type;
2077 External oldExternal = curExternal;
2079 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2080 // *** It was commented out for problems such as
2082 class VirtualDesktop : Window
2084 clientSize = Size { };
2095 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2097 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2100 if(strcmp(declarator.symbol.string, name))
2102 printf("TOCHECK: Look out for this\n");
2103 delete declarator.symbol.string;
2104 declarator.symbol.string = CopyString(name);
2107 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2109 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2110 excludedSymbols->Remove(declarator.symbol);
2111 globalContext.symbols.Add((BTNode)declarator.symbol);
2112 if(strstr(declarator.symbol.string), "::")
2113 globalContext.hasNameSpace = true;
2118 //curExternal = curExternal.prev;
2119 //afterExternal = afterExternal->next;
2121 //ProcessFunction(afterExternal->function);
2123 //curExternal = afterExternal;
2125 External externalDecl;
2126 externalDecl = MkExternalDeclaration(null);
2127 ast->Insert(oldExternal.prev, externalDecl);
2129 // Which function does this process?
2130 if(createdExternal.function)
2132 ProcessFunction(createdExternal.function);
2134 //curExternal = oldExternal;
2137 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2139 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2140 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2142 //externalDecl = MkExternalDeclaration(decl);
2144 //***** ast->Insert(external.prev, externalDecl);
2145 //ast->Insert(curExternal.prev, externalDecl);
2146 externalDecl.declaration = decl;
2147 if(decl.symbol && !decl.symbol.pointerExternal)
2148 decl.symbol.pointerExternal = externalDecl;
2150 // Trying this out...
2151 declarator.symbol.pointerExternal = externalDecl;
2158 curExternal = declarator.symbol.pointerExternal;
2159 ProcessFunction((FunctionDefinition)members.function);
2161 curExternal = external;
2162 curContext = context;
2166 FreeClassFunction(members.function);
2168 // In this pass, turn this into a MemberInitData
2169 exp = QMkExpId(name);
2170 members.type = dataMembersInit;
2171 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2177 case dataMembersInit:
2179 if(members.dataMembers && classSym)
2182 Location oldyyloc = yylloc;
2183 for(member = members.dataMembers->first; member; member = member.next)
2185 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2186 if(member.initializer && !member.initializer.isConstant)
2187 inst.isConstant = false;
2199 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2201 // OPTIMIZATIONS: TESTING THIS...
2204 if(type.kind == functionType)
2209 for(param = type.params.first; param; param = param.next)
2210 DeclareType(param, declarePointers, true);
2212 DeclareType(type.returnType, declarePointers, true);
2214 else if(type.kind == pointerType && declarePointers)
2215 DeclareType(type.type, declarePointers, false);
2216 else if(type.kind == classType)
2218 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2219 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2221 else if(type.kind == structType || type.kind == unionType)
2224 for(member = type.members.first; member; member = member.next)
2225 DeclareType(member, false, false);
2227 else if(type.kind == arrayType)
2228 DeclareType(type.arrayType, declarePointers, false);
2232 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2234 ClassTemplateArgument * arg = null;
2236 ClassTemplateParameter curParam = null;
2238 for(sClass = _class; sClass; sClass = sClass.base)
2241 if(sClass.templateClass) sClass = sClass.templateClass;
2242 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2244 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2246 for(sClass = sClass.base; sClass; sClass = sClass.base)
2248 if(sClass.templateClass) sClass = sClass.templateClass;
2249 id += sClass.templateParams.count;
2259 arg = &_class.templateArgs[id];
2260 if(arg && param.type == type)
2261 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2266 public Context SetupTemplatesContext(Class _class)
2268 Context context = PushContext();
2269 context.templateTypesOnly = true;
2270 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2272 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2273 for(; param; param = param.next)
2275 if(param.type == type && param.identifier)
2277 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2278 curContext.templateTypes.Add((BTNode)type);
2285 for(sClass = _class; sClass; sClass = sClass.base)
2287 ClassTemplateParameter p;
2288 for(p = sClass.templateParams.first; p; p = p.next)
2290 //OldList * specs = MkList();
2291 //Declarator decl = null;
2292 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2295 TemplateParameter param = p.param;
2299 // ADD DATA TYPE HERE...
2300 p.param = param = TemplateParameter
2302 identifier = MkIdentifier(p.name), type = p.type,
2303 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2306 type = TemplatedType { key = (uintptr)p.name, param = param };
2307 curContext.templateTypes.Add((BTNode)type);
2315 public void FinishTemplatesContext(Context context)
2317 PopContext(context);
2318 FreeContext(context);
2322 public void ProcessMethodType(Method method)
2324 if(!method.dataType)
2326 Context context = SetupTemplatesContext(method._class);
2328 method.dataType = ProcessTypeString(method.dataTypeString, false);
2330 FinishTemplatesContext(context);
2332 if(method.type != virtualMethod && method.dataType)
2334 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2336 if(!method._class.symbol)
2337 method._class.symbol = FindClass(method._class.fullName);
2338 method.dataType.thisClass = method._class.symbol;
2342 // Why was this commented out? Working fine without now...
2345 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2346 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2353 char * par = strstr(type, "(");
2354 char * classOp = null;
2359 for(c = par-type-1; c >= 0; c++)
2361 if(type[c] == ':' && type[c+1] == ':')
2363 classOp = type + c - 1;
2364 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2371 else if(!isspace(type[c]))
2378 int typeLen = strlen(type);
2379 memcpy(temp, classOp, classOpLen);
2380 temp[classOpLen] = '\0';
2382 _class = eSystem_FindClass(module, temp);
2385 method.dataTypeString = new char[typeLen - classOpLen + 1];
2386 memcpy(method.dataTypeString, type, classOp - type);
2387 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2390 method.dataTypeString = type;
2396 public void ProcessPropertyType(Property prop)
2400 Context context = SetupTemplatesContext(prop._class);
2401 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2402 FinishTemplatesContext(context);
2406 public void DeclareMethod(Method method, char * name)
2408 Symbol symbol = method.symbol;
2409 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2411 bool imported = false;
2412 bool dllImport = false;
2414 if(!method.dataType)
2415 method.dataType = ProcessTypeString(method.dataTypeString, false);
2417 if(!symbol || symbol._import || method.type == virtualMethod)
2419 if(!symbol || method.type == virtualMethod)
2422 if(!method._class.symbol)
2423 method._class.symbol = FindClass(method._class.fullName);
2424 classSym = method._class.symbol;
2425 if(!classSym._import)
2427 ModuleImport module;
2429 if(method._class.module && method._class.module.name)
2430 module = FindModule(method._class.module);
2432 module = mainModule;
2433 classSym._import = ClassImport
2435 name = CopyString(method._class.fullName);
2436 isRemote = method._class.isRemote;
2438 module.classes.Add(classSym._import);
2442 symbol = method.symbol = Symbol { };
2446 symbol._import = (ClassImport)MethodImport
2448 name = CopyString(method.name);
2449 isVirtual = method.type == virtualMethod;
2451 classSym._import.methods.Add(symbol._import);
2455 // Set the symbol type
2459 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2461 else if(type.thisClass == (void *)-1)
2463 type.thisClass = null;
2466 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2467 symbol.type = method.dataType;
2468 if(symbol.type) symbol.type.refCount++;
2471 if(!method.thisClass || strcmp(method.thisClass, "void"))
2472 symbol.type.params.Insert(null,
2473 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2476 if(!method.dataType.dllExport)
2479 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2485 if(!method.dataType)
2486 method.dataType = ((Symbol)method.symbol).type;
2487 //ProcessMethodType(method);
2490 if(method.type != virtualMethod && method.dataType)
2491 DeclareType(method.dataType, true, true);
2493 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2495 // We need a declaration here :)
2497 OldList * specifiers, * declarators;
2499 Declarator funcDecl;
2502 specifiers = MkList();
2503 declarators = MkList();
2507 ListAdd(specifiers, MkSpecifier(EXTERN));
2508 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2509 ListAdd(specifiers, MkSpecifier(STATIC));
2511 if(method.type == virtualMethod)
2513 ListAdd(specifiers, MkSpecifier(INT));
2514 d = MkDeclaratorIdentifier(MkIdentifier(name));
2518 d = MkDeclaratorIdentifier(MkIdentifier(name));
2521 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2523 Context context = SetupTemplatesContext(method._class);
2524 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2525 FinishTemplatesContext(context);
2527 funcDecl = GetFuncDecl(d);
2531 Specifier spec, next;
2532 for(spec = specifiers->first; spec; spec = next)
2535 if(spec.type == extendedSpecifier)
2537 specifiers->Remove(spec);
2538 FreeSpecifier(spec);
2543 // Add this parameter if not a static method
2544 if(method.dataType && !method.dataType.staticMethod)
2546 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2548 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2549 TypeName thisParam = MkTypeName(MkListOne(
2550 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2551 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2552 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2553 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2555 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2557 TypeName param = funcDecl.function.parameters->first;
2558 funcDecl.function.parameters->Remove(param);
2559 FreeTypeName(param);
2562 if(!funcDecl.function.parameters)
2563 funcDecl.function.parameters = MkList();
2564 funcDecl.function.parameters->Insert(null, thisParam);
2567 // Make sure we don't have empty parameter declarations for static methods...
2569 else if(!funcDecl.function.parameters)
2571 funcDecl.function.parameters = MkList();
2572 funcDecl.function.parameters->Insert(null,
2573 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2577 ProcessDeclarator(d);
2579 ListAdd(declarators, MkInitDeclarator(d, null));
2581 decl = MkDeclaration(specifiers, declarators);
2583 ReplaceThisClassSpecifiers(specifiers, method._class);
2585 // Keep a different symbol for the function definition than the declaration...
2586 if(symbol.pointerExternal)
2588 Symbol functionSymbol { };
2592 *functionSymbol = *symbol;
2593 functionSymbol.string = CopyString(symbol.string);
2594 if(functionSymbol.type)
2595 functionSymbol.type.refCount++;
2598 excludedSymbols->Add(functionSymbol);
2599 symbol.pointerExternal.symbol = functionSymbol;
2601 external = MkExternalDeclaration(decl);
2603 ast->Insert(curExternal ? curExternal.prev : null, external);
2604 external.symbol = symbol;
2605 symbol.pointerExternal = external;
2609 // Move declaration higher...
2610 ast->Move(symbol.pointerExternal, curExternal.prev);
2613 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2617 char * ReplaceThisClass(Class _class)
2619 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2623 ClassTemplateParameter param;
2626 char className[1024];
2627 strcpy(className, _class.fullName);
2628 for(param = _class.templateParams.first; param; param = param.next)
2630 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2632 if(first) strcat(className, "<");
2633 if(!first) strcat(className, ", ");
2634 if(lastParam + 1 != p)
2636 strcat(className, param.name);
2637 strcat(className, " = ");
2639 strcat(className, param.name);
2647 int len = strlen(className);
2648 if(className[len-1] == '>') className[len++] = ' ';
2649 className[len++] = '>';
2650 className[len++] = '\0';
2652 return CopyString(className);
2655 return CopyString(_class.fullName);
2658 Type ReplaceThisClassType(Class _class)
2660 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2664 ClassTemplateParameter param;
2666 char className[1024];
2667 strcpy(className, _class.fullName);
2669 for(param = _class.templateParams.first; param; param = param.next)
2671 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2673 if(first) strcat(className, "<");
2674 if(!first) strcat(className, ", ");
2675 if(lastParam + 1 != p)
2677 strcat(className, param.name);
2678 strcat(className, " = ");
2680 strcat(className, param.name);
2688 int len = strlen(className);
2689 if(className[len-1] == '>') className[len++] = ' ';
2690 className[len++] = '>';
2691 className[len++] = '\0';
2693 return MkClassType(className);
2694 //return ProcessTypeString(className, false);
2698 return MkClassType(_class.fullName);
2699 //return ProcessTypeString(_class.fullName, false);
2703 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2705 if(specs != null && _class)
2708 for(spec = specs.first; spec; spec = spec.next)
2710 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2712 spec.type = nameSpecifier;
2713 spec.name = ReplaceThisClass(_class);
2714 spec.symbol = FindClass(spec.name); //_class.symbol;
2720 // Returns imported or not
2721 bool DeclareFunction(GlobalFunction function, char * name)
2723 Symbol symbol = function.symbol;
2724 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2726 bool imported = false;
2727 bool dllImport = false;
2729 if(!function.dataType)
2731 function.dataType = ProcessTypeString(function.dataTypeString, false);
2732 if(!function.dataType.thisClass)
2733 function.dataType.staticMethod = true;
2740 ModuleImport module = FindModule(function.module);
2741 // WARNING: This is not added anywhere...
2742 symbol = function.symbol = Symbol { };
2746 if(!function.dataType.dllExport)
2748 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2749 module.functions.Add(symbol._import);
2752 // Set the symbol type
2754 symbol.type = ProcessTypeString(function.dataTypeString, false);
2755 if(!symbol.type.thisClass)
2756 symbol.type.staticMethod = true;
2759 imported = symbol._import ? true : false;
2760 if(imported && function.module != privateModule && function.module.importType != staticImport)
2764 DeclareType(function.dataType, true, true);
2768 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2770 // We need a declaration here :)
2772 OldList * specifiers, * declarators;
2774 Declarator funcDecl;
2777 specifiers = MkList();
2778 declarators = MkList();
2781 ListAdd(specifiers, MkSpecifier(EXTERN));
2784 ListAdd(specifiers, MkSpecifier(STATIC));
2787 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2790 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2792 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2793 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2794 if(function.module.importType == staticImport)
2797 for(spec = specifiers->first; spec; spec = spec.next)
2798 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2800 specifiers->Remove(spec);
2801 FreeSpecifier(spec);
2806 funcDecl = GetFuncDecl(d);
2808 // Make sure we don't have empty parameter declarations for static methods...
2809 if(funcDecl && !funcDecl.function.parameters)
2811 funcDecl.function.parameters = MkList();
2812 funcDecl.function.parameters->Insert(null,
2813 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2816 ListAdd(declarators, MkInitDeclarator(d, null));
2819 Context oldCtx = curContext;
2820 curContext = globalContext;
2821 decl = MkDeclaration(specifiers, declarators);
2822 curContext = oldCtx;
2825 // Keep a different symbol for the function definition than the declaration...
2826 if(symbol.pointerExternal)
2828 Symbol functionSymbol { };
2831 *functionSymbol = *symbol;
2832 functionSymbol.string = CopyString(symbol.string);
2833 if(functionSymbol.type)
2834 functionSymbol.type.refCount++;
2837 excludedSymbols->Add(functionSymbol);
2839 symbol.pointerExternal.symbol = functionSymbol;
2841 external = MkExternalDeclaration(decl);
2843 ast->Insert(curExternal.prev, external);
2844 external.symbol = symbol;
2845 symbol.pointerExternal = external;
2849 // Move declaration higher...
2850 ast->Move(symbol.pointerExternal, curExternal.prev);
2854 symbol.id = curExternal.symbol.idCode;
2857 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2860 void DeclareGlobalData(GlobalData data)
2862 Symbol symbol = data.symbol;
2863 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2868 symbol = data.symbol = Symbol { };
2871 data.dataType = ProcessTypeString(data.dataTypeString, false);
2872 DeclareType(data.dataType, true, true);
2875 if(!symbol.pointerExternal)
2877 // We need a declaration here :)
2879 OldList * specifiers, * declarators;
2883 specifiers = MkList();
2884 declarators = MkList();
2886 ListAdd(specifiers, MkSpecifier(EXTERN));
2887 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2888 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2890 ListAdd(declarators, MkInitDeclarator(d, null));
2892 decl = MkDeclaration(specifiers, declarators);
2893 external = MkExternalDeclaration(decl);
2895 ast->Insert(curExternal.prev, external);
2896 external.symbol = symbol;
2897 symbol.pointerExternal = external;
2901 // Move declaration higher...
2902 ast->Move(symbol.pointerExternal, curExternal.prev);
2906 symbol.id = curExternal.symbol.idCode;
2911 class Conversion : struct
2913 Conversion prev, next;
2919 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams, bool isConversionExploration)
2923 // Property convert;
2925 if(source.kind == templateType && dest.kind != templateType)
2927 Type type = ProcessTemplateParameterType(source.templateParameter);
2928 if(type) source = type;
2931 if(dest.kind == templateType && source.kind != templateType)
2933 Type type = ProcessTemplateParameterType(dest.templateParameter);
2934 if(type) dest = type;
2937 if(dest.classObjectType == typedObject)
2939 if(source.classObjectType != anyObject)
2943 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2944 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2952 if(source.classObjectType == anyObject)
2954 if(dest.classObjectType == anyObject && source.classObjectType != typedObject)
2958 if((dest.kind == structType && source.kind == structType) ||
2959 (dest.kind == unionType && source.kind == unionType))
2961 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2962 (source.members.first && source.members.first == dest.members.first))
2966 if(dest.kind == ellipsisType && source.kind != voidType)
2969 if(dest.kind == pointerType && dest.type.kind == voidType &&
2970 ((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))
2971 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2973 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2975 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2977 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2978 ((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))
2979 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2981 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2983 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2986 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2988 if(source._class.registered && source._class.registered.type == unitClass)
2990 if(conversions != null)
2992 if(source._class.registered == dest._class.registered)
2997 Class sourceBase, destBase;
2998 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2999 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
3000 if(sourceBase == destBase)
3004 // Don't match enum inheriting from other enum if resolving enumeration values
3005 // TESTING: !dest.classObjectType
3006 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
3008 (!source._class.registered || source._class.registered.type != enumClass) ||
3009 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
3013 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
3015 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
3016 ((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)
3018 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3026 // JUST ADDED THIS...
3027 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3032 // Just added this for Straight conversion of ColorAlpha => Color
3033 if(source.kind == classType)
3036 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3039 for(convert = _class.conversions.first; convert; convert = convert.next)
3041 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3043 Conversion after = (conversions != null) ? conversions.last : null;
3045 if(!convert.dataType)
3046 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3047 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3048 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3049 MatchTypes(convert.dataType, dest, conversions, null, null,
3050 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3051 convert.dataType.kind == classType, false, true))
3053 if(!conversions && !convert.Get)
3055 else if(conversions != null)
3057 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3058 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3059 (dest.kind != classType || dest._class.registered != _class.base))
3063 Conversion conv { convert = convert, isGet = true };
3064 // conversions.Add(conv);
3065 conversions.Insert(after, conv);
3077 if(dest.kind == classType)
3080 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3083 for(convert = _class.conversions.first; convert; convert = convert.next)
3085 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3087 // Conversion after = (conversions != null) ? conversions.last : null;
3089 if(!convert.dataType)
3090 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3091 // Just added this equality check to prevent recursion.... Make it safer?
3092 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3093 if(convert.dataType != dest && MatchTypes(source, convert.dataType, conversions, null, null, true, false /*true*/, false, true))
3095 if(!conversions && !convert.Set)
3097 else if(conversions != null)
3099 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3100 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3101 (source.kind != classType || source._class.registered != _class.base))
3105 // *** Testing this! ***
3106 Conversion conv { convert = convert };
3107 conversions.Add(conv);
3108 //conversions.Insert(after, conv);
3116 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3118 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3119 (source.kind != classType || source._class.registered.type != structClass))
3123 // TESTING THIS... IS THIS OK??
3124 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3126 if(!dest._class.registered.dataType)
3127 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3128 // Only support this for classes...
3129 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3130 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3132 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false))
3141 if(source.kind == classType)
3144 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3147 for(convert = _class.conversions.first; convert; convert = convert.next)
3149 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3151 Conversion after = (conversions != null) ? conversions.last : null;
3153 if(!convert.dataType)
3154 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3155 if(convert.dataType != source &&
3156 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3157 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true))
3159 if(!conversions && !convert.Get)
3161 else if(conversions != null)
3163 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3164 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3165 (dest.kind != classType || dest._class.registered != _class.base))
3169 Conversion conv { convert = convert, isGet = true };
3171 // conversions.Add(conv);
3172 conversions.Insert(after, conv);
3181 // TESTING THIS... IS THIS OK??
3182 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3184 if(!source._class.registered.dataType)
3185 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3186 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3188 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, source._class.registered.dataType.kind == classType, source._class.registered.dataType.kind == classType, false, false))
3190 // For bool to be accepted by byte, short, etc.
3191 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false))
3198 if(source.kind == classType || source.kind == subClassType)
3200 else if(dest.kind == source.kind &&
3201 (dest.kind != structType && dest.kind != unionType &&
3202 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3204 // RECENTLY ADDED THESE
3205 else if(dest.kind == doubleType && source.kind == floatType)
3207 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3209 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3211 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3213 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3215 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3217 else if(source.kind == enumType &&
3218 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3220 else if(dest.kind == enumType && !isConversionExploration &&
3221 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3223 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3224 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3226 Type paramSource, paramDest;
3228 if(dest.kind == methodType)
3229 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3230 if(source.kind == methodType)
3231 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3233 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3234 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3235 if(dest.kind == methodType)
3236 dest = dest.method.dataType;
3237 if(source.kind == methodType)
3238 source = source.method.dataType;
3240 paramSource = source.params.first;
3241 if(paramSource && paramSource.kind == voidType) paramSource = null;
3242 paramDest = dest.params.first;
3243 if(paramDest && paramDest.kind == voidType) paramDest = null;
3246 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3247 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3249 // Source thisClass must be derived from destination thisClass
3250 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3251 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3253 if(paramDest && paramDest.kind == classType)
3254 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3256 Compiler_Error($"method class should not take an object\n");
3259 paramDest = paramDest.next;
3261 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3263 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3267 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3269 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3275 // THIS WAS BACKWARDS:
3276 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3277 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3280 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3282 Compiler_Error($"overriding class expected to be derived from method class\n");
3286 paramSource = paramSource.next;
3292 // Source thisClass must be derived from destination thisClass
3293 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3295 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3301 // THIS WAS BACKWARDS TOO??
3302 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3303 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3306 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3308 //Compiler_Error($"overriding class expected to be derived from method class\n");
3316 // Source return type must be derived from destination return type
3317 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false))
3319 Compiler_Warning($"incompatible return type for function\n");
3325 for(; paramDest; paramDest = paramDest.next)
3329 //Compiler_Warning($"not enough parameters\n");
3330 Compiler_Error($"not enough parameters\n");
3334 Type paramDestType = paramDest;
3335 Type paramSourceType = paramSource;
3336 Type type = paramDestType;
3338 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3339 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3340 paramSource.kind != templateType)
3343 ClassTemplateParameter curParam = null;
3345 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3348 if(sClass.templateClass) sClass = sClass.templateClass;
3349 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3351 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3353 for(sClass = sClass.base; sClass; sClass = sClass.base)
3355 if(sClass.templateClass) sClass = sClass.templateClass;
3356 id += sClass.templateParams.count;
3367 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3368 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3372 // paramDest must be derived from paramSource
3373 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false) &&
3374 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false)))
3378 PrintType(paramDest, type, false, true);
3379 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3381 if(paramDestType != paramDest)
3382 FreeType(paramDestType);
3385 if(paramDestType != paramDest)
3386 FreeType(paramDestType);
3389 paramSource = paramSource.next;
3393 Compiler_Error($"too many parameters\n");
3398 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3402 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3403 (source.kind == arrayType || source.kind == pointerType))
3405 if(MatchTypes(source.type, dest.type, null, null, null, true, true, false, false))
3412 static void FreeConvert(Conversion convert)
3414 if(convert.resultType)
3415 FreeType(convert.resultType);
3418 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3419 char * string, OldList conversions)
3423 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3425 Class _class = link.data;
3426 if(_class.type == enumClass)
3428 OldList converts { };
3430 type.kind = classType;
3433 _class.symbol = FindClass(_class.fullName);
3434 type._class = _class.symbol;
3436 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false))
3439 Class enumClass = eSystem_FindClass(privateModule, "enum");
3443 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3445 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3446 for(value = e.values.first; value; value = value.next)
3448 if(!strcmp(value.name, string))
3453 FreeExpContents(sourceExp);
3454 FreeType(sourceExp.expType);
3456 sourceExp.isConstant = true;
3457 sourceExp.expType = MkClassType(baseClass.fullName);
3461 sourceExp.type = constantExp;
3462 if(!strcmp(baseClass.dataTypeString, "int"))
3463 sprintf(constant, "%d",(int)value.data);
3465 sprintf(constant, "0x%X",(int)value.data);
3466 sourceExp.constant = CopyString(constant);
3467 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3470 while(converts.first)
3472 Conversion convert = converts.first;
3473 converts.Remove(convert);
3474 conversions.Add(convert);
3483 converts.Free(FreeConvert);
3487 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3488 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3493 public bool ModuleVisibility(Module searchIn, Module searchFor)
3495 SubModule subModule;
3497 if(searchFor == searchIn)
3500 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3502 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3504 if(ModuleVisibility(subModule.module, searchFor))
3511 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3515 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3517 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3519 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3522 for(module = mainModule.application.allModules.first; module; module = module.next)
3524 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3530 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla)
3533 Type realDest = dest;
3534 Type backupSourceExpType = null;
3535 Expression computedExp = sourceExp;
3538 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3539 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3541 computedExp = CopyExpression(sourceExp); // Keep the original expression, but compute for checking enum ranges
3542 ComputeExpression(computedExp /*sourceExp*/);
3545 source = sourceExp.expType;
3547 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3549 if(computedExp != sourceExp)
3551 FreeExpression(computedExp);
3552 computedExp = sourceExp;
3558 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3560 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3562 Class sourceBase, destBase;
3563 for(sourceBase = source._class.registered;
3564 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3565 sourceBase = sourceBase.base);
3566 for(destBase = dest._class.registered;
3567 destBase && destBase.base && destBase.base.type != systemClass;
3568 destBase = destBase.base);
3569 //if(source._class.registered == dest._class.registered)
3570 if(sourceBase == destBase)
3572 if(computedExp != sourceExp)
3574 FreeExpression(computedExp);
3575 computedExp = sourceExp;
3587 int64 value = MAXINT;
3591 if(computedExp.type == constantExp)
3594 value = strtoll(computedExp.constant, null, 0);
3596 value = strtoull(computedExp.constant, null, 0);
3598 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3601 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3603 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3605 if(computedExp != sourceExp)
3607 FreeExpression(computedExp);
3608 computedExp = sourceExp;
3611 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3612 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3615 source = Type { kind = intType, isSigned = false, refCount = 1 };
3618 if(dest.kind == classType)
3620 Class _class = dest._class ? dest._class.registered : null;
3622 if(_class && _class.type == unitClass)
3624 if(source.kind != classType)
3627 Type tempDest, tempSource;
3629 for(; _class.base.type != systemClass; _class = _class.base);
3631 tempDest = tempType;
3633 tempType.kind = classType;
3635 _class.symbol = FindClass(_class.fullName);
3637 tempType._class = _class.symbol;
3638 tempType.truth = dest.truth;
3640 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3642 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3643 backupSourceExpType = sourceExp.expType;
3644 sourceExp.expType = dest; dest.refCount++;
3645 //sourceExp.expType = MkClassType(_class.fullName);
3653 // Why wasn't there something like this?
3654 if(_class && _class.type == bitClass && source.kind != classType)
3656 if(!dest._class.registered.dataType)
3657 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3658 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false))
3661 FreeType(sourceExp.expType);
3662 source = sourceExp.expType = MkClassType(dest._class.string);
3665 //source.kind = classType;
3666 //source._class = dest._class;
3670 // Adding two enumerations
3672 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3674 if(!source._class.registered.dataType)
3675 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3676 if(!dest._class.registered.dataType)
3677 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3679 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3682 source = sourceExp.expType = MkClassType(dest._class.string);
3685 //source.kind = classType;
3686 //source._class = dest._class;
3690 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3692 OldList * specs = MkList();
3696 ReadString(string, sourceExp.string);
3697 decl = SpecDeclFromString(string, specs, null);
3699 FreeExpContents(sourceExp);
3700 FreeType(sourceExp.expType);
3702 sourceExp.type = classExp;
3703 sourceExp._classExp.specifiers = specs;
3704 sourceExp._classExp.decl = decl;
3705 sourceExp.expType = dest;
3710 if(backupSourceExpType) FreeType(backupSourceExpType);
3714 else if(source.kind == classType)
3716 Class _class = source._class ? source._class.registered : null;
3718 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3721 if(dest.kind != classType)
3723 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3724 if(!source._class.registered.dataType)
3725 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3728 dest = MkClassType(source._class.string);
3729 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3730 // dest = MkClassType(source._class.string);
3734 if(dest.kind != classType)
3737 Type tempDest, tempSource;
3739 if(!source._class.registered.dataType)
3740 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3742 for(; _class.base.type != systemClass; _class = _class.base);
3744 tempSource = tempType;
3745 tempType.kind = classType;
3746 tempType._class = FindClass(_class.fullName);
3747 tempType.truth = source.truth;
3748 tempType.classObjectType = source.classObjectType;
3751 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false);
3753 // PUT THIS BACK TESTING UNITS?
3754 if(conversions.last)
3756 ((Conversion)(conversions.last)).resultType = dest;
3760 FreeType(sourceExp.expType);
3761 sourceExp.expType = MkClassType(_class.fullName);
3762 sourceExp.expType.truth = source.truth;
3763 sourceExp.expType.classObjectType = source.classObjectType;
3765 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3767 if(!sourceExp.destType)
3769 FreeType(sourceExp.destType);
3770 sourceExp.destType = sourceExp.expType;
3771 if(sourceExp.expType)
3772 sourceExp.expType.refCount++;
3775 //source = _class.dataType;
3778 // TOCHECK: TESTING THIS NEW CODE
3779 if(!_class.dataType)
3780 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3782 dest = MkClassType(source._class.string);
3783 dest.truth = source.truth;
3784 dest.classObjectType = source.classObjectType;
3787 source = _class.dataType;
3797 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false))
3807 if(source.kind == classType)
3809 Class _class = source._class.registered;
3810 if(_class.type == unitClass)
3812 if(!_class.dataType)
3813 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3814 source = _class.dataType;
3818 if(dest.kind == classType)
3820 Class _class = dest._class ? dest._class.registered : null;
3821 bool fittingValue = false;
3822 if(_class && _class.type == enumClass)
3824 Class enumClass = eSystem_FindClass(privateModule, "enum");
3825 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3826 if(c && value >= 0 && value <= c.largest)
3827 fittingValue = true;
3830 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3831 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3833 if(_class.type == normalClass || _class.type == noHeadClass)
3835 Expression newExp { };
3836 *newExp = *sourceExp;
3837 if(sourceExp.destType) sourceExp.destType.refCount++;
3838 if(sourceExp.expType) sourceExp.expType.refCount++;
3839 sourceExp.type = castExp;
3840 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3841 sourceExp.cast.exp = newExp;
3842 FreeType(sourceExp.expType);
3843 sourceExp.expType = null;
3844 ProcessExpressionType(sourceExp);
3846 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3849 FreeType(sourceExp.expType);
3850 sourceExp.expType = dest;
3854 if(inCompiler) FreeType(dest);
3856 if(backupSourceExpType) FreeType(backupSourceExpType);
3860 if(!_class.dataType)
3861 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3863 dest = _class.dataType;
3867 // Accept lower precision types for units, since we want to keep the unit type
3868 if(dest.kind == doubleType &&
3869 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3870 source.kind == charType || source.kind == _BoolType))
3872 specs = MkListOne(MkSpecifier(DOUBLE));
3874 else if(dest.kind == floatType &&
3875 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3876 source.kind == _BoolType || source.kind == doubleType))
3878 specs = MkListOne(MkSpecifier(FLOAT));
3880 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3881 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3884 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3885 ListAdd(specs, MkSpecifier(INT64));
3887 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3888 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3891 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3892 ListAdd(specs, MkSpecifier(INT));
3894 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3895 source.kind == floatType || source.kind == doubleType))
3898 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3899 ListAdd(specs, MkSpecifier(SHORT));
3901 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3902 source.kind == floatType || source.kind == doubleType))
3905 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3906 ListAdd(specs, MkSpecifier(CHAR));
3912 if(backupSourceExpType)
3914 // Failed to convert: revert previous exp type
3915 if(sourceExp.expType) FreeType(sourceExp.expType);
3916 sourceExp.expType = backupSourceExpType;
3921 else if(dest.kind == doubleType &&
3922 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3923 source.kind == _BoolType || source.kind == charType))
3925 specs = MkListOne(MkSpecifier(DOUBLE));
3927 else if(dest.kind == floatType &&
3928 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3930 specs = MkListOne(MkSpecifier(FLOAT));
3932 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3933 (value == 1 || value == 0))
3936 ListAdd(specs, MkSpecifier(BOOL));
3938 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3939 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3942 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3943 ListAdd(specs, MkSpecifier(CHAR));
3945 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3946 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3949 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3950 ListAdd(specs, MkSpecifier(SHORT));
3952 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3955 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3956 ListAdd(specs, MkSpecifier(INT));
3958 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3961 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3962 ListAdd(specs, MkSpecifier(INT64));
3964 else if(dest.kind == enumType &&
3965 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3967 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3973 if(backupSourceExpType)
3975 // Failed to convert: revert previous exp type
3976 if(sourceExp.expType) FreeType(sourceExp.expType);
3977 sourceExp.expType = backupSourceExpType;
3982 if(!flag && !sourceExp.opDestType)
3984 Expression newExp { };
3985 *newExp = *sourceExp;
3988 if(sourceExp.destType) sourceExp.destType.refCount++;
3989 if(sourceExp.expType) sourceExp.expType.refCount++;
3991 sourceExp.type = castExp;
3992 if(realDest.kind == classType)
3994 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3995 FreeList(specs, FreeSpecifier);
3998 sourceExp.cast.typeName = MkTypeName(specs, null);
3999 if(newExp.type == opExp)
4001 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4004 sourceExp.cast.exp = newExp;
4006 FreeType(sourceExp.expType);
4007 sourceExp.expType = null;
4008 ProcessExpressionType(sourceExp);
4011 FreeList(specs, FreeSpecifier);
4015 if(backupSourceExpType) FreeType(backupSourceExpType);
4021 if(computedExp != sourceExp)
4023 FreeExpression(computedExp);
4024 computedExp = sourceExp;
4027 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4028 if(sourceExp.type == identifierExp)
4030 Identifier id = sourceExp.identifier;
4031 if(dest.kind == classType)
4033 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4035 Class _class = dest._class.registered;
4036 Class enumClass = eSystem_FindClass(privateModule, "enum");
4039 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4042 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4043 for(value = e.values.first; value; value = value.next)
4045 if(!strcmp(value.name, id.string))
4050 FreeExpContents(sourceExp);
4051 FreeType(sourceExp.expType);
4053 sourceExp.isConstant = true;
4054 sourceExp.expType = MkClassType(_class.fullName);
4058 sourceExp.type = constantExp;
4059 if(/*_class && */_class.dataTypeString && !strcmp(_class.dataTypeString, "int")) // _class cannot be null here!
4060 sprintf(constant, "%d", (int) value.data);
4062 sprintf(constant, "0x%X", (int) value.data);
4063 sourceExp.constant = CopyString(constant);
4064 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4074 // Loop through all enum classes
4075 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4086 #define TERTIARY(o, name, m, t, p) \
4087 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4089 exp.type = constantExp; \
4090 exp.string = p(op1.m ? op2.m : op3.m); \
4092 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4096 #define BINARY(o, name, m, t, p) \
4097 static bool name(Expression exp, Operand op1, Operand op2) \
4100 exp.type = constantExp; \
4101 exp.string = p((t)(op1.m o value2)); \
4103 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4107 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4108 static bool name(Expression exp, Operand op1, Operand op2) \
4111 exp.type = constantExp; \
4112 exp.string = p(value2 ? (op1.m o value2) : 0); \
4114 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4118 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4119 static bool name(Expression exp, Operand op1, Operand op2) \
4122 exp.type = constantExp; \
4123 exp.string = p(op1.m o value2); \
4125 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4129 #define UNARY(o, name, m, t, p) \
4130 static bool name(Expression exp, Operand op1) \
4132 exp.type = constantExp; \
4133 exp.string = p((t)(o op1.m)); \
4135 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4139 #define OPERATOR_ALL(macro, o, name) \
4140 macro(o, Int##name, i, int, PrintInt) \
4141 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4142 macro(o, Int64##name, i64, int64, PrintInt64) \
4143 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4144 macro(o, Short##name, s, short, PrintShort) \
4145 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4146 macro(o, Char##name, c, char, PrintChar) \
4147 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4148 macro(o, Float##name, f, float, PrintFloat) \
4149 macro(o, Double##name, d, double, PrintDouble)
4151 #define OPERATOR_INTTYPES(macro, o, name) \
4152 macro(o, Int##name, i, int, PrintInt) \
4153 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4154 macro(o, Int64##name, i64, int64, PrintInt64) \
4155 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4156 macro(o, Short##name, s, short, PrintShort) \
4157 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4158 macro(o, Char##name, c, char, PrintChar) \
4159 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4161 #define OPERATOR_REALTYPES(macro, o, name) \
4162 macro(o, Float##name, f, float, PrintFloat) \
4163 macro(o, Double##name, d, double, PrintDouble)
4165 // binary arithmetic
4166 OPERATOR_ALL(BINARY, +, Add)
4167 OPERATOR_ALL(BINARY, -, Sub)
4168 OPERATOR_ALL(BINARY, *, Mul)
4169 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4170 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4171 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4174 OPERATOR_ALL(UNARY, -, Neg)
4176 // unary arithmetic increment and decrement
4177 OPERATOR_ALL(UNARY, ++, Inc)
4178 OPERATOR_ALL(UNARY, --, Dec)
4180 // binary arithmetic assignment
4181 OPERATOR_ALL(BINARY, =, Asign)
4182 OPERATOR_ALL(BINARY, +=, AddAsign)
4183 OPERATOR_ALL(BINARY, -=, SubAsign)
4184 OPERATOR_ALL(BINARY, *=, MulAsign)
4185 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4186 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4187 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4190 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4191 OPERATOR_INTTYPES(BINARY, |, BitOr)
4192 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4193 OPERATOR_INTTYPES(BINARY, <<, LShift)
4194 OPERATOR_INTTYPES(BINARY, >>, RShift)
4197 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4199 // binary bitwise assignment
4200 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4201 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4202 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4203 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4204 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4206 // unary logical negation
4207 OPERATOR_INTTYPES(UNARY, !, Not)
4209 // binary logical equality
4210 OPERATOR_ALL(BINARY, ==, Equ)
4211 OPERATOR_ALL(BINARY, !=, Nqu)
4214 OPERATOR_ALL(BINARY, &&, And)
4215 OPERATOR_ALL(BINARY, ||, Or)
4217 // binary logical relational
4218 OPERATOR_ALL(BINARY, >, Grt)
4219 OPERATOR_ALL(BINARY, <, Sma)
4220 OPERATOR_ALL(BINARY, >=, GrtEqu)
4221 OPERATOR_ALL(BINARY, <=, SmaEqu)
4223 // tertiary condition operator
4224 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4226 //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
4227 #define OPERATOR_TABLE_ALL(name, type) \
4228 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4230 type##Inc, type##Dec, \
4231 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4232 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4234 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4236 type##Equ, type##Nqu, \
4237 type##And, type##Or, \
4238 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4241 #define OPERATOR_TABLE_INTTYPES(name, type) \
4242 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4244 type##Inc, type##Dec, \
4245 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4246 null, null, null, null, null, \
4248 null, null, null, null, null, \
4250 type##Equ, type##Nqu, \
4251 type##And, type##Or, \
4252 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4255 OPERATOR_TABLE_ALL(int, Int)
4256 OPERATOR_TABLE_ALL(uint, UInt)
4257 OPERATOR_TABLE_ALL(int64, Int64)
4258 OPERATOR_TABLE_ALL(uint64, UInt64)
4259 OPERATOR_TABLE_ALL(short, Short)
4260 OPERATOR_TABLE_ALL(ushort, UShort)
4261 OPERATOR_TABLE_INTTYPES(float, Float)
4262 OPERATOR_TABLE_INTTYPES(double, Double)
4263 OPERATOR_TABLE_ALL(char, Char)
4264 OPERATOR_TABLE_ALL(uchar, UChar)
4266 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4267 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4268 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4269 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4270 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4271 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4272 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4273 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4275 public void ReadString(char * output, char * string)
4277 int len = strlen(string);
4279 bool quoted = false, escaped = false;
4280 for(c = 0; c<len; c++)
4282 char ch = string[c];
4287 case 'n': output[d] = '\n'; break;
4288 case 't': output[d] = '\t'; break;
4289 case 'a': output[d] = '\a'; break;
4290 case 'b': output[d] = '\b'; break;
4291 case 'f': output[d] = '\f'; break;
4292 case 'r': output[d] = '\r'; break;
4293 case 'v': output[d] = '\v'; break;
4294 case '\\': output[d] = '\\'; break;
4295 case '\"': output[d] = '\"'; break;
4296 case '\'': output[d] = '\''; break;
4297 default: output[d] = ch;
4318 // String Unescape Copy
4320 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4321 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4322 public int UnescapeString(char * d, char * s, int len)
4326 while(j < len && (ch = s[j]))
4331 switch((ch = s[++j]))
4333 case 'n': d[k] = '\n'; break;
4334 case 't': d[k] = '\t'; break;
4335 case 'a': d[k] = '\a'; break;
4336 case 'b': d[k] = '\b'; break;
4337 case 'f': d[k] = '\f'; break;
4338 case 'r': d[k] = '\r'; break;
4339 case 'v': d[k] = '\v'; break;
4340 case '\\': d[k] = '\\'; break;
4341 case '\"': d[k] = '\"'; break;
4342 case '\'': d[k] = '\''; break;
4343 default: d[k] = '\\'; d[k] = ch;
4355 public char * OffsetEscapedString(char * s, int len, int offset)
4359 while(j < len && k < offset && (ch = s[j]))
4364 return (k == offset) ? s + j : null;
4367 public Operand GetOperand(Expression exp)
4370 Type type = exp.expType;
4373 while(type.kind == classType &&
4374 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4376 if(!type._class.registered.dataType)
4377 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4378 type = type._class.registered.dataType;
4381 if(exp.type == stringExp && op.kind == pointerType)
4383 op.ui64 = (uint64)exp.string;
4384 op.kind = pointerType;
4387 else if(exp.isConstant && exp.type == constantExp)
4389 op.kind = type.kind;
4390 op.type = exp.expType;
4397 if(exp.constant[0] == '\'')
4399 op.c = exp.constant[1];
4402 else if(type.isSigned)
4404 op.c = (char)strtol(exp.constant, null, 0);
4409 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4417 op.s = (short)strtol(exp.constant, null, 0);
4422 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4430 op.i = (int)strtol(exp.constant, null, 0);
4435 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4443 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4448 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4451 op.kind = int64Type;
4456 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4461 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4464 op.kind = int64Type;
4469 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4474 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4477 op.kind = int64Type;
4480 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4481 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4482 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4483 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4485 op.f = (float)strtod(exp.constant, null);
4489 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4490 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4491 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4492 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4494 op.d = (double)strtod(exp.constant, null);
4497 //case classType: For when we have operator overloading...
4498 // Pointer additions
4499 //case functionType:
4503 op.ui64 = _strtoui64(exp.constant, null, 0);
4504 op.kind = pointerType;
4514 static void UnusedFunction()
4517 a.OnGetString(0,0,0);
4520 extern int __ecereVMethodID_class_OnGetString;
4523 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4525 DataMember dataMember;
4526 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4528 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4529 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4533 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4535 void * ptr = inst.data + dataMember.offset + offset;
4536 char * result = null;
4537 exp.loc = member.loc = inst.loc;
4538 ((Identifier)member.identifiers->first).loc = inst.loc;
4540 if(!dataMember.dataType)
4541 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4542 type = dataMember.dataType;
4543 if(type.kind == classType)
4545 Class _class = type._class.registered;
4546 if(_class.type == enumClass)
4548 Class enumClass = eSystem_FindClass(privateModule, "enum");
4551 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4553 for(item = e.values.first; item; item = item.next)
4555 if((int)item.data == *(int *)ptr)
4563 exp.identifier = MkIdentifier(result);
4564 exp.type = identifierExp;
4565 exp.destType = MkClassType(_class.fullName);
4566 ProcessExpressionType(exp);
4570 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4572 if(!_class.dataType)
4573 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4574 type = _class.dataType;
4583 FreeExpContents(exp);
4585 exp.constant = PrintFloat(*(float*)ptr);
4586 exp.type = constantExp;
4591 FreeExpContents(exp);
4593 exp.constant = PrintDouble(*(double*)ptr);
4594 exp.type = constantExp;
4599 FreeExpContents(exp);
4601 exp.constant = PrintInt(*(int*)ptr);
4602 exp.type = constantExp;
4607 FreeExpContents(exp);
4609 exp.constant = PrintInt64(*(int64*)ptr);
4610 exp.type = constantExp;
4615 FreeExpContents(exp);
4616 // TODO: This should probably use proper type
4617 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4618 exp.type = constantExp;
4623 FreeExpContents(exp);
4624 // TODO: This should probably use proper type
4625 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4626 exp.type = constantExp;
4630 Compiler_Error($"Unhandled type populating instance\n");
4633 ListAdd(memberList, member);
4636 if(parentDataMember.type == unionMember)
4641 void PopulateInstance(Instantiation inst)
4643 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4644 Class _class = classSym.registered;
4645 DataMember dataMember;
4646 OldList * memberList = MkList();
4647 // Added this check and ->Add to prevent memory leaks on bad code
4649 inst.members = MkListOne(MkMembersInitList(memberList));
4651 inst.members->Add(MkMembersInitList(memberList));
4652 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4654 if(!dataMember.isProperty)
4656 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4657 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4661 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4663 void * ptr = inst.data + dataMember.offset;
4664 char * result = null;
4666 exp.loc = member.loc = inst.loc;
4667 ((Identifier)member.identifiers->first).loc = inst.loc;
4669 if(!dataMember.dataType)
4670 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4671 type = dataMember.dataType;
4672 if(type.kind == classType)
4674 Class _class = type._class.registered;
4675 if(_class.type == enumClass)
4677 Class enumClass = eSystem_FindClass(privateModule, "enum");
4680 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4682 for(item = e.values.first; item; item = item.next)
4684 if((int)item.data == *(int *)ptr)
4693 exp.identifier = MkIdentifier(result);
4694 exp.type = identifierExp;
4695 exp.destType = MkClassType(_class.fullName);
4696 ProcessExpressionType(exp);
4699 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4701 if(!_class.dataType)
4702 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4703 type = _class.dataType;
4712 exp.constant = PrintFloat(*(float*)ptr);
4713 exp.type = constantExp;
4718 exp.constant = PrintDouble(*(double*)ptr);
4719 exp.type = constantExp;
4724 exp.constant = PrintInt(*(int*)ptr);
4725 exp.type = constantExp;
4730 exp.constant = PrintInt64(*(int64*)ptr);
4731 exp.type = constantExp;
4736 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4737 exp.type = constantExp;
4741 Compiler_Error($"Unhandled type populating instance\n");
4744 ListAdd(memberList, member);
4750 void ComputeInstantiation(Expression exp)
4752 Instantiation inst = exp.instance;
4753 MembersInit members;
4754 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4755 Class _class = classSym ? classSym.registered : null;
4756 DataMember curMember = null;
4757 Class curClass = null;
4758 DataMember subMemberStack[256];
4759 int subMemberStackPos = 0;
4762 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4764 // Don't recompute the instantiation...
4765 // Non Simple classes will have become constants by now
4769 if(_class.type == normalClass || _class.type == noHeadClass)
4771 inst.data = (byte *)eInstance_New(_class);
4772 if(_class.type == normalClass)
4773 ((Instance)inst.data)._refCount++;
4776 inst.data = new0 byte[_class.structSize];
4781 for(members = inst.members->first; members; members = members.next)
4783 switch(members.type)
4785 case dataMembersInit:
4787 if(members.dataMembers)
4790 for(member = members.dataMembers->first; member; member = member.next)
4792 Identifier ident = member.identifiers ? member.identifiers->first : null;
4795 Property prop = null;
4796 DataMember dataMember = null;
4797 Method method = null;
4798 uint dataMemberOffset;
4802 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4805 if(curMember.isProperty)
4806 prop = (Property)curMember;
4809 dataMember = curMember;
4811 // CHANGED THIS HERE
4812 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4814 // 2013/17/29 -- It seems that this was missing here!
4815 if(_class.type == normalClass)
4816 dataMemberOffset += _class.base.structSize;
4817 // dataMemberOffset = dataMember.offset;
4824 prop = eClass_FindProperty(_class, ident.string, privateModule);
4828 if(prop.memberAccess == publicAccess)
4830 curMember = (DataMember)prop;
4831 curClass = prop._class;
4836 DataMember _subMemberStack[256];
4837 int _subMemberStackPos = 0;
4839 // FILL MEMBER STACK
4840 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4845 if(dataMember.memberAccess == publicAccess)
4847 curMember = dataMember;
4848 curClass = dataMember._class;
4849 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4850 subMemberStackPos = _subMemberStackPos;
4856 if(found && member.initializer && member.initializer.type == expInitializer)
4858 Expression value = member.initializer.exp;
4860 bool deepMember = false;
4863 type = prop.dataType;
4867 if(!dataMember.dataType)
4868 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4870 type = dataMember.dataType;
4873 if(ident && ident.next)
4877 // for(; ident && type; ident = ident.next)
4878 for(ident = ident.next; ident && type; ident = ident.next)
4880 if(type.kind == classType)
4882 prop = eClass_FindProperty(type._class.registered,
4883 ident.string, privateModule);
4885 type = prop.dataType;
4888 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4889 ident.string, &dataMemberOffset, privateModule, null, null);
4891 type = dataMember.dataType;
4894 else if(type.kind == structType || type.kind == unionType)
4897 for(memberType = type.members.first; memberType; memberType = memberType.next)
4899 if(!strcmp(memberType.name, ident.string))
4910 FreeType(value.destType);
4911 value.destType = type;
4912 if(type) type.refCount++;
4913 ComputeExpression(value);
4915 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4917 if(type.kind == classType)
4919 Class _class = type._class.registered;
4920 if(_class.type == bitClass || _class.type == unitClass ||
4921 _class.type == enumClass)
4923 if(!_class.dataType)
4924 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4925 type = _class.dataType;
4931 void * ptr = inst.data + dataMemberOffset;
4933 if(value.type == constantExp)
4939 GetInt(value, (int*)ptr);
4944 GetInt64(value, (int64*)ptr);
4949 GetIntPtr(value, (intptr*)ptr);
4954 GetIntSize(value, (intsize*)ptr);
4959 GetFloat(value, (float*)ptr);
4964 GetDouble(value, (double *)ptr);
4969 else if(value.type == instanceExp)
4971 if(type.kind == classType)
4973 Class _class = type._class.registered;
4974 if(_class.type == structClass)
4976 ComputeTypeSize(type);
4977 if(value.instance.data)
4978 memcpy(ptr, value.instance.data, type.size);
4985 if(value.type == instanceExp && value.instance.data)
4987 if(type.kind == classType)
4989 Class _class = type._class.registered;
4990 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
4992 void (*Set)(void *, void *) = (void *)prop.Set;
4993 Set(inst.data, value.instance.data);
4994 PopulateInstance(inst);
4998 else if(value.type == constantExp)
5004 void (*Set)(void *, double) = (void *)prop.Set;
5005 Set(inst.data, strtod(value.constant, null) );
5010 void (*Set)(void *, float) = (void *)prop.Set;
5011 Set(inst.data, (float)(strtod(value.constant, null)));
5016 void (*Set)(void *, int) = (void *)prop.Set;
5017 Set(inst.data, (int)strtol(value.constant, null, 0));
5022 void (*Set)(void *, int64) = (void *)prop.Set;
5023 Set(inst.data, _strtoi64(value.constant, null, 0));
5028 void (*Set)(void *, intptr) = (void *)prop.Set;
5029 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5034 void (*Set)(void *, intsize) = (void *)prop.Set;
5035 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5040 else if(value.type == stringExp)
5043 ReadString(temp, value.string);
5044 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5048 else if(!deepMember && type && _class.type == unitClass)
5052 // Only support converting units to units for now...
5053 if(value.type == constantExp)
5055 if(type.kind == classType)
5057 Class _class = type._class.registered;
5058 if(_class.type == unitClass)
5060 if(!_class.dataType)
5061 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5062 type = _class.dataType;
5065 // TODO: Assuming same base type for units...
5071 float (*Set)(float) = (void *)prop.Set;
5072 GetFloat(member.initializer.exp, &fValue);
5073 exp.constant = PrintFloat(Set(fValue));
5074 exp.type = constantExp;
5080 double (*Set)(double) = (void *)prop.Set;
5081 GetDouble(member.initializer.exp, &dValue);
5082 exp.constant = PrintDouble(Set(dValue));
5083 exp.type = constantExp;
5090 else if(!deepMember && type && _class.type == bitClass)
5094 if(value.type == instanceExp && value.instance.data)
5096 unsigned int (*Set)(void *) = (void *)prop.Set;
5097 bits = Set(value.instance.data);
5099 else if(value.type == constantExp)
5105 BitMember bitMember = (BitMember) dataMember;
5108 bits = (bits & ~bitMember.mask);
5109 if(!bitMember.dataType)
5110 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5111 type = bitMember.dataType;
5112 if(type.kind == classType && type._class && type._class.registered)
5114 if(!type._class.registered.dataType)
5115 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5116 type = type._class.registered.dataType;
5121 case charType: { byte v; type.isSigned ? GetChar(value, &v) : GetUChar(value, &v); part = (uint64)v; break; }
5122 case shortType: { uint16 v; type.isSigned ? GetShort(value, &v) : GetUShort(value, &v); part = (uint64)v; break; }
5124 case longType: { uint v; type.isSigned ? GetInt(value, &v) : GetUInt(value, &v); part = (uint64)v; break; }
5125 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, &v) : GetUInt64(value, &v); part = (uint64)v; break; }
5126 case intPtrType: { intptr v; type.isSigned ? GetIntPtr(value, &v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5127 case intSizeType: { intsize v; type.isSigned ? GetIntSize(value, &v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5129 bits |= part << bitMember.pos;
5135 if(_class && _class.type == unitClass)
5137 ComputeExpression(member.initializer.exp);
5138 exp.constant = member.initializer.exp.constant;
5139 exp.type = constantExp;
5141 member.initializer.exp.constant = null;
5151 if(_class && _class.type == bitClass)
5153 exp.constant = PrintHexUInt(bits);
5154 exp.type = constantExp;
5156 if(exp.type != instanceExp)
5162 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5164 bool result = false;
5168 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5169 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5173 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5174 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5177 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5178 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5179 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5182 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5183 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5184 result = GetOpFloat(op, &op.f);
5187 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5188 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5189 result = GetOpDouble(op, &op.d);
5192 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5193 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5194 result = GetOpUIntPtr(op, &op.ui64);
5197 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5198 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5199 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5202 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5203 result = isSigned ? GetOpIntPtr(op, &op.i64) : GetOpUIntPtr(op, &op.i64);
5206 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5207 result = isSigned ? GetOpIntSize(op, &op.ui64) : GetOpUIntSize(op, &op.ui64);
5213 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5215 if(exp.op.op == SIZEOF)
5217 FreeExpContents(exp);
5218 exp.type = constantExp;
5219 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5230 // Provide default unary +
5231 Expression exp2 = exp.op.exp2;
5233 FreeExpContents(exp);
5234 FreeType(exp.expType);
5235 FreeType(exp.destType);
5241 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5243 // unary arithmetic increment and decrement
5244 //OPERATOR_ALL(UNARY, ++, Inc)
5245 //OPERATOR_ALL(UNARY, --, Dec)
5248 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5250 // unary logical negation
5252 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5258 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5260 if(Promote(op2, op1.kind, op1.type.isSigned))
5261 op2.kind = op1.kind, op2.ops = op1.ops;
5262 else if(Promote(op1, op2.kind, op2.type.isSigned))
5263 op1.kind = op2.kind, op1.ops = op2.ops;
5267 // binary arithmetic
5269 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5272 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5275 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5278 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5281 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5283 // binary arithmetic assignment
5284 //OPERATOR_ALL(BINARY, =, Asign)
5285 //OPERATOR_ALL(BINARY, +=, AddAsign)
5286 //OPERATOR_ALL(BINARY, -=, SubAsign)
5287 //OPERATOR_ALL(BINARY, *=, MulAsign)
5288 //OPERATOR_ALL(BINARY, /=, DivAsign)
5289 //OPERATOR_ALL(BINARY, %=, ModAsign)
5294 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5298 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5301 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5304 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5307 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5309 // binary bitwise assignment
5310 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5311 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5312 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5313 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5314 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5315 // binary logical equality
5317 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5320 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5324 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5327 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5329 // binary logical relational
5331 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5334 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5337 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5340 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5347 void ComputeExpression(Expression exp)
5349 char expString[10240];
5350 expString[0] = '\0';
5352 PrintExpression(exp, expString);
5359 ComputeInstantiation(exp);
5368 Expression exp1, exp2 = null;
5372 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5375 Expression e = exp.op.exp2;
5377 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5379 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5381 if(e.type == extensionCompoundExp)
5382 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5387 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5389 if(e.type == stringExp && e.string)
5391 char * string = e.string;
5392 int len = strlen(string);
5393 char * tmp = new char[len-2+1];
5394 len = UnescapeString(tmp, string + 1, len - 2);
5396 FreeExpContents(exp);
5397 exp.type = constantExp;
5398 exp.constant = PrintUInt(len + 1);
5402 Type type = e.expType;
5404 FreeExpContents(exp);
5405 exp.type = constantExp;
5406 exp.constant = PrintUInt(ComputeTypeSize(type));
5412 ComputeExpression(exp.op.exp2);
5416 ComputeExpression(exp.op.exp1);
5419 op1 = GetOperand(exp1);
5420 if(op1.type) op1.type.refCount++;
5423 op2 = GetOperand(exp2);
5424 if(op2.type) op2.type.refCount++;
5430 op1 = GetOperand(exp1);
5431 if(op1.type) op1.type.refCount++;
5434 CallOperator(exp, exp1, exp2, op1, op2);
5441 if(exp.op.exp1 && exp.op.exp2)
5446 FreeExpContents(exp);
5447 op1.ops.BitAnd(exp, op1, op2);
5456 FreeExpContents(exp);
5457 op1.ops.Mul(exp, op1, op2);
5466 FreeExpContents(exp);
5467 op1.ops.Add(exp, op1, op2);
5472 // Provide default unary +
5473 Expression exp2 = exp.op.exp2;
5475 FreeExpContents(exp);
5476 FreeType(exp.expType);
5477 FreeType(exp.destType);
5488 FreeExpContents(exp);
5489 op1.ops.Sub(exp, op1, op2);
5496 FreeExpContents(exp);
5497 op1.ops.Neg(exp, op1);
5504 FreeExpContents(exp);
5505 op1.ops.BitNot(exp, op1);
5511 FreeExpContents(exp);
5512 op1.ops.Not(exp, op1);
5515 // Binary only operators
5519 FreeExpContents(exp);
5520 op1.ops.Div(exp, op1, op2);
5526 FreeExpContents(exp);
5527 op1.ops.Mod(exp, op1, op2);
5539 FreeExpContents(exp);
5540 op1.ops.Sma(exp, op1, op2);
5549 FreeExpContents(exp);
5550 op1.ops.Grt(exp, op1, op2);
5559 FreeExpContents(exp);
5560 op1.ops.SmaEqu(exp, op1, op2);
5569 FreeExpContents(exp);
5570 op1.ops.GrtEqu(exp, op1, op2);
5579 FreeExpContents(exp);
5580 op1.ops.Equ(exp, op1, op2);
5589 FreeExpContents(exp);
5590 op1.ops.Nqu(exp, op1, op2);
5597 FreeExpContents(exp);
5598 op1.ops.BitOr(exp, op1, op2);
5604 FreeExpContents(exp);
5605 op1.ops.BitXor(exp, op1, op2);
5613 FreeExpContents(exp);
5614 exp.type = constantExp;
5615 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5619 if(op1.type) FreeType(op1.type);
5620 if(op2.type) FreeType(op2.type);
5624 case extensionExpressionExp:
5627 for(e = exp.list->first; e; e = n)
5632 OldList * list = exp.list;
5633 Expression prev = exp.prev;
5634 Expression next = exp.next;
5635 ComputeExpression(e);
5636 //FreeExpContents(exp);
5637 FreeType(exp.expType);
5638 FreeType(exp.destType);
5657 exp.isConstant = true;
5659 ComputeExpression(exp.index.exp);
5660 if(!exp.index.exp.isConstant)
5661 exp.isConstant = false;
5663 for(e = exp.index.index->first; e; e = e.next)
5665 ComputeExpression(e);
5668 // Check if this type is int
5671 exp.isConstant = false;
5673 exp.expType = Dereference(exp.index.exp.expType);
5679 Expression memberExp = exp.member.exp;
5680 Identifier memberID = exp.member.member;
5683 ComputeExpression(exp.member.exp);
5684 type = exp.member.exp.expType;
5687 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);
5688 Property prop = null;
5689 DataMember member = null;
5690 Class convertTo = null;
5691 if(type.kind == subClassType && exp.member.exp.type == classExp)
5692 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5699 PrintTypeNoConst(type, string, false, true);
5700 classSym = FindClass(string);
5701 _class = classSym ? classSym.registered : null;
5704 if(exp.member.member)
5706 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5708 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5710 if(!prop && !member && _class && exp.member.member)
5712 Symbol classSym = FindClass(exp.member.member.string);
5714 _class = classSym ? classSym.registered : null;
5715 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5722 Type type = prop.dataType;
5723 // TODO: Assuming same base type for units...
5724 if(_class.type == unitClass)
5726 if(type.kind == classType)
5728 Class _class = type._class.registered;
5729 if(_class.type == unitClass)
5731 if(!_class.dataType)
5732 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5733 type = _class.dataType;
5741 float (*Get)(float) = (void *)prop.Get;
5742 GetFloat(exp.member.exp, &value);
5743 exp.constant = PrintFloat(Get ? Get(value) : value);
5744 exp.type = constantExp;
5750 double (*Get)(double);
5751 GetDouble(exp.member.exp, &value);
5754 Get = (void *)prop.Set;
5756 Get = (void *)prop.Get;
5757 exp.constant = PrintDouble(Get ? Get(value) : value);
5758 exp.type = constantExp;
5767 Expression value = exp.member.exp;
5770 ProcessPropertyType(prop);
5772 type = prop.dataType;
5775 // printf("Investigate this\n");
5777 else if(_class.type == structClass)
5783 Class propertyClass = type._class.registered;
5784 if(propertyClass.type == structClass && value.type == instanceExp)
5786 void (*Set)(void *, void *) = (void *)prop.Set;
5787 exp.instance = Instantiation { };
5788 exp.instance.data = new0 byte[_class.structSize];
5789 exp.instance._class = MkSpecifierName(_class.fullName);
5790 exp.instance.loc = exp.loc;
5791 exp.type = instanceExp;
5792 Set(exp.instance.data, value.instance.data);
5793 PopulateInstance(exp.instance);
5800 void (*Set)(void *, int) = (void *)prop.Set;
5802 exp.instance = Instantiation { };
5803 exp.instance.data = new0 byte[_class.structSize];
5804 exp.instance._class = MkSpecifierName(_class.fullName);
5805 exp.instance.loc = exp.loc;
5806 exp.type = instanceExp;
5808 GetInt(value, &intValue);
5810 Set(exp.instance.data, intValue);
5811 PopulateInstance(exp.instance);
5817 void (*Set)(void *, int64) = (void *)prop.Set;
5819 exp.instance = Instantiation { };
5820 exp.instance.data = new0 byte[_class.structSize];
5821 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5822 exp.instance.loc = exp.loc;
5823 exp.type = instanceExp;
5825 GetInt64(value, &intValue);
5827 Set(exp.instance.data, intValue);
5828 PopulateInstance(exp.instance);
5835 void (*Set)(void *, intptr) = (void *)prop.Set;
5837 exp.instance = Instantiation { };
5838 exp.instance.data = new0 byte[_class.structSize];
5839 exp.instance._class = MkSpecifierName(_class.fullName);
5840 exp.instance.loc = exp.loc;
5841 exp.type = instanceExp;
5843 GetIntPtr(value, &intValue);
5845 Set(exp.instance.data, intValue);
5846 PopulateInstance(exp.instance);
5853 void (*Set)(void *, intsize) = (void *)prop.Set;
5855 exp.instance = Instantiation { };
5856 exp.instance.data = new0 byte[_class.structSize];
5857 exp.instance._class = MkSpecifierName(_class.fullName);
5858 exp.instance.loc = exp.loc;
5859 exp.type = instanceExp;
5861 GetIntSize(value, &intValue);
5863 Set(exp.instance.data, intValue);
5864 PopulateInstance(exp.instance);
5870 void (*Set)(void *, float) = (void *)prop.Set;
5872 exp.instance = Instantiation { };
5873 exp.instance.data = new0 byte[_class.structSize];
5874 exp.instance._class = MkSpecifierName(_class.fullName);
5875 exp.instance.loc = exp.loc;
5876 exp.type = instanceExp;
5878 GetFloat(value, &floatValue);
5880 Set(exp.instance.data, floatValue);
5881 PopulateInstance(exp.instance);
5887 void (*Set)(void *, double) = (void *)prop.Set;
5889 exp.instance = Instantiation { };
5890 exp.instance.data = new0 byte[_class.structSize];
5891 exp.instance._class = MkSpecifierName(_class.fullName);
5892 exp.instance.loc = exp.loc;
5893 exp.type = instanceExp;
5895 GetDouble(value, &doubleValue);
5897 Set(exp.instance.data, doubleValue);
5898 PopulateInstance(exp.instance);
5903 else if(_class.type == bitClass)
5909 Class propertyClass = type._class.registered;
5910 if(propertyClass.type == structClass && value.instance.data)
5912 unsigned int (*Set)(void *) = (void *)prop.Set;
5913 unsigned int bits = Set(value.instance.data);
5914 exp.constant = PrintHexUInt(bits);
5915 exp.type = constantExp;
5918 else if(_class.type == bitClass)
5921 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5924 GetUInt(exp.member.exp, &value);
5926 exp.constant = PrintHexUInt(bits);
5927 exp.type = constantExp;
5935 if(_class.type == bitClass)
5938 GetUInt(exp.member.exp, &value);
5944 Class _class = type._class.registered;
5945 if(_class.type == structClass)
5947 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5949 exp.instance = Instantiation { };
5950 exp.instance.data = new0 byte[_class.structSize];
5951 exp.instance._class = MkSpecifierName(_class.fullName);
5952 exp.instance.loc = exp.loc;
5953 //exp.instance.fullSet = true;
5954 exp.type = instanceExp;
5955 Get(value, exp.instance.data);
5956 PopulateInstance(exp.instance);
5958 else if(_class.type == bitClass)
5960 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
5961 uint64 bits = Get(value);
5962 exp.constant = PrintHexUInt64(bits);
5963 exp.type = constantExp;
5969 else if(_class.type == structClass)
5971 char * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
5976 Class _class = type._class.registered;
5977 if(_class.type == structClass && value)
5979 void (*Get)(void *, void *) = (void *)prop.Get;
5981 exp.instance = Instantiation { };
5982 exp.instance.data = new0 byte[_class.structSize];
5983 exp.instance._class = MkSpecifierName(_class.fullName);
5984 exp.instance.loc = exp.loc;
5985 //exp.instance.fullSet = true;
5986 exp.type = instanceExp;
5987 Get(value, exp.instance.data);
5988 PopulateInstance(exp.instance);
5996 char * value = exp.member.exp.instance.data;
6001 Class _class = type._class.registered;
6002 if(_class.type == normalClass)
6004 void *(*Get)(void *) = (void *)prop.Get;
6006 exp.instance = Instantiation { };
6007 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6008 exp.type = instanceExp;
6009 exp.instance.data = Get(value, exp.instance.data);
6021 exp.isConstant = false;
6029 if(exp.type != ExpressionType::memberExp)
6031 FreeExpression(memberExp);
6032 FreeIdentifier(memberID);
6038 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6039 FreeExpContents(exp);
6040 exp.constant = PrintUInt(ComputeTypeSize(type));
6041 exp.type = constantExp;
6047 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6048 if(classSym && classSym.registered)
6050 if(classSym.registered.fixed)
6052 FreeSpecifier(exp._class);
6053 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6054 exp.type = constantExp;
6058 char className[1024];
6059 strcpy(className, "__ecereClass_");
6060 FullClassNameCat(className, classSym.string, true);
6061 MangleClassName(className);
6063 DeclareClass(classSym, className);
6065 FreeExpContents(exp);
6066 exp.type = pointerExp;
6067 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6068 exp.member.member = MkIdentifier("structSize");
6078 if(exp.type == castExp)
6081 ComputeExpression(exp.cast.exp);
6084 if(e && exp.expType)
6087 type = exp.destType;
6090 if(type.kind == classType)
6092 Class _class = type._class.registered;
6093 if(_class && (_class.type == unitClass || _class.type == bitClass))
6095 if(!_class.dataType)
6096 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6097 type = _class.dataType;
6108 if(GetChar(e, &value))
6110 FreeExpContents(exp);
6111 exp.constant = PrintChar(value);
6112 exp.type = constantExp;
6117 unsigned char value = 0;
6118 if(GetUChar(e, &value))
6120 FreeExpContents(exp);
6121 exp.constant = PrintUChar(value);
6122 exp.type = constantExp;
6130 if(GetShort(e, &value))
6132 FreeExpContents(exp);
6133 exp.constant = PrintShort(value);
6134 exp.type = constantExp;
6139 unsigned short value = 0;
6140 if(GetUShort(e, &value))
6142 FreeExpContents(exp);
6143 exp.constant = PrintUShort(value);
6144 exp.type = constantExp;
6152 if(GetInt(e, &value))
6154 FreeExpContents(exp);
6155 exp.constant = PrintInt(value);
6156 exp.type = constantExp;
6161 unsigned int value = 0;
6162 if(GetUInt(e, &value))
6164 FreeExpContents(exp);
6165 exp.constant = PrintUInt(value);
6166 exp.type = constantExp;
6174 if(GetInt64(e, &value))
6176 FreeExpContents(exp);
6177 exp.constant = PrintInt64(value);
6178 exp.type = constantExp;
6184 if(GetUInt64(e, &value))
6186 FreeExpContents(exp);
6187 exp.constant = PrintUInt64(value);
6188 exp.type = constantExp;
6196 if(GetIntPtr(e, &value))
6198 FreeExpContents(exp);
6199 exp.constant = PrintInt64((int64)value);
6200 exp.type = constantExp;
6206 if(GetUIntPtr(e, &value))
6208 FreeExpContents(exp);
6209 exp.constant = PrintUInt64((uint64)value);
6210 exp.type = constantExp;
6218 if(GetIntSize(e, &value))
6220 FreeExpContents(exp);
6221 exp.constant = PrintInt64((int64)value);
6222 exp.type = constantExp;
6228 if(GetUIntSize(e, &value))
6230 FreeExpContents(exp);
6231 exp.constant = PrintUInt64((uint64)value);
6232 exp.type = constantExp;
6239 if(GetFloat(e, &value))
6241 FreeExpContents(exp);
6242 exp.constant = PrintFloat(value);
6243 exp.type = constantExp;
6250 if(GetDouble(e, &value))
6252 FreeExpContents(exp);
6253 exp.constant = PrintDouble(value);
6254 exp.type = constantExp;
6269 // Caring only about last expression for now...
6270 ComputeExpression(exp.cond.exp->last);
6271 if(exp.cond.elseExp)
6272 ComputeExpression(exp.cond.elseExp);
6274 ComputeExpression(exp.cond.cond);
6276 op1 = GetOperand(exp.cond.cond);
6277 if(op1.type) op1.type.refCount++;
6278 op2 = GetOperand(exp.cond.exp->last);
6279 if(op2.type) op2.type.refCount++;
6280 op3 = GetOperand(exp.cond.elseExp);
6281 if(op3.type) op3.type.refCount++;
6283 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6284 if(op1.type) FreeType(op1.type);
6285 if(op2.type) FreeType(op2.type);
6286 if(op3.type) FreeType(op3.type);
6292 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla)
6297 OldList converts { };
6300 if(destType.kind == voidType)
6303 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla))
6307 // for(convert = converts.last; convert; convert = convert.prev)
6308 for(convert = converts.first; convert; convert = convert.next)
6310 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6313 Expression newExp { };
6314 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6316 // TODO: Check this...
6320 newExp.destType = null;
6325 exp.type = memberExp;
6326 exp.addedThis = true;
6327 exp.member.exp = newExp;
6328 FreeType(exp.member.exp.expType);
6330 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6331 exp.member.exp.expType.classObjectType = objectType;
6332 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6333 exp.member.memberType = propertyMember;
6334 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6335 // TESTING THIS... for (int)degrees
6336 exp.needCast = true;
6337 if(exp.expType) exp.expType.refCount++;
6338 ApplyAnyObjectLogic(exp.member.exp);
6343 /*if(exp.isConstant)
6345 // Color { ColorRGB = [exp] };
6346 exp.type = instanceExp;
6347 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6348 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6349 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6353 // If not constant, don't turn it yet into an instantiation
6354 // (Go through the deep members system first)
6355 exp.type = memberExp;
6356 exp.addedThis = true;
6357 exp.member.exp = newExp;
6359 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6360 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6361 newExp.expType._class.registered.type == noHeadClass)
6363 newExp.byReference = true;
6366 FreeType(exp.member.exp.expType);
6367 /*exp.member.exp.expType = convert.convert.dataType;
6368 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6369 exp.member.exp.expType = null;
6370 if(convert.convert.dataType)
6372 exp.member.exp.expType = { };
6373 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6374 exp.member.exp.expType.refCount = 1;
6375 exp.member.exp.expType.classObjectType = objectType;
6376 ApplyAnyObjectLogic(exp.member.exp);
6379 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6380 exp.member.memberType = reverseConversionMember;
6381 exp.expType = convert.resultType ? convert.resultType :
6382 MkClassType(convert.convert._class.fullName);
6383 exp.needCast = true;
6384 if(convert.resultType) convert.resultType.refCount++;
6390 FreeType(exp.expType);
6393 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6394 exp.needCast = true;
6395 if(exp.expType) exp.expType.refCount++;
6399 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6400 exp.needCast = true;
6401 if(convert.resultType)
6402 convert.resultType.refCount++;
6406 if(exp.isConstant && inCompiler)
6407 ComputeExpression(exp);
6409 converts.Free(FreeConvert);
6412 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6414 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false);
6416 if(!result && exp.expType && exp.destType)
6418 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6419 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6420 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6421 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6425 // if(result) CheckTemplateTypes(exp);
6429 void CheckTemplateTypes(Expression exp)
6431 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate)
6433 Expression newExp { };
6437 if(exp.destType) exp.destType.refCount++;
6438 if(exp.expType) exp.expType.refCount++;
6442 switch(exp.expType.kind)
6445 if(exp.destType.classObjectType)
6447 // We need to pass the address, just pass it along (Undo what was done above)
6448 if(exp.destType) exp.destType.refCount--;
6449 if(exp.expType) exp.expType.refCount--;
6454 // If we're looking for value:
6455 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6457 OldList * unionDefs = MkList();
6458 OldList * statements = MkList();
6459 context = PushContext();
6460 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6461 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6462 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6463 exp.type = extensionCompoundExp;
6464 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6465 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6466 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6467 exp.compound.compound.context = context;
6468 PopContext(context);
6473 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6474 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6478 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6480 Expression newExp { };
6484 if(exp.destType) exp.destType.refCount++;
6485 if(exp.expType) exp.expType.refCount++;
6489 switch(exp.expType.kind)
6492 if(exp.destType.classObjectType)
6494 // We need to pass the address, just pass it along (Undo what was done above)
6495 if(exp.destType) exp.destType.refCount--;
6496 if(exp.expType) exp.expType.refCount--;
6501 // If we're looking for value:
6502 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6504 OldList * unionDefs = MkList();
6505 OldList * statements = MkList();
6506 context = PushContext();
6507 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6508 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6509 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6510 exp.type = extensionCompoundExp;
6511 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6512 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6513 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6514 exp.compound.compound.context = context;
6515 PopContext(context);
6520 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6522 exp.type = bracketsExp;
6523 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6524 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6525 ProcessExpressionType(exp.list->first);
6530 exp.type = bracketsExp;
6531 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6532 newExp.needCast = true;
6533 ProcessExpressionType(exp.list->first);
6539 if(exp.expType.kind == templateType)
6541 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6544 FreeType(exp.destType);
6545 FreeType(exp.expType);
6550 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6555 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6556 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6560 char typeString[1024];
6562 OldList * specs = MkList();
6563 typeString[0] = '\0';
6564 PrintType(exp.expType, typeString, false, false);
6565 decl = SpecDeclFromString(typeString, specs, null);
6568 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6569 exp.cast.typeName = MkTypeName(specs, decl);
6570 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6571 exp.cast.exp.needCast = true;
6578 // TODO: The Symbol tree should be reorganized by namespaces
6580 // - Tree of all symbols within (stored without namespace)
6581 // - Tree of sub-namespaces
6583 static Symbol ScanWithNameSpace(BinaryTree tree, char * nameSpace, char * name)
6585 int nsLen = strlen(nameSpace);
6587 // Start at the name space prefix
6588 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6590 char * s = symbol.string;
6591 if(!strncmp(s, nameSpace, nsLen))
6593 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6596 for(c = strlen(s)-1; c >= 0; c--)
6601 if(!strcmp(namePart, name))
6603 // TODO: Error on ambiguity
6613 static Symbol FindWithNameSpace(BinaryTree tree, char * name)
6616 char nameSpace[1024];
6618 bool gotColon = false;
6620 nameSpace[0] = '\0';
6621 for(c = strlen(name)-1; c >= 0; c--)
6628 namePart = name+c+1;
6629 while(c >= 0 && name[c] == ':') c--;
6632 // Try an exact match first
6633 Symbol symbol = (Symbol)tree.FindString(name);
6637 // Namespace specified
6638 memcpy(nameSpace, name, c + 1);
6641 return ScanWithNameSpace(tree, nameSpace, namePart);
6645 // Looking for a global symbol, e.g. ::Sleep()
6646 Symbol symbol = (Symbol)tree.FindString(namePart);
6651 // Name only (no namespace specified)
6652 Symbol symbol = (Symbol)tree.FindString(namePart);
6655 return ScanWithNameSpace(tree, "", namePart);
6660 static void ProcessDeclaration(Declaration decl);
6662 /*static */Symbol FindSymbol(char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6665 //Time startTime = GetTime();
6667 // Optimize this later? Do this before/less?
6669 Symbol symbol = null;
6670 // First, check if the identifier is declared inside the function
6671 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6673 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6675 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6681 strcpy(curName, thisNameSpace);
6682 strcat(curName, "::");
6683 strcat(curName, name);
6684 // Try to resolve in current namespace first
6685 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6688 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6691 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6693 if(symbol || ctx == endContext) break;
6695 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6697 if(symbol.pointerExternal.type == functionExternal)
6699 FunctionDefinition function = symbol.pointerExternal.function;
6701 // Modified this recently...
6702 Context tmpContext = curContext;
6704 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6705 curContext = tmpContext;
6707 symbol.pointerExternal.symbol = symbol;
6710 DeclareType(symbol.type, true, true);
6712 ast->Insert(curExternal.prev, symbol.pointerExternal);
6714 symbol.id = curExternal.symbol.idCode;
6717 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6719 ast->Move(symbol.pointerExternal, curExternal.prev);
6720 symbol.id = curExternal.symbol.idCode;
6724 //findSymbolTotalTime += GetTime() - startTime;
6729 static void GetTypeSpecs(Type type, OldList * specs)
6731 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6736 if(type._class.registered)
6738 if(!type._class.registered.dataType)
6739 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6740 GetTypeSpecs(type._class.registered.dataType, specs);
6744 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6745 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6746 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6747 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6748 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6749 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6750 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6751 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6754 ListAdd(specs, MkSpecifier(INT)); break;
6758 static void PrintArraySize(Type arrayType, char * string)
6763 if(arrayType.enumClass)
6764 strcat(size, arrayType.enumClass.string);
6765 else if(arrayType.arraySizeExp)
6766 PrintExpression(arrayType.arraySizeExp, size);
6768 strcat(string, size);
6771 // WARNING : This function expects a null terminated string since it recursively concatenate...
6772 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6776 if(printConst && type.constant)
6777 strcat(string, "const ");
6782 Symbol c = type._class;
6783 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6784 // look into merging with thisclass ?
6785 if(type.classObjectType == typedObject)
6786 strcat(string, "typed_object");
6787 else if(type.classObjectType == anyObject)
6788 strcat(string, "any_object");
6792 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6794 if(type.byReference)
6795 strcat(string, " &");
6798 case voidType: strcat(string, "void"); break;
6799 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6800 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6801 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6802 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6803 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6804 case _BoolType: strcat(string, "_Bool"); break;
6805 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6806 case floatType: strcat(string, "float"); break;
6807 case doubleType: strcat(string, "double"); break;
6811 strcat(string, "struct ");
6812 strcat(string, type.enumName);
6814 else if(type.typeName)
6815 strcat(string, type.typeName);
6819 strcat(string, "struct { ");
6820 for(member = type.members.first; member; member = member.next)
6822 PrintType(member, string, true, fullName);
6823 strcat(string,"; ");
6831 strcat(string, "union ");
6832 strcat(string, type.enumName);
6834 else if(type.typeName)
6835 strcat(string, type.typeName);
6838 strcat(string, "union ");
6839 strcat(string,"(unnamed)");
6845 strcat(string, "enum ");
6846 strcat(string, type.enumName);
6848 else if(type.typeName)
6849 strcat(string, type.typeName);
6851 strcat(string, "int"); // "enum");
6854 strcat(string, "...");
6857 strcat(string, "subclass(");
6858 strcat(string, type._class ? type._class.string : "int");
6859 strcat(string, ")");
6862 strcat(string, type.templateParameter.identifier.string);
6865 strcat(string, "thisclass");
6868 strcat(string, "__builtin_va_list");
6874 static void PrintName(Type type, char * string, bool fullName)
6876 if(type.name && type.name[0])
6879 strcat(string, type.name);
6882 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6883 if(name) name += 2; else name = type.name;
6884 strcat(string, name);
6889 static void PrintAttribs(Type type, char * string)
6893 if(type.dllExport) strcat(string, "dllexport ");
6894 if(type.attrStdcall) strcat(string, "stdcall ");
6898 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
6900 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6902 Type attrType = null;
6903 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
6904 PrintAttribs(type, string);
6905 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
6906 strcat(string, " const");
6907 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
6908 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6909 strcat(string, " (");
6910 if(type.kind == pointerType)
6912 if(type.type.kind == functionType || type.type.kind == methodType)
6913 PrintAttribs(type.type, string);
6915 if(type.kind == pointerType)
6917 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
6918 strcat(string, "*");
6920 strcat(string, " *");
6922 if(printConst && type.constant && type.kind == pointerType)
6923 strcat(string, " const");
6926 PrintTypeSpecs(type, string, fullName, printConst);
6929 static void PostPrintType(Type type, char * string, bool fullName)
6931 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6932 strcat(string, ")");
6933 if(type.kind == arrayType)
6934 PrintArraySize(type, string);
6935 else if(type.kind == functionType)
6938 strcat(string, "(");
6939 for(param = type.params.first; param; param = param.next)
6941 PrintType(param, string, true, fullName);
6942 if(param.next) strcat(string, ", ");
6944 strcat(string, ")");
6946 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6947 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
6951 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
6953 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
6955 PrePrintType(type, string, fullName, null, printConst);
6957 if(type.thisClass || (printName && type.name && type.name[0]))
6958 strcat(string, " ");
6959 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
6961 Symbol _class = type.thisClass;
6962 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
6964 if(type.classObjectType == classPointer)
6965 strcat(string, "class");
6967 strcat(string, type.byReference ? "typed_object&" : "typed_object");
6969 else if(_class && _class.string)
6971 String s = _class.string;
6976 char * name = RSearchString(s, "::", strlen(s), true, false);
6977 if(name) name += 2; else name = s;
6978 strcat(string, name);
6981 strcat(string, "::");
6984 if(printName && type.name)
6985 PrintName(type, string, fullName);
6986 PostPrintType(type, string, fullName);
6987 if(type.bitFieldCount)
6990 sprintf(count, ":%d", type.bitFieldCount);
6991 strcat(string, count);
6995 void PrintType(Type type, char * string, bool printName, bool fullName)
6997 _PrintType(type, string, printName, fullName, true);
7000 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7002 _PrintType(type, string, printName, fullName, false);
7005 static Type FindMember(Type type, char * string)
7008 for(memberType = type.members.first; memberType; memberType = memberType.next)
7010 if(!memberType.name)
7012 Type subType = FindMember(memberType, string);
7016 else if(!strcmp(memberType.name, string))
7022 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7025 for(memberType = type.members.first; memberType; memberType = memberType.next)
7027 if(!memberType.name)
7029 Type subType = FindMember(memberType, string);
7032 *offset += memberType.offset;
7036 else if(!strcmp(memberType.name, string))
7038 *offset += memberType.offset;
7045 public bool GetParseError() { return parseError; }
7047 Expression ParseExpressionString(char * expression)
7051 fileInput = TempFile { };
7052 fileInput.Write(expression, 1, strlen(expression));
7053 fileInput.Seek(0, start);
7056 parsedExpression = null;
7058 expression_yyparse();
7061 return parsedExpression;
7064 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7066 Identifier id = exp.identifier;
7067 Method method = null;
7068 Property prop = null;
7069 DataMember member = null;
7070 ClassProperty classProp = null;
7072 if(_class && _class.type == enumClass)
7074 NamedLink value = null;
7075 Class enumClass = eSystem_FindClass(privateModule, "enum");
7079 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7081 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7082 for(value = e.values.first; value; value = value.next)
7084 if(!strcmp(value.name, id.string))
7091 FreeExpContents(exp);
7093 exp.type = constantExp;
7094 exp.isConstant = true;
7095 if(!strcmp(baseClass.dataTypeString, "int"))
7096 sprintf(constant, "%d",(int)value.data);
7098 sprintf(constant, "0x%X",(int)value.data);
7099 exp.constant = CopyString(constant);
7100 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7101 exp.expType = MkClassType(baseClass.fullName);
7109 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7111 ProcessMethodType(method);
7118 // TOCHECK: Put it back to what it was...
7119 // methodClass = _class;
7120 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7125 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7128 ProcessPropertyType(prop);
7129 exp.expType = prop.dataType;
7130 if(prop.dataType) prop.dataType.refCount++;
7133 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7135 if(!member.dataType)
7136 member.dataType = ProcessTypeString(member.dataTypeString, false);
7137 exp.expType = member.dataType;
7138 if(member.dataType) member.dataType.refCount++;
7141 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7143 if(!classProp.dataType)
7144 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7146 if(classProp.constant)
7148 FreeExpContents(exp);
7150 exp.isConstant = true;
7151 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7153 //char constant[256];
7154 exp.type = stringExp;
7155 exp.constant = QMkString((char *)classProp.Get(_class));
7160 exp.type = constantExp;
7161 sprintf(constant, "%d", (int)classProp.Get(_class));
7162 exp.constant = CopyString(constant);
7170 exp.expType = classProp.dataType;
7171 if(classProp.dataType) classProp.dataType.refCount++;
7177 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7179 BinaryTree * tree = &nameSpace.functions;
7180 GlobalData data = (GlobalData)tree->FindString(name);
7184 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7186 data = ScanGlobalData(child, name);
7194 static GlobalData FindGlobalData(char * name)
7197 NameSpace * nameSpace;
7198 nameSpace = globalData;
7199 for(c = 0; name[c]; c++)
7201 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7203 NameSpace * newSpace;
7204 char * spaceName = new char[c - start + 1];
7205 strncpy(spaceName, name + start, c - start);
7206 spaceName[c-start] = '\0';
7207 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7211 nameSpace = newSpace;
7212 if(name[c] == ':') c++;
7218 return ScanGlobalData(nameSpace, name + start);
7223 static int definedExpStackPos;
7224 static void * definedExpStack[512];
7226 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7227 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7229 Expression prev = checkedExp.prev, next = checkedExp.next;
7231 FreeExpContents(checkedExp);
7232 FreeType(checkedExp.expType);
7233 FreeType(checkedExp.destType);
7235 *checkedExp = *newExp;
7239 checkedExp.prev = prev;
7240 checkedExp.next = next;
7243 void ApplyAnyObjectLogic(Expression e)
7245 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7247 char debugExpString[4096];
7248 debugExpString[0] = '\0';
7249 PrintExpression(e, debugExpString);
7252 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7254 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7255 //ellipsisDestType = destType;
7258 Type type = e.expType;
7259 Class _class = null;
7260 //Type destType = e.destType;
7262 if(type.kind == classType && type._class && type._class.registered)
7264 _class = type._class.registered;
7266 else if(type.kind == subClassType)
7268 _class = FindClass("ecere::com::Class").registered;
7272 char string[1024] = "";
7275 PrintTypeNoConst(type, string, false, true);
7276 classSym = FindClass(string);
7277 if(classSym) _class = classSym.registered;
7280 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...
7281 (!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))) ||
7282 destType.byReference)))
7284 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7286 Expression checkedExp = e, newExp;
7288 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7290 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7292 if(checkedExp.type == extensionCompoundExp)
7294 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7297 checkedExp = checkedExp.list->last;
7299 else if(checkedExp.type == castExp)
7300 checkedExp = checkedExp.cast.exp;
7303 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7305 newExp = checkedExp.op.exp2;
7306 checkedExp.op.exp2 = null;
7307 FreeExpContents(checkedExp);
7309 if(e.expType && e.expType.passAsTemplate)
7312 ComputeTypeSize(e.expType);
7313 sprintf(size, "%d", e.expType.size);
7314 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7315 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7316 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7319 ReplaceExpContents(checkedExp, newExp);
7320 e.byReference = true;
7322 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7324 Expression checkedExp, newExp;
7327 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7329 e.type == identifierExp ||
7330 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7331 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7332 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7335 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7337 Context context = PushContext();
7339 OldList * specs = MkList();
7340 char typeString[1024];
7341 Expression newExp { };
7343 typeString[0] = '\0';
7346 //if(e.destType) e.destType.refCount++;
7347 // if(exp.expType) exp.expType.refCount++;
7350 newExp.expType = null;
7352 PrintTypeNoConst(e.expType, typeString, false, true);
7353 decl = SpecDeclFromString(typeString, specs, null);
7354 newExp.destType = ProcessType(specs, decl);
7356 curContext = context;
7358 // We need a current compound for this
7362 OldList * stmts = MkList();
7363 e.type = extensionCompoundExp;
7364 sprintf(name, "__internalValue%03X", internalValueCounter++);
7365 if(!curCompound.compound.declarations)
7366 curCompound.compound.declarations = MkList();
7367 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7368 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7369 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7370 e.compound = MkCompoundStmt(null, stmts);
7373 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7376 e.compound = MkCompoundStmt(
7377 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7378 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7380 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7384 Type type = e.destType;
7386 CopyTypeInto(e.destType, type);
7387 e.destType.refCount = 1;
7388 e.destType.classObjectType = none;
7392 e.compound.compound.context = context;
7393 PopContext(context);
7394 curContext = context.parent;
7398 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7400 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7402 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7404 if(checkedExp.type == extensionCompoundExp)
7406 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7409 checkedExp = checkedExp.list->last;
7411 else if(checkedExp.type == castExp)
7412 checkedExp = checkedExp.cast.exp;
7415 Expression operand { };
7416 operand = *checkedExp;
7417 checkedExp.destType = null;
7418 checkedExp.expType = null;
7420 checkedExp.type = opExp;
7421 checkedExp.op.op = '&';
7422 checkedExp.op.exp1 = null;
7423 checkedExp.op.exp2 = operand;
7425 //newExp = MkExpOp(null, '&', checkedExp);
7427 //ReplaceExpContents(checkedExp, newExp);
7434 // If expression type is a simple class, make it an address
7435 // FixReference(e, true);
7438 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7439 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7440 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7442 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"))
7444 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7448 Expression thisExp { };
7451 thisExp.prev = null;
7452 thisExp.next = null;
7455 e.type = bracketsExp;
7456 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7457 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7458 ((Expression)e.list->first).byReference = true;
7460 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7462 e.expType = thisExp.expType;
7463 e.expType.refCount++;
7468 CopyTypeInto(e.expType, thisExp.expType);
7469 e.expType.byReference = false;
7470 e.expType.refCount = 1;
7472 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7473 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7475 e.expType.classObjectType = none;
7480 // TOFIX: Try this for a nice IDE crash!
7482 // The other way around
7485 if(destType && e.expType &&
7486 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7487 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7488 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7490 if(destType.kind == ellipsisType)
7492 Compiler_Error($"Unspecified type\n");
7494 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7496 bool byReference = e.expType.byReference;
7497 Expression thisExp { };
7499 OldList * specs = MkList();
7500 char typeString[1024]; // Watch buffer overruns
7502 ClassObjectType backupClassObjectType;
7503 bool backupByReference;
7505 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7510 backupClassObjectType = type.classObjectType;
7511 backupByReference = type.byReference;
7513 type.classObjectType = none;
7514 type.byReference = false;
7516 typeString[0] = '\0';
7517 PrintType(type, typeString, false, true);
7518 decl = SpecDeclFromString(typeString, specs, null);
7520 type.classObjectType = backupClassObjectType;
7521 type.byReference = backupByReference;
7524 thisExp.prev = null;
7525 thisExp.next = null;
7528 if( ( type.kind == classType && type._class && type._class.registered &&
7529 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7530 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7531 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7532 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7537 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7540 CopyTypeInto(e.expType, type);
7541 e.expType.byReference = false;
7542 e.expType.refCount = 1;
7547 e.cast.typeName = MkTypeName(specs, decl);
7548 e.cast.exp = thisExp;
7549 e.byReference = true;
7553 e.destType = destType;
7554 destType.refCount++;
7559 void ProcessExpressionType(Expression exp)
7561 bool unresolved = false;
7562 Location oldyylloc = yylloc;
7563 bool notByReference = false;
7565 char debugExpString[4096];
7566 debugExpString[0] = '\0';
7567 PrintExpression(exp, debugExpString);
7569 if(!exp || exp.expType)
7572 //eSystem_Logf("%s\n", expString);
7574 // Testing this here
7580 Identifier id = exp.identifier;
7581 if(!id || !topContext) return;
7583 // DOING THIS LATER NOW...
7584 if(id._class && id._class.name)
7586 id.classSym = id._class.symbol; // FindClass(id._class.name);
7587 /* TODO: Name Space Fix ups
7589 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7593 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7595 exp.expType = ProcessTypeString("Module", true);
7598 else */if(strstr(id.string, "__ecereClass") == id.string)
7600 exp.expType = ProcessTypeString("ecere::com::Class", true);
7603 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7605 // Added this here as well
7606 ReplaceClassMembers(exp, thisClass);
7607 if(exp.type != identifierExp)
7609 ProcessExpressionType(exp);
7613 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7618 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7619 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7620 if(!symbol/* && exp.destType*/)
7622 if(exp.destType && CheckExpressionType(exp, exp.destType, false))
7628 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7629 if(exp.type != identifierExp)
7631 ProcessExpressionType(exp);
7635 // Static methods called from inside the _class
7636 else if(currentClass && !id._class)
7638 if(ResolveIdWithClass(exp, currentClass, true))
7641 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7645 // If we manage to resolve this symbol
7648 Type type = symbol.type;
7649 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7651 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7653 Context context = SetupTemplatesContext(_class);
7654 type = ReplaceThisClassType(_class);
7655 FinishTemplatesContext(context);
7656 if(type) type.refCount = 0; // We'll be incrementing it right below...
7659 FreeSpecifier(id._class);
7662 id.string = CopyString(symbol.string);
7669 // Commented this out, it was making non-constant enum parameters seen as constant
7670 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7671 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7672 // Add missing cases here... enum Classes...
7673 exp.isConstant = true;
7675 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7676 if(symbol.isParam || !strcmp(id.string, "this"))
7678 if(_class && _class.type == structClass && !type.declaredWithStruct)
7679 exp.byReference = true;
7681 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7682 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7683 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7684 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7686 Identifier id = exp.identifier;
7687 exp.type = bracketsExp;
7688 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7692 if(symbol.isIterator)
7694 if(symbol.isIterator == 3)
7696 exp.type = bracketsExp;
7697 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7698 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7700 ProcessExpressionType(exp);
7702 else if(symbol.isIterator != 4)
7704 exp.type = memberExp;
7705 exp.member.exp = MkExpIdentifier(exp.identifier);
7706 exp.member.exp.expType = exp.expType;
7707 /*if(symbol.isIterator == 6)
7708 exp.member.member = MkIdentifier("key");
7710 exp.member.member = MkIdentifier("data");
7712 ProcessExpressionType(exp);
7719 DefinedExpression definedExp = null;
7720 if(thisNameSpace && !(id._class && !id._class.name))
7723 strcpy(name, thisNameSpace);
7725 strcat(name, id.string);
7726 definedExp = eSystem_FindDefine(privateModule, name);
7729 definedExp = eSystem_FindDefine(privateModule, id.string);
7733 for(c = 0; c<definedExpStackPos; c++)
7734 if(definedExpStack[c] == definedExp)
7736 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7738 Location backupYylloc = yylloc;
7739 File backInput = fileInput;
7740 definedExpStack[definedExpStackPos++] = definedExp;
7742 fileInput = TempFile { };
7743 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7744 fileInput.Seek(0, start);
7747 parsedExpression = null;
7749 expression_yyparse();
7752 fileInput = backInput;
7754 yylloc = backupYylloc;
7756 if(parsedExpression)
7759 exp.type = bracketsExp;
7760 exp.list = MkListOne(parsedExpression);
7761 parsedExpression.loc = yylloc;
7762 ProcessExpressionType(exp);
7763 definedExpStackPos--;
7766 definedExpStackPos--;
7772 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7778 GlobalData data = null;
7779 if(thisNameSpace && !(id._class && !id._class.name))
7782 strcpy(name, thisNameSpace);
7784 strcat(name, id.string);
7785 data = FindGlobalData(name);
7788 data = FindGlobalData(id.string);
7791 DeclareGlobalData(data);
7792 exp.expType = data.dataType;
7793 if(data.dataType) data.dataType.refCount++;
7796 id.string = CopyString(data.fullName);
7797 FreeSpecifier(id._class);
7804 GlobalFunction function = null;
7805 if(thisNameSpace && !(id._class && !id._class.name))
7808 strcpy(name, thisNameSpace);
7810 strcat(name, id.string);
7811 function = eSystem_FindFunction(privateModule, name);
7814 function = eSystem_FindFunction(privateModule, id.string);
7819 id.string = CopyString(function.name);
7822 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7823 strcpy(name, "__ecereFunction_");
7824 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7825 if(DeclareFunction(function, name))
7828 id.string = CopyString(name);
7830 exp.expType = function.dataType;
7831 if(function.dataType) function.dataType.refCount++;
7833 FreeSpecifier(id._class);
7850 if(!exp.instance._class)
7852 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
7854 exp.instance._class = MkSpecifierName(exp.destType._class.string);
7858 //classSym = FindClass(exp.instance._class.fullName);
7859 //_class = classSym ? classSym.registered : null;
7861 ProcessInstantiationType(exp.instance);
7862 exp.isConstant = exp.instance.isConstant;
7865 if(_class.type == unitClass && _class.base.type != systemClass)
7868 Type destType = exp.destType;
7870 exp.destType = MkClassType(_class.base.fullName);
7871 exp.expType = MkClassType(_class.fullName);
7872 CheckExpressionType(exp, exp.destType, true);
7874 exp.destType = destType;
7876 exp.expType = MkClassType(_class.fullName);
7879 if(exp.instance._class)
7881 exp.expType = MkClassType(exp.instance._class.name);
7882 /*if(exp.expType._class && exp.expType._class.registered &&
7883 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
7884 exp.expType.byReference = true;*/
7892 char * constant = exp.constant;
7900 if(constant[0] == '\'')
7902 if((int)((byte *)constant)[1] > 127)
7905 unichar ch = UTF8GetChar(constant + 1, &nb);
7906 if(nb < 2) ch = constant[1];
7908 exp.constant = PrintUInt(ch);
7909 // type.kind = (ch > 0xFFFF) ? intType : shortType;
7910 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
7911 type._class = FindClass("unichar");
7913 type.isSigned = false;
7917 type.kind = charType;
7918 type.isSigned = true;
7923 char * dot = strchr(constant, '.');
7924 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
7928 exponent = strchr(constant, 'p');
7929 if(!exponent) exponent = strchr(constant, 'P');
7933 exponent = strchr(constant, 'e');
7934 if(!exponent) exponent = strchr(constant, 'E');
7939 if(strchr(constant, 'f') || strchr(constant, 'F'))
7940 type.kind = floatType;
7942 type.kind = doubleType;
7943 type.isSigned = true;
7947 bool isSigned = constant[0] == '-';
7949 int64 i64 = strtoll(constant, &endP, 0);
7950 uint64 ui64 = strtoull(constant, &endP, 0);
7951 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
7964 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
7968 else if(constant[0] != '0' || !constant[1])
7971 type.kind = is64Bit ? int64Type : intType;
7972 type.isSigned = isSigned;
7975 exp.isConstant = true;
7976 if(exp.destType && exp.destType.kind == doubleType)
7977 type.kind = doubleType;
7978 else if(exp.destType && exp.destType.kind == floatType)
7979 type.kind = floatType;
7980 else if(exp.destType && exp.destType.kind == int64Type)
7981 type.kind = int64Type;
7987 exp.isConstant = true; // Why wasn't this constant?
8004 ProcessExpressionType(exp._new.size);
8009 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8011 DeclareType(exp.expType.type, false, false);
8015 ProcessExpressionType(exp._renew.size);
8016 ProcessExpressionType(exp._renew.exp);
8021 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8023 DeclareType(exp.expType.type, false, false);
8027 bool assign = false, boolResult = false, boolOps = false;
8028 Type type1 = null, type2 = null;
8029 bool useDestType = false, useSideType = false;
8030 Location oldyylloc = yylloc;
8031 bool useSideUnit = false;
8032 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8034 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8043 // Assignment Operators
8057 // boolean Operators
8059 // Expect boolean operators
8061 //boolResult = true;
8065 // Expect boolean operands
8076 // Gives boolean result
8108 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8114 /*// Implement speed etc.
8120 if(exp.op.op == '&')
8122 // Added this here earlier for Iterator address as key
8123 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8125 Identifier id = exp.op.exp2.identifier;
8126 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8127 if(symbol && symbol.isIterator == 2)
8129 exp.type = memberExp;
8130 exp.member.exp = exp.op.exp2;
8131 exp.member.member = MkIdentifier("key");
8133 exp.op.exp2.expType = symbol.type;
8134 symbol.type.refCount++;
8135 ProcessExpressionType(exp);
8139 // exp.op.exp2.usage.usageRef = true;
8143 //dummy.kind = TypeDummy;
8146 // Added this check here to use the dest type only for units derived from the base unit
8147 // So that untyped units will use the side unit as opposed to the untyped destination unit
8148 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8149 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8150 useDestType = false;
8152 if(destClass && useDestType &&
8153 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8155 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8157 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8158 exp.op.exp1.destType = exp.destType;
8159 exp.op.exp1.opDestType = true;
8161 exp.destType.refCount++;
8165 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8166 exp.op.exp1.destType = dummy;
8170 // TESTING THIS HERE...
8171 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8172 ProcessExpressionType(exp.op.exp1);
8173 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8175 exp.op.exp1.opDestType = false;
8177 // Fix for unit and ++ / --
8178 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8179 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8181 exp.op.exp2 = MkExpConstant("1");
8182 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8186 if(exp.op.exp1.destType == dummy)
8189 exp.op.exp1.destType = null;
8191 type1 = exp.op.exp1.expType;
8196 char expString[10240];
8197 expString[0] = '\0';
8198 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8202 exp.op.exp2.destType = exp.op.exp1.expType;
8203 if(exp.op.exp1.expType)
8204 exp.op.exp1.expType.refCount++;
8208 exp.op.exp2.destType = exp.destType;
8209 if(!exp.op.exp1 || exp.op.op != '&')
8210 exp.op.exp2.opDestType = true;
8212 exp.destType.refCount++;
8215 if(type1) type1.refCount++;
8216 exp.expType = type1;
8221 PrintExpression(exp.op.exp2, expString);
8223 if(type1 && type1.kind == pointerType)
8225 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 ||
8226 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8227 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8228 else if(exp.op.op == '=')
8230 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8231 exp.op.exp2.destType = type1;
8238 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8239 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/* ||
8240 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8243 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8244 exp.op.exp2.destType = type1;
8249 if(type1) type1.refCount++;
8250 exp.expType = type1;
8252 else if(destClass &&
8253 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8254 (destClass.type == enumClass && useDestType)))
8256 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8257 exp.op.exp2.destType = exp.destType;
8258 if(exp.op.op != '&')
8259 exp.op.exp2.opDestType = true;
8261 exp.destType.refCount++;
8265 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8266 exp.op.exp2.destType = dummy;
8270 // TESTING THIS HERE... (DANGEROUS)
8271 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8272 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8274 FreeType(exp.op.exp2.destType);
8275 exp.op.exp2.destType = type1;
8278 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8279 // Cannot lose the cast on a sizeof
8280 if(exp.op.op == SIZEOF)
8282 Expression e = exp.op.exp2;
8283 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8285 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8287 if(e.type == extensionCompoundExp)
8288 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8293 if(e.type == castExp && e.cast.exp)
8294 e.cast.exp.needCast = true;
8296 ProcessExpressionType(exp.op.exp2);
8297 exp.op.exp2.opDestType = false;
8298 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8300 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8302 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)
8304 if(exp.op.op != '=' && type1.type.kind == voidType)
8305 Compiler_Error($"void *: unknown size\n");
8307 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||
8308 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8309 (exp.op.exp2.expType._class.registered.type == normalClass ||
8310 exp.op.exp2.expType._class.registered.type == structClass ||
8311 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8313 if(exp.op.op == ADD_ASSIGN)
8314 Compiler_Error($"cannot add two pointers\n");
8316 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8317 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8319 if(exp.op.op == ADD_ASSIGN)
8320 Compiler_Error($"cannot add two pointers\n");
8324 char type1String[1024];
8325 char type2String[1024];
8326 type1String[0] = '\0';
8327 type2String[0] = '\0';
8329 PrintType(exp.op.exp2.expType, type1String, false, true);
8330 PrintType(type1, type2String, false, true);
8331 ChangeCh(expString, '\n', ' ');
8332 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8336 if(exp.op.exp2.destType == dummy)
8339 exp.op.exp2.destType = null;
8342 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8346 CopyTypeInto(type2, exp.op.exp2.expType);
8347 type2.isSigned = true;
8349 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8351 type2 = { kind = intType };
8353 type2.isSigned = true;
8357 type2 = exp.op.exp2.expType;
8358 if(type2) type2.refCount++;
8362 dummy.kind = voidType;
8364 if(exp.op.op == SIZEOF)
8371 exp.isConstant = true;
8373 // Get type of dereferenced pointer
8374 else if(exp.op.op == '*' && !exp.op.exp1)
8376 exp.expType = Dereference(type2);
8377 if(type2 && type2.kind == classType)
8378 notByReference = true;
8380 else if(exp.op.op == '&' && !exp.op.exp1)
8381 exp.expType = Reference(type2);
8388 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8389 exp.op.exp1.destType = MkClassType("bool");
8390 exp.op.exp1.destType.truth = true;
8391 if(!exp.op.exp1.expType)
8392 ProcessExpressionType(exp.op.exp1);
8394 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8395 FreeType(exp.op.exp1.expType);
8396 exp.op.exp1.expType = MkClassType("bool");
8397 exp.op.exp1.expType.truth = true;
8401 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8402 exp.op.exp2.destType = MkClassType("bool");
8403 exp.op.exp2.destType.truth = true;
8404 if(!exp.op.exp2.expType)
8405 ProcessExpressionType(exp.op.exp2);
8407 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8408 FreeType(exp.op.exp2.expType);
8409 exp.op.exp2.expType = MkClassType("bool");
8410 exp.op.exp2.expType.truth = true;
8413 else if(exp.op.exp1 && exp.op.exp2 &&
8416 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8417 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8418 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8419 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8421 if(type1 && type2 &&
8422 // If either both are class or both are not class
8423 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8425 // Added this check for enum subtraction to result in an int type:
8426 if(exp.op.op == '-' &&
8427 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8428 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8431 if(!type1._class.registered.dataType)
8432 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8433 if(!type2._class.registered.dataType)
8434 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8436 intType = ProcessTypeString(
8437 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8439 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8440 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8441 exp.op.exp1.destType = intType;
8442 exp.op.exp2.destType = intType;
8447 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8448 exp.op.exp2.destType = type1;
8450 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8451 exp.op.exp1.destType = type2;
8455 // Warning here for adding Radians + Degrees with no destination type
8456 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8457 type1._class.registered && type1._class.registered.type == unitClass &&
8458 type2._class.registered && type2._class.registered.type == unitClass &&
8459 type1._class.registered != type2._class.registered)
8460 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8461 type1._class.string, type2._class.string, type1._class.string);
8463 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8465 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8468 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8470 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8471 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8474 ProcessExpressionType(exp.op.exp1);
8476 if(type2.kind != pointerType)
8478 ProcessExpressionType(classExp);
8480 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*',
8481 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8482 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8484 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("5")),
8487 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpConstant("0"))))),
8488 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8489 MkPointer(null, null), null)))),
8490 MkExpMember(classExp, MkIdentifier("typeSize"))))))));
8492 if(!exp.op.exp2.expType)
8496 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8500 ProcessExpressionType(exp.op.exp2);
8505 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)))
8507 if(type1.kind != classType && type1.type.kind == voidType)
8508 Compiler_Error($"void *: unknown size\n");
8509 exp.expType = type1;
8510 if(type1) type1.refCount++;
8512 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)))
8514 if(type2.kind != classType && type2.type.kind == voidType)
8515 Compiler_Error($"void *: unknown size\n");
8516 exp.expType = type2;
8517 if(type2) type2.refCount++;
8519 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8520 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8522 Compiler_Warning($"different levels of indirection\n");
8526 bool success = false;
8527 if(type1.kind == pointerType && type2.kind == pointerType)
8529 if(exp.op.op == '+')
8530 Compiler_Error($"cannot add two pointers\n");
8531 else if(exp.op.op == '-')
8533 // Pointer Subtraction gives integer
8534 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false))
8543 if(type1.type.kind == templateType)
8545 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8548 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8550 ProcessExpressionType(classExp);
8552 exp.type = bracketsExp;
8553 exp.list = MkListOne(MkExpOp(
8554 MkExpBrackets(MkListOne(MkExpOp(
8555 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8557 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8559 //MkExpMember(classExp, MkIdentifier("typeSize"))
8561 // ((_class.type == noHeadClass || _class.type == normalClass) ? sizeof(void *) : type.size)
8562 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(MkExpOp(
8564 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("noHeadClass"))),
8567 MkExpOp(MkExpMember(CopyExpression(classExp), MkIdentifier("type")), EQ_OP, MkExpIdentifier(MkIdentifier("normalClass")))))),
8568 MkListOne(MkExpTypeSize(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(
8569 MkPointer(null, null), null)))),
8570 MkExpMember(classExp, MkIdentifier("typeSize")))))
8575 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8584 if(!success && exp.op.exp1.type == constantExp)
8586 // If first expression is constant, try to match that first
8587 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8589 if(exp.expType) FreeType(exp.expType);
8590 exp.expType = exp.op.exp1.destType;
8591 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8594 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8596 if(exp.expType) FreeType(exp.expType);
8597 exp.expType = exp.op.exp2.destType;
8598 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8604 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8606 if(exp.expType) FreeType(exp.expType);
8607 exp.expType = exp.op.exp2.destType;
8608 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8611 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8613 if(exp.expType) FreeType(exp.expType);
8614 exp.expType = exp.op.exp1.destType;
8615 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8621 char expString1[10240];
8622 char expString2[10240];
8625 expString1[0] = '\0';
8626 expString2[0] = '\0';
8631 PrintExpression(exp.op.exp1, expString1);
8632 ChangeCh(expString1, '\n', ' ');
8633 PrintExpression(exp.op.exp2, expString2);
8634 ChangeCh(expString2, '\n', ' ');
8635 PrintType(exp.op.exp1.expType, type1, false, true);
8636 PrintType(exp.op.exp2.expType, type2, false, true);
8639 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8643 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8644 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8646 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8647 // Convert e.g. / 4 into / 4.0
8648 exp.op.exp1.destType = type2._class.registered.dataType;
8649 if(type2._class.registered.dataType)
8650 type2._class.registered.dataType.refCount++;
8651 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8652 exp.expType = type2;
8653 if(type2) type2.refCount++;
8655 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8657 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8658 // Convert e.g. / 4 into / 4.0
8659 exp.op.exp2.destType = type1._class.registered.dataType;
8660 if(type1._class.registered.dataType)
8661 type1._class.registered.dataType.refCount++;
8662 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8663 exp.expType = type1;
8664 if(type1) type1.refCount++;
8670 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8672 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8674 if(!type1._class.registered.dataType)
8675 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8676 exp.op.exp2.destType = type1._class.registered.dataType;
8677 exp.op.exp2.destType.refCount++;
8679 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8682 type2 = exp.op.exp2.destType;
8683 if(type2) type2.refCount++;
8685 exp.expType = type2;
8689 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8691 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8693 if(!type2._class.registered.dataType)
8694 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8695 exp.op.exp1.destType = type2._class.registered.dataType;
8696 exp.op.exp1.destType.refCount++;
8698 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8699 type1 = exp.op.exp1.destType;
8700 exp.expType = type1;
8704 // TESTING THIS NEW CODE
8705 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8707 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8708 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8709 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8711 // Convert the enum to an int instead for these operators
8712 if(op1IsEnum && exp.op.exp2.expType)
8714 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8716 if(exp.expType) FreeType(exp.expType);
8717 exp.expType = exp.op.exp2.expType;
8718 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8722 else if(op2IsEnum && exp.op.exp1.expType)
8724 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8726 if(exp.expType) FreeType(exp.expType);
8727 exp.expType = exp.op.exp1.expType;
8728 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8735 if(op1IsEnum && exp.op.exp2.expType)
8737 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false))
8739 if(exp.expType) FreeType(exp.expType);
8740 exp.expType = exp.op.exp1.expType;
8741 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8745 else if(op2IsEnum && exp.op.exp1.expType)
8747 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false))
8749 if(exp.expType) FreeType(exp.expType);
8750 exp.expType = exp.op.exp2.expType;
8751 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8760 // 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
8761 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8762 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8764 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8765 exp.op.exp1.destType = type2;
8768 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8770 if(exp.expType) FreeType(exp.expType);
8771 exp.expType = exp.op.exp1.destType;
8772 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8777 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8778 exp.op.exp2.destType = type1;
8782 // Maybe this was meant to be an enum...
8783 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8785 Type oldType = exp.op.exp2.expType;
8786 exp.op.exp2.expType = null;
8787 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8790 exp.op.exp2.expType = oldType;
8795 // TESTING THIS HERE... LATEST ADDITION
8796 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8798 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8799 exp.op.exp2.destType = type2._class.registered.dataType;
8800 if(type2._class.registered.dataType)
8801 type2._class.registered.dataType.refCount++;
8802 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8804 //exp.expType = type2._class.registered.dataType; //type2;
8805 //if(type2) type2.refCount++;
8808 // TESTING THIS HERE... LATEST ADDITION
8809 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8811 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8812 exp.op.exp1.destType = type1._class.registered.dataType;
8813 if(type1._class.registered.dataType)
8814 type1._class.registered.dataType.refCount++;
8815 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8816 exp.expType = type1._class.registered.dataType; //type1;
8817 if(type1) type1.refCount++;
8821 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8823 if(exp.expType) FreeType(exp.expType);
8824 exp.expType = exp.op.exp2.destType;
8825 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8827 else if(type1 && type2)
8829 char expString1[10240];
8830 char expString2[10240];
8831 char type1String[1024];
8832 char type2String[1024];
8833 expString1[0] = '\0';
8834 expString2[0] = '\0';
8835 type1String[0] = '\0';
8836 type2String[0] = '\0';
8839 PrintExpression(exp.op.exp1, expString1);
8840 ChangeCh(expString1, '\n', ' ');
8841 PrintExpression(exp.op.exp2, expString2);
8842 ChangeCh(expString2, '\n', ' ');
8843 PrintType(exp.op.exp1.expType, type1String, false, true);
8844 PrintType(exp.op.exp2.expType, type2String, false, true);
8847 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8849 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8851 exp.expType = exp.op.exp1.expType;
8852 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8854 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8856 exp.expType = exp.op.exp2.expType;
8857 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8865 // Maybe this was meant to be an enum...
8866 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8868 Type oldType = exp.op.exp1.expType;
8869 exp.op.exp1.expType = null;
8870 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8873 exp.op.exp1.expType = oldType;
8876 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8877 exp.op.exp1.destType = type2;
8880 // TESTING THIS HERE... LATEST ADDITION
8881 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8883 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8884 exp.op.exp1.destType = type1._class.registered.dataType;
8885 if(type1._class.registered.dataType)
8886 type1._class.registered.dataType.refCount++;
8889 // TESTING THIS HERE... LATEST ADDITION
8890 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8892 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8893 exp.op.exp2.destType = type2._class.registered.dataType;
8894 if(type2._class.registered.dataType)
8895 type2._class.registered.dataType.refCount++;
8899 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false))
8901 if(exp.expType) FreeType(exp.expType);
8902 exp.expType = exp.op.exp1.destType;
8903 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8907 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
8909 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8911 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8912 // Convert e.g. / 4 into / 4.0
8913 exp.op.exp1.destType = type2._class.registered.dataType;
8914 if(type2._class.registered.dataType)
8915 type2._class.registered.dataType.refCount++;
8916 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8918 if(exp.op.op == '!')
8920 exp.expType = MkClassType("bool");
8921 exp.expType.truth = true;
8925 exp.expType = type2;
8926 if(type2) type2.refCount++;
8929 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
8931 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8933 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8934 // Convert e.g. / 4 into / 4.0
8935 exp.op.exp2.destType = type1._class.registered.dataType;
8936 if(type1._class.registered.dataType)
8937 type1._class.registered.dataType.refCount++;
8938 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8940 exp.expType = type1;
8941 if(type1) type1.refCount++;
8946 if(exp.op.exp1 && !exp.op.exp1.expType)
8948 char expString[10000];
8949 expString[0] = '\0';
8952 PrintExpression(exp.op.exp1, expString);
8953 ChangeCh(expString, '\n', ' ');
8956 Compiler_Error($"couldn't determine type of %s\n", expString);
8958 if(exp.op.exp2 && !exp.op.exp2.expType)
8960 char expString[10240];
8961 expString[0] = '\0';
8964 PrintExpression(exp.op.exp2, expString);
8965 ChangeCh(expString, '\n', ' ');
8968 Compiler_Error($"couldn't determine type of %s\n", expString);
8973 FreeType(exp.expType);
8974 exp.expType = MkClassType("bool");
8975 exp.expType.truth = true;
8978 if(exp.op.op != SIZEOF)
8979 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
8980 (!exp.op.exp2 || exp.op.exp2.isConstant);
8982 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
8984 DeclareType(exp.op.exp2.expType, false, false);
8995 case extensionExpressionExp:
8998 exp.isConstant = true;
8999 for(e = exp.list->first; e; e = e.next)
9004 FreeType(e.destType);
9005 e.opDestType = exp.opDestType;
9006 e.destType = exp.destType;
9007 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
9009 ProcessExpressionType(e);
9011 exp.destType.count--;
9012 if(!exp.expType && !e.next)
9014 exp.expType = e.expType;
9015 if(e.expType) e.expType.refCount++;
9018 exp.isConstant = false;
9021 // In case a cast became a member...
9022 e = exp.list->first;
9023 if(!e.next && e.type == memberExp)
9025 // Preserve prev, next
9026 Expression next = exp.next, prev = exp.prev;
9029 FreeType(exp.expType);
9030 FreeType(exp.destType);
9040 ProcessExpressionType(exp);
9047 exp.isConstant = true;
9049 ProcessExpressionType(exp.index.exp);
9050 if(!exp.index.exp.isConstant)
9051 exp.isConstant = false;
9053 if(exp.index.exp.expType)
9055 Type source = exp.index.exp.expType;
9056 if(source.kind == classType && source._class && source._class.registered)
9058 Class _class = source._class.registered;
9059 Class c = _class.templateClass ? _class.templateClass : _class;
9060 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9062 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9064 if(exp.index.index && exp.index.index->last)
9066 ((Expression)exp.index.index->last).destType = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9072 for(e = exp.index.index->first; e; e = e.next)
9074 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9076 if(e.destType) FreeType(e.destType);
9077 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9079 ProcessExpressionType(e);
9082 // Check if this type is int
9085 exp.isConstant = false;
9089 exp.expType = Dereference(exp.index.exp.expType);
9091 DeclareType(exp.expType, false, false);
9098 Type methodType = null;
9104 PrintExpression(exp.call.exp, name);
9105 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9107 //exp.call.exp.expType = null;
9108 PrintExpression(exp.call.exp, name);
9111 if(exp.call.exp.type == identifierExp)
9113 Expression idExp = exp.call.exp;
9114 Identifier id = idExp.identifier;
9115 if(!strcmp(id.string, "__builtin_frame_address"))
9117 exp.expType = ProcessTypeString("void *", true);
9118 if(exp.call.arguments && exp.call.arguments->first)
9119 ProcessExpressionType(exp.call.arguments->first);
9122 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9124 exp.expType = ProcessTypeString("int", true);
9125 if(exp.call.arguments && exp.call.arguments->first)
9126 ProcessExpressionType(exp.call.arguments->first);
9129 else if(!strcmp(id.string, "Max") ||
9130 !strcmp(id.string, "Min") ||
9131 !strcmp(id.string, "Sgn") ||
9132 !strcmp(id.string, "Abs"))
9134 Expression a = null;
9135 Expression b = null;
9136 Expression tempExp1 = null, tempExp2 = null;
9137 if((!strcmp(id.string, "Max") ||
9138 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9140 a = exp.call.arguments->first;
9141 b = exp.call.arguments->last;
9145 else if(exp.call.arguments->count == 1)
9147 a = exp.call.arguments->first;
9153 exp.call.arguments->Clear();
9154 idExp.identifier = null;
9156 FreeExpContents(exp);
9158 ProcessExpressionType(a);
9160 ProcessExpressionType(b);
9162 exp.type = bracketsExp;
9163 exp.list = MkList();
9165 if(a.expType && (!b || b.expType))
9167 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9169 // Use the simpleStruct name/ids for now...
9172 OldList * specs = MkList();
9173 OldList * decls = MkList();
9175 char temp1[1024], temp2[1024];
9177 GetTypeSpecs(a.expType, specs);
9179 if(a && !a.isConstant && a.type != identifierExp)
9181 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9182 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9183 tempExp1 = QMkExpId(temp1);
9184 tempExp1.expType = a.expType;
9186 a.expType.refCount++;
9187 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9189 if(b && !b.isConstant && b.type != identifierExp)
9191 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9192 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9193 tempExp2 = QMkExpId(temp2);
9194 tempExp2.expType = b.expType;
9196 b.expType.refCount++;
9197 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9200 decl = MkDeclaration(specs, decls);
9201 if(!curCompound.compound.declarations)
9202 curCompound.compound.declarations = MkList();
9203 curCompound.compound.declarations->Insert(null, decl);
9208 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9210 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9212 MkExpCondition(MkExpBrackets(MkListOne(
9213 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9214 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9215 exp.expType = a.expType;
9217 a.expType.refCount++;
9219 else if(!strcmp(id.string, "Abs"))
9222 MkExpCondition(MkExpBrackets(MkListOne(
9223 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9224 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9225 exp.expType = a.expType;
9227 a.expType.refCount++;
9229 else if(!strcmp(id.string, "Sgn"))
9231 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9233 MkExpCondition(MkExpBrackets(MkListOne(
9234 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9235 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9236 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9237 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9238 exp.expType = ProcessTypeString("int", false);
9241 FreeExpression(tempExp1);
9242 if(tempExp2) FreeExpression(tempExp2);
9256 if(!exp.call.exp.destType)
9258 exp.call.exp.destType = dummy;
9261 ProcessExpressionType(exp.call.exp);
9262 if(exp.call.exp.destType == dummy)
9265 exp.call.exp.destType = null;
9270 // Check argument types against parameter types
9271 functionType = exp.call.exp.expType;
9273 if(functionType && functionType.kind == TypeKind::methodType)
9275 methodType = functionType;
9276 functionType = methodType.method.dataType;
9278 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9279 // TOCHECK: Instead of doing this here could this be done per param?
9280 if(exp.call.exp.expType.usedClass)
9282 char typeString[1024];
9283 typeString[0] = '\0';
9285 Symbol back = functionType.thisClass;
9286 // Do not output class specifier here (thisclass was added to this)
9287 functionType.thisClass = null;
9288 PrintType(functionType, typeString, true, true);
9289 functionType.thisClass = back;
9291 if(strstr(typeString, "thisclass"))
9293 OldList * specs = MkList();
9296 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9298 decl = SpecDeclFromString(typeString, specs, null);
9300 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9301 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9302 exp.call.exp.expType.usedClass))
9303 thisClassParams = false;
9305 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9307 Class backupThisClass = thisClass;
9308 thisClass = exp.call.exp.expType.usedClass;
9309 ProcessDeclarator(decl);
9310 thisClass = backupThisClass;
9313 thisClassParams = true;
9315 functionType = ProcessType(specs, decl);
9316 functionType.refCount = 0;
9317 FinishTemplatesContext(context);
9320 FreeList(specs, FreeSpecifier);
9321 FreeDeclarator(decl);
9325 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9327 Type type = functionType.type;
9328 if(!functionType.refCount)
9330 functionType.type = null;
9331 FreeType(functionType);
9333 //methodType = functionType;
9334 functionType = type;
9336 if(functionType && functionType.kind != TypeKind::functionType)
9338 Compiler_Error($"called object %s is not a function\n", name);
9340 else if(functionType)
9342 bool emptyParams = false, noParams = false;
9343 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9344 Type type = functionType.params.first;
9345 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9347 Location oldyylloc = yylloc;
9349 if(!type) emptyParams = true;
9352 if(functionType.extraParam && e && functionType.thisClass)
9354 e.destType = MkClassType(functionType.thisClass.string);
9358 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9359 // Fixed #141 by adding '&& !functionType.extraParam'
9360 if(!functionType.staticMethod && !functionType.extraParam)
9362 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9363 memberExp.member.exp.expType._class)
9365 type = MkClassType(memberExp.member.exp.expType._class.string);
9370 type = functionType.params.first;
9375 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9377 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9378 type.byReference = functionType.byReference;
9379 type.typedByReference = functionType.typedByReference;
9382 // Allow manually passing a class for typed object
9383 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9387 type = functionType.params.first;
9395 if(type && type.kind == voidType)
9398 if(!type.refCount) FreeType(type);
9402 for( ; e; e = e.next)
9404 if(!type && !emptyParams)
9407 if(methodType && methodType.methodClass)
9408 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9409 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9410 noParams ? 0 : functionType.params.count);
9412 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9413 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9414 noParams ? 0 : functionType.params.count);
9418 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9420 Type templatedType = null;
9421 Class _class = methodType.usedClass;
9422 ClassTemplateParameter curParam = null;
9424 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9427 for(sClass = _class; sClass; sClass = sClass.base)
9429 if(sClass.templateClass) sClass = sClass.templateClass;
9431 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9433 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9436 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9438 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9439 id += nextClass.templateParams.count;
9448 if(curParam && _class.templateArgs[id].dataTypeString)
9450 ClassTemplateArgument arg = _class.templateArgs[id];
9452 Context context = SetupTemplatesContext(_class);
9455 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9456 templatedType = ProcessTypeString(arg.dataTypeString, false);
9457 FinishTemplatesContext(context);
9459 e.destType = templatedType;
9462 templatedType.passAsTemplate = true;
9463 // templatedType.refCount++;
9469 if(type) type.refCount++;
9474 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9476 e.destType = type.prev;
9477 e.destType.refCount++;
9482 if(type) type.refCount++;
9485 // Don't reach the end for the ellipsis
9486 if(type && type.kind != ellipsisType)
9488 Type next = type.next;
9489 if(!type.refCount) FreeType(type);
9494 if(type && type.kind != ellipsisType)
9496 if(methodType && methodType.methodClass)
9497 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9498 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9499 functionType.params.count + extra);
9501 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9502 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9503 functionType.params.count + extra);
9506 if(type && !type.refCount) FreeType(type);
9513 kind = TypeKind::functionType;
9516 if(exp.call.exp.type == identifierExp)
9518 char * string = exp.call.exp.identifier.string;
9522 Location oldyylloc = yylloc;
9524 yylloc = exp.call.exp.identifier.loc;
9525 if(strstr(string, "__builtin_") == string)
9529 functionType.returnType = exp.destType;
9530 exp.destType.refCount++;
9534 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9535 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9536 globalContext.symbols.Add((BTNode)symbol);
9537 if(strstr(symbol.string, "::"))
9538 globalContext.hasNameSpace = true;
9543 else if(exp.call.exp.type == memberExp)
9545 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9546 exp.call.exp.member.member.string);*/
9549 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9551 if(!functionType.returnType)
9553 functionType.returnType = Type
9560 if(functionType && functionType.kind == TypeKind::functionType)
9562 exp.expType = functionType.returnType;
9564 if(functionType.returnType)
9565 functionType.returnType.refCount++;
9567 if(!functionType.refCount)
9568 FreeType(functionType);
9571 if(exp.call.arguments)
9573 for(e = exp.call.arguments->first; e; e = e.next)
9575 Type destType = e.destType;
9576 ProcessExpressionType(e);
9584 Location oldyylloc = yylloc;
9586 Expression checkExp = exp.member.exp;
9589 if(checkExp.type == castExp)
9590 checkExp = checkExp.cast.exp;
9591 else if(checkExp.type == bracketsExp)
9592 checkExp = checkExp.list ? checkExp.list->first : null;
9597 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9598 exp.thisPtr = thisPtr;
9600 // DOING THIS LATER NOW...
9601 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9603 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9604 /* TODO: Name Space Fix ups
9605 if(!exp.member.member.classSym)
9606 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9610 ProcessExpressionType(exp.member.exp);
9611 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9612 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9614 exp.isConstant = false;
9617 exp.isConstant = exp.member.exp.isConstant;
9618 type = exp.member.exp.expType;
9622 if(type && (type.kind == templateType))
9624 Class _class = thisClass ? thisClass : currentClass;
9625 ClassTemplateParameter param = null;
9628 for(param = _class.templateParams.first; param; param = param.next)
9630 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9634 if(param && param.defaultArg.member)
9636 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9639 Expression expMember = exp.member.exp;
9641 OldList * specs = MkList();
9642 char thisClassTypeString[1024];
9644 FreeIdentifier(exp.member.member);
9646 ProcessExpressionType(argExp);
9649 char * colon = strstr(param.defaultArg.memberString, "::");
9652 char className[1024];
9655 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9656 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9659 strcpy(thisClassTypeString, _class.fullName);
9662 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9664 exp.expType = ProcessType(specs, decl);
9665 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9667 Class expClass = exp.expType._class.registered;
9668 Class cClass = null;
9673 char templateString[1024];
9674 ClassTemplateParameter param;
9675 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9676 for(cClass = expClass; cClass; cClass = cClass.base)
9679 for(param = cClass.templateParams.first; param; param = param.next)
9683 ClassTemplateArgument arg;
9684 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9685 arg = expClass.templateArgs[id];
9687 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9689 ClassTemplateParameter cParam;
9690 //int p = numParams - sClass.templateParams.count;
9693 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9695 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9697 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9699 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9701 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9702 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9714 strcat(argument, arg.name.string);
9715 strcat(argument, " = ");
9721 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9722 char expString[1024];
9723 OldList * specs = MkList();
9724 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9726 char * string = PrintHexUInt64(arg.expression.ui64);
9727 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9730 ProcessExpressionType(exp);
9731 ComputeExpression(exp);
9732 expString[0] = '\0';
9733 PrintExpression(exp, expString);
9734 strcat(argument, expString);
9736 FreeExpression(exp);
9741 strcat(argument, arg.member.name);
9744 case TemplateParameterType::type:
9746 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9748 if(!strcmp(arg.dataTypeString, "thisclass"))
9749 strcat(argument, thisClassTypeString);
9751 strcat(argument, arg.dataTypeString);
9758 if(paramCount) strcat(templateString, ", ");
9759 if(lastParam != p - 1)
9761 strcat(templateString, param.name);
9762 strcat(templateString, " = ");
9764 strcat(templateString, argument);
9773 int len = strlen(templateString);
9774 if(templateString[len-1] == '>') templateString[len++] = ' ';
9775 templateString[len++] = '>';
9776 templateString[len++] = '\0';
9779 Context context = SetupTemplatesContext(_class);
9780 FreeType(exp.expType);
9781 exp.expType = ProcessTypeString(templateString, false);
9782 FinishTemplatesContext(context);
9786 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
9787 exp.type = bracketsExp;
9788 exp.list = MkListOne(MkExpOp(null, '*',
9793 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9794 MkExpBrackets(MkListOne(
9795 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
9797 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9799 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9804 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9805 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9807 type = ProcessTemplateParameterType(type.templateParameter);
9810 // TODO: *** This seems to be where we should add method support for all basic types ***
9811 if(type && (type.kind == templateType));
9812 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9813 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
9814 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9815 (type.kind == pointerType && type.type.kind == charType)))
9817 Identifier id = exp.member.member;
9818 TypeKind typeKind = type.kind;
9819 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9820 if(typeKind == subClassType && exp.member.exp.type == classExp)
9822 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9823 typeKind = classType;
9828 if(typeKind == intType || typeKind == enumType)
9829 _class = eSystem_FindClass(privateModule, "int");
9832 if(type.kind == classType && type._class && type._class.registered)
9834 _class = type._class.registered;
9836 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
9838 _class = FindClass("char *").registered;
9840 else if(type.kind == pointerType)
9842 _class = eSystem_FindClass(privateModule, "uintptr");
9843 FreeType(exp.expType);
9844 exp.expType = ProcessTypeString("uintptr", false);
9845 exp.byReference = true;
9849 char string[1024] = "";
9851 PrintTypeNoConst(type, string, false, true);
9852 classSym = FindClass(string);
9853 if(classSym) _class = classSym.registered;
9861 (exp.member.exp.type == identifierExp &&
9862 !strcmp(exp.member.exp.identifier.string, "this"));*/
9863 Property prop = null;
9864 Method method = null;
9865 DataMember member = null;
9866 Property revConvert = null;
9867 ClassProperty classProp = null;
9869 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
9870 exp.member.memberType = propertyMember;
9872 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
9873 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
9875 if(typeKind != subClassType)
9877 // Prioritize data members over properties for "this"
9878 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
9880 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9881 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
9883 prop = eClass_FindProperty(_class, id.string, privateModule);
9887 if(!member && !prop)
9888 prop = eClass_FindProperty(_class, id.string, privateModule);
9889 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
9890 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
9891 exp.member.thisPtr = true;
9893 // Prioritize properties over data members otherwise
9896 // First look for Public Members (Unless class specifier is provided, which skips public priority)
9899 prop = eClass_FindProperty(_class, id.string, null);
9900 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9901 member = eClass_FindDataMember(_class, id.string, null, null, null);
9904 if(!prop && !member)
9906 method = eClass_FindMethod(_class, id.string, null);
9909 prop = eClass_FindProperty(_class, id.string, privateModule);
9910 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
9911 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
9917 if(member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class))
9924 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
9925 method = eClass_FindMethod(_class, id.string, privateModule);
9926 if(!prop && !member && !method)
9928 if(typeKind == subClassType)
9930 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
9933 exp.member.memberType = classPropertyMember;
9934 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
9938 // Assume this is a class_data member
9939 char structName[1024];
9940 Identifier id = exp.member.member;
9941 Expression classExp = exp.member.exp;
9944 FreeType(classExp.expType);
9945 classExp.expType = ProcessTypeString("ecere::com::Class", false);
9947 strcpy(structName, "__ecereClassData_");
9948 FullClassNameCat(structName, type._class.string, false);
9949 exp.type = pointerExp;
9950 exp.member.member = id;
9952 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
9953 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
9954 MkExpBrackets(MkListOne(MkExpOp(
9955 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
9956 MkExpMember(classExp, MkIdentifier("data"))), '+',
9957 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
9962 ProcessExpressionType(exp);
9968 // Check for reverse conversion
9969 // (Convert in an instantiation later, so that we can use
9970 // deep properties system)
9971 Symbol classSym = FindClass(id.string);
9974 Class convertClass = classSym.registered;
9976 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
9983 exp.member.memberType = propertyMember;
9985 ProcessPropertyType(prop);
9986 exp.expType = prop.dataType;
9987 if(prop.dataType) prop.dataType.refCount++;
9991 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
9993 FreeExpContents(exp);
9994 exp.type = identifierExp;
9995 exp.identifier = MkIdentifier("class");
9996 ProcessExpressionType(exp);
10000 exp.member.memberType = dataMember;
10001 DeclareStruct(_class.fullName, false);
10002 if(!member.dataType)
10004 Context context = SetupTemplatesContext(_class);
10005 member.dataType = ProcessTypeString(member.dataTypeString, false);
10006 FinishTemplatesContext(context);
10008 exp.expType = member.dataType;
10009 if(member.dataType) member.dataType.refCount++;
10011 else if(revConvert)
10013 exp.member.memberType = reverseConversionMember;
10014 exp.expType = MkClassType(revConvert._class.fullName);
10022 exp.type = identifierExp;
10023 exp.identifier = exp.member.member;
10026 exp.member.memberType = methodMember;
10028 if(!method.dataType)
10029 ProcessMethodType(method);
10037 // Tricky spot here... To use instance versus class virtual table
10038 // Put it back to what it was... What did we break?
10040 // Had to put it back for overriding Main of Thread global instance
10042 //exp.expType.methodClass = _class;
10043 exp.expType.methodClass = (id && id._class) ? _class : null;
10045 // Need the actual class used for templated classes
10046 exp.expType.usedClass = _class;
10048 else if(!classProp)
10050 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10052 FreeExpContents(exp);
10053 exp.type = identifierExp;
10054 exp.identifier = MkIdentifier("class");
10055 FreeType(exp.expType);
10056 exp.expType = MkClassType("ecere::com::Class");
10059 yylloc = exp.member.member.loc;
10060 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10062 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10065 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10070 while(tClass && !tClass.templateClass) tClass = tClass.base;
10072 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10075 ClassTemplateParameter curParam = null;
10078 for(sClass = tClass; sClass; sClass = sClass.base)
10081 if(sClass.templateClass) sClass = sClass.templateClass;
10082 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10084 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10086 for(sClass = sClass.base; sClass; sClass = sClass.base)
10087 id += sClass.templateParams.count;
10092 if(curParam) break;
10095 if(curParam && tClass.templateArgs[id].dataTypeString)
10097 ClassTemplateArgument arg = tClass.templateArgs[id];
10098 Context context = SetupTemplatesContext(tClass);
10099 /*if(!arg.dataType)
10100 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10101 FreeType(exp.expType);
10102 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10105 if(exp.expType.kind == thisClassType)
10107 FreeType(exp.expType);
10108 exp.expType = ReplaceThisClassType(_class);
10111 if(tClass.templateClass)
10112 exp.expType.passAsTemplate = true;
10113 //exp.expType.refCount++;
10116 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10117 //exp.destType.refCount++;
10119 if(exp.destType.kind == thisClassType)
10121 FreeType(exp.destType);
10122 exp.destType = ReplaceThisClassType(_class);
10126 FinishTemplatesContext(context);
10129 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10130 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10133 ClassTemplateParameter curParam = null;
10136 for(sClass = tClass; sClass; sClass = sClass.base)
10139 if(sClass.templateClass) sClass = sClass.templateClass;
10140 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10142 if(curParam.type == TemplateParameterType::type &&
10143 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10145 for(sClass = sClass.base; sClass; sClass = sClass.base)
10146 id += sClass.templateParams.count;
10151 if(curParam) break;
10156 ClassTemplateArgument arg = tClass.templateArgs[id];
10157 Context context = SetupTemplatesContext(tClass);
10159 /*if(!arg.dataType)
10160 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10162 basicType = ProcessTypeString(arg.dataTypeString, false);
10165 if(basicType.kind == thisClassType)
10167 FreeType(basicType);
10168 basicType = ReplaceThisClassType(_class);
10171 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10172 if(tClass.templateClass)
10173 basicType.passAsTemplate = true;
10176 FreeType(exp.expType);
10178 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10179 //exp.expType.refCount++;
10182 exp.destType = exp.expType;
10183 exp.destType.refCount++;
10187 Expression newExp { };
10188 OldList * specs = MkList();
10190 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10192 if(exp.destType) exp.destType.refCount++;
10193 if(exp.expType) exp.expType.refCount++;
10194 exp.type = castExp;
10195 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10196 exp.cast.exp = newExp;
10197 //FreeType(exp.expType);
10198 //exp.expType = null;
10199 //ProcessExpressionType(sourceExp);
10202 FinishTemplatesContext(context);
10205 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10207 Class expClass = exp.expType._class.registered;
10210 Class cClass = null;
10213 int paramCount = 0;
10214 int lastParam = -1;
10215 char templateString[1024];
10216 ClassTemplateParameter param;
10217 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10218 while(cClass != expClass)
10221 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10224 for(param = cClass.templateParams.first; param; param = param.next)
10226 Class cClassCur = null;
10229 ClassTemplateParameter paramCur = null;
10230 ClassTemplateArgument arg;
10231 while(cClassCur != tClass && !paramCur)
10234 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10235 cClassCur = sClassCur;
10237 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10239 if(!strcmp(paramCur.name, param.name))
10247 if(paramCur && paramCur.type == TemplateParameterType::type)
10248 arg = tClass.templateArgs[cp];
10250 arg = expClass.templateArgs[p];
10253 char argument[256];
10254 argument[0] = '\0';
10257 strcat(argument, arg.name.string);
10258 strcat(argument, " = ");
10264 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10265 char expString[1024];
10266 OldList * specs = MkList();
10267 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10269 char * string = PrintHexUInt64(arg.expression.ui64);
10270 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10273 ProcessExpressionType(exp);
10274 ComputeExpression(exp);
10275 expString[0] = '\0';
10276 PrintExpression(exp, expString);
10277 strcat(argument, expString);
10279 FreeExpression(exp);
10284 strcat(argument, arg.member.name);
10287 case TemplateParameterType::type:
10289 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10290 strcat(argument, arg.dataTypeString);
10296 if(paramCount) strcat(templateString, ", ");
10297 if(lastParam != p - 1)
10299 strcat(templateString, param.name);
10300 strcat(templateString, " = ");
10302 strcat(templateString, argument);
10311 int len = strlen(templateString);
10312 if(templateString[len-1] == '>') templateString[len++] = ' ';
10313 templateString[len++] = '>';
10314 templateString[len++] = '\0';
10317 FreeType(exp.expType);
10319 Context context = SetupTemplatesContext(tClass);
10320 exp.expType = ProcessTypeString(templateString, false);
10321 FinishTemplatesContext(context);
10328 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10330 else if(type && (type.kind == structType || type.kind == unionType))
10332 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10335 exp.expType = memberType;
10337 memberType.refCount++;
10342 char expString[10240];
10343 expString[0] = '\0';
10344 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10345 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10348 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10350 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10352 Identifier id = exp.member.member;
10353 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10356 FreeType(exp.expType);
10357 exp.expType = ReplaceThisClassType(_class);
10361 yylloc = oldyylloc;
10364 // Convert x->y into (*x).y
10367 Type destType = exp.destType;
10369 // DOING THIS LATER NOW...
10370 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10372 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10373 /* TODO: Name Space Fix ups
10374 if(!exp.member.member.classSym)
10375 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10379 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10380 exp.type = memberExp;
10383 ProcessExpressionType(exp);
10390 //ComputeExpression(exp);
10392 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10393 if(classSym && classSym.registered)
10395 if(classSym.registered.type == noHeadClass)
10399 DeclareStruct(classSym.string, false);
10400 FreeSpecifier(exp._class);
10401 exp.type = typeSizeExp;
10402 FullClassNameCat(name, classSym.string, false);
10403 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10407 if(classSym.registered.fixed)
10409 FreeSpecifier(exp._class);
10410 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10411 exp.type = constantExp;
10415 char className[1024];
10416 strcpy(className, "__ecereClass_");
10417 FullClassNameCat(className, classSym.string, true);
10418 MangleClassName(className);
10420 DeclareClass(classSym, className);
10422 FreeExpContents(exp);
10423 exp.type = pointerExp;
10424 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10425 exp.member.member = MkIdentifier("structSize");
10433 kind = intSizeType;
10435 // exp.isConstant = true;
10440 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10445 kind = intSizeType;
10447 exp.isConstant = true;
10449 DeclareType(type, false, false);
10455 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10457 FreeType(exp.cast.exp.destType);
10458 exp.cast.exp.destType = type;
10460 ProcessExpressionType(exp.cast.exp);
10462 exp.expType = type;
10465 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10466 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10468 void * prev = exp.prev, * next = exp.next;
10469 Type expType = exp.cast.exp.destType;
10470 Expression castExp = exp.cast.exp;
10471 Type destType = exp.destType;
10473 if(expType) expType.refCount++;
10475 //FreeType(exp.destType);
10476 FreeType(exp.expType);
10477 FreeTypeName(exp.cast.typeName);
10480 FreeType(exp.expType);
10481 FreeType(exp.destType);
10483 exp.expType = expType;
10484 exp.destType = destType;
10494 exp.isConstant = exp.cast.exp.isConstant;
10499 case extensionInitializerExp:
10501 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10502 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10503 // ProcessInitializer(exp.initializer.initializer, type);
10504 exp.expType = type;
10509 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10510 ProcessExpressionType(exp.vaArg.exp);
10511 exp.expType = type;
10517 exp.isConstant = true;
10519 FreeType(exp.cond.cond.destType);
10520 exp.cond.cond.destType = MkClassType("bool");
10521 exp.cond.cond.destType.truth = true;
10522 ProcessExpressionType(exp.cond.cond);
10523 if(!exp.cond.cond.isConstant)
10524 exp.isConstant = false;
10525 for(e = exp.cond.exp->first; e; e = e.next)
10529 FreeType(e.destType);
10530 e.destType = exp.destType;
10531 if(e.destType) e.destType.refCount++;
10533 ProcessExpressionType(e);
10536 exp.expType = e.expType;
10537 if(e.expType) e.expType.refCount++;
10540 exp.isConstant = false;
10543 FreeType(exp.cond.elseExp.destType);
10544 // Added this check if we failed to find an expType
10545 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10548 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10550 if(exp.cond.elseExp.destType)
10551 exp.cond.elseExp.destType.refCount++;
10552 ProcessExpressionType(exp.cond.elseExp);
10554 // FIXED THIS: Was done before calling process on elseExp
10555 if(!exp.cond.elseExp.isConstant)
10556 exp.isConstant = false;
10559 case extensionCompoundExp:
10561 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10563 Statement last = exp.compound.compound.statements->last;
10564 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10566 ((Expression)last.expressions->last).destType = exp.destType;
10568 exp.destType.refCount++;
10570 ProcessStatement(exp.compound);
10571 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10573 exp.expType.refCount++;
10579 Specifier spec = exp._classExp.specifiers->first;
10580 if(spec && spec.type == nameSpecifier)
10582 exp.expType = MkClassType(spec.name);
10583 exp.expType.kind = subClassType;
10584 exp.byReference = true;
10588 exp.expType = MkClassType("ecere::com::Class");
10589 exp.byReference = true;
10595 Class _class = thisClass ? thisClass : currentClass;
10598 Identifier id = exp.classData.id;
10599 char structName[1024];
10600 Expression classExp;
10601 strcpy(structName, "__ecereClassData_");
10602 FullClassNameCat(structName, _class.fullName, false);
10603 exp.type = pointerExp;
10604 exp.member.member = id;
10605 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10606 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10608 classExp = MkExpIdentifier(MkIdentifier("class"));
10610 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10611 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10612 MkExpBrackets(MkListOne(MkExpOp(
10613 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10614 MkExpMember(classExp, MkIdentifier("data"))), '+',
10615 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10618 ProcessExpressionType(exp);
10626 char * typeString = null;
10627 char typeStringBuf[1024];
10628 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10629 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10631 Class templateClass = exp.destType._class.registered;
10632 typeString = templateClass.templateArgs[2].dataTypeString;
10636 // Guess type from expressions in the array
10638 for(e = exp.list->first; e; e = e.next)
10640 ProcessExpressionType(e);
10643 if(!type) { type = e.expType; type.refCount++; }
10646 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10647 if(!MatchTypeExpression(e, type, null, false))
10653 e = exp.list->first;
10654 ProcessExpressionType(e);
10657 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10658 if(!MatchTypeExpression(e, type, null, false))
10660 FreeType(e.expType);
10671 FreeType(e.expType);
10678 typeStringBuf[0] = '\0';
10679 PrintTypeNoConst(type, typeStringBuf, false, true);
10680 typeString = typeStringBuf;
10688 (Container)& (struct BuiltInContainer)
10690 ._vTbl = class(BuiltInContainer)._vTbl,
10691 ._class = class(BuiltInContainer),
10693 .data = (int[]){ 1, 7, 3, 4, 5 },
10695 .type = class(int),
10698 char templateString[1024];
10699 OldList * initializers = MkList();
10700 OldList * structInitializers = MkList();
10701 OldList * specs = MkList();
10703 Declarator decl = SpecDeclFromString(typeString, specs, null);
10704 sprintf(templateString, "Container<%s>", typeString);
10709 type = ProcessTypeString(typeString, false);
10710 while(e = exp.list->first)
10712 exp.list->Remove(e);
10715 ProcessExpressionType(e);
10716 ListAdd(initializers, MkInitializerAssignment(e));
10722 DeclareStruct("ecere::com::BuiltInContainer", false);
10724 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
10725 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10726 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
10727 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10728 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
10729 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10730 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
10731 MkTypeName(specs, MkDeclaratorArray(decl, null)),
10732 MkInitializerList(initializers))));
10733 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10734 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
10735 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10736 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
10737 ProcessExpressionType(((Initializer)structInitializers->last).exp);
10738 exp.expType = ProcessTypeString(templateString, false);
10739 exp.type = bracketsExp;
10740 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
10742 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
10743 MkInitializerList(structInitializers)))));
10744 ProcessExpressionType(expExt);
10748 exp.expType = ProcessTypeString("Container", false);
10749 Compiler_Error($"Couldn't determine type of array elements\n");
10755 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
10757 FreeType(exp.expType);
10758 exp.expType = ReplaceThisClassType(thisClass);
10761 // Resolve structures here
10762 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
10764 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
10765 // TODO: Fix members reference...
10768 if(exp.expType.kind != enumType)
10771 String enumName = CopyString(exp.expType.enumName);
10773 // Fixed a memory leak on self-referencing C structs typedefs
10774 // by instantiating a new type rather than simply copying members
10775 // into exp.expType
10776 FreeType(exp.expType);
10777 exp.expType = Type { };
10778 exp.expType.kind = symbol.type.kind;
10779 exp.expType.refCount++;
10780 exp.expType.enumName = enumName;
10782 exp.expType.members = symbol.type.members;
10783 for(member = symbol.type.members.first; member; member = member.next)
10789 for(member = symbol.type.members.first; member; member = member.next)
10791 NamedLink value { name = CopyString(member.name) };
10792 exp.expType.members.Add(value);
10799 if(exp.destType && (exp.destType.kind == voidType || exp.destType.kind == dummyType) );
10800 else if(exp.destType && !exp.destType.keepCast)
10802 if(!CheckExpressionType(exp, exp.destType, false))
10804 if(!exp.destType.count || unresolved)
10809 if(exp.destType.kind != ellipsisType)
10815 char expString[10240];
10816 expString[0] = '\0';
10818 PrintType(exp.destType, type2, false, true);
10820 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10822 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
10823 else if(exp.type != dummyExp)
10824 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
10829 char expString[10240] ;
10830 expString[0] = '\0';
10831 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10834 Compiler_Error($"unresolved identifier %s\n", expString);
10835 else if(exp.type != dummyExp)
10836 Compiler_Error($"couldn't determine type of %s\n", expString);
10847 PrintType(exp.expType, type1, false, true);
10848 PrintType(exp.destType, type2, false, true);
10851 //CheckExpressionType(exp, exp.destType, false);
10853 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
10854 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
10855 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
10858 char expString[10240];
10859 expString[0] = '\0';
10860 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10863 CheckExpressionType(exp, exp.destType, false);
10865 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
10866 if(!sourceFile || (strcmp(sourceFile, "src\\lexer.ec") && strcmp(sourceFile, "src/lexer.ec") && strcmp(sourceFile, "src\\grammar.ec") && strcmp(sourceFile, "src/grammar.ec")))
10867 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
10869 // TO CHECK: FORCING HERE TO HELP DEBUGGER
10870 FreeType(exp.expType);
10871 exp.destType.refCount++;
10872 exp.expType = exp.destType;
10877 else if(exp.destType && exp.destType.kind == ellipsisType && exp.expType && exp.expType.passAsTemplate)
10879 Expression newExp { };
10880 char typeString[1024];
10881 OldList * specs = MkList();
10884 typeString[0] = '\0';
10888 if(exp.expType) exp.expType.refCount++;
10889 if(exp.expType) exp.expType.refCount++;
10890 exp.type = castExp;
10891 newExp.destType = exp.expType;
10893 PrintType(exp.expType, typeString, false, false);
10894 decl = SpecDeclFromString(typeString, specs, null);
10896 exp.cast.typeName = MkTypeName(specs, decl);
10897 exp.cast.exp = newExp;
10900 else if(unresolved)
10902 if(exp.identifier._class && exp.identifier._class.name)
10903 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
10904 else if(exp.identifier.string && exp.identifier.string[0])
10905 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
10907 else if(!exp.expType && exp.type != dummyExp)
10909 char expString[10240];
10910 expString[0] = '\0';
10911 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10912 Compiler_Error($"couldn't determine type of %s\n", expString);
10915 // Let's try to support any_object & typed_object here:
10917 ApplyAnyObjectLogic(exp);
10919 // Mark nohead classes as by reference, unless we're casting them to an integral type
10920 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
10921 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
10922 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
10923 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
10925 exp.byReference = true;
10927 yylloc = oldyylloc;
10930 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
10932 // THIS CODE WILL FIND NEXT MEMBER...
10935 *curMember = (*curMember).next;
10937 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
10939 *curMember = subMemberStack[--(*subMemberStackPos)];
10940 *curMember = (*curMember).next;
10943 // SKIP ALL PROPERTIES HERE...
10944 while((*curMember) && (*curMember).isProperty)
10945 *curMember = (*curMember).next;
10947 if(subMemberStackPos)
10949 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10951 subMemberStack[(*subMemberStackPos)++] = *curMember;
10953 *curMember = (*curMember).members.first;
10954 while(*curMember && (*curMember).isProperty)
10955 *curMember = (*curMember).next;
10963 if(subMemberStackPos && *subMemberStackPos)
10965 *curMember = subMemberStack[--(*subMemberStackPos)];
10966 *curMember = (*curMember).next;
10970 Class lastCurClass = *curClass;
10972 if(*curClass == _class) break; // REACHED THE END
10974 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
10975 *curMember = (*curClass).membersAndProperties.first;
10978 while((*curMember) && (*curMember).isProperty)
10979 *curMember = (*curMember).next;
10980 if(subMemberStackPos)
10982 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
10984 subMemberStack[(*subMemberStackPos)++] = *curMember;
10986 *curMember = (*curMember).members.first;
10987 while(*curMember && (*curMember).isProperty)
10988 *curMember = (*curMember).next;
10996 static void ProcessInitializer(Initializer init, Type type)
11000 case expInitializer:
11001 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11003 // TESTING THIS FOR SHUTTING = 0 WARNING
11004 if(init.exp && !init.exp.destType)
11006 FreeType(init.exp.destType);
11007 init.exp.destType = type;
11008 if(type) type.refCount++;
11012 ProcessExpressionType(init.exp);
11013 init.isConstant = init.exp.isConstant;
11019 Expression exp = init.exp;
11020 Instantiation inst = exp.instance;
11021 MembersInit members;
11023 init.type = listInitializer;
11024 init.list = MkList();
11028 for(members = inst.members->first; members; members = members.next)
11030 if(members.type == dataMembersInit)
11033 for(member = members.dataMembers->first; member; member = member.next)
11035 ListAdd(init.list, member.initializer);
11036 member.initializer = null;
11039 // Discard all MembersInitMethod
11042 FreeExpression(exp);
11044 case listInitializer:
11047 Type initializerType = null;
11048 Class curClass = null;
11049 DataMember curMember = null;
11050 DataMember subMemberStack[256];
11051 int subMemberStackPos = 0;
11053 if(type && type.kind == arrayType)
11054 initializerType = Dereference(type);
11055 else if(type && (type.kind == structType || type.kind == unionType))
11056 initializerType = type.members.first;
11058 for(i = init.list->first; i; i = i.next)
11060 if(type && type.kind == classType && type._class && type._class.registered)
11062 // 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)
11063 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11064 // TODO: Generate error on initializing a private data member this way from another module...
11067 if(!curMember.dataType)
11068 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11069 initializerType = curMember.dataType;
11072 ProcessInitializer(i, initializerType);
11073 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11074 initializerType = initializerType.next;
11076 init.isConstant = false;
11079 if(type && type.kind == arrayType)
11080 FreeType(initializerType);
11082 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11084 Compiler_Error($"Assigning list initializer to non list\n");
11091 static void ProcessSpecifier(Specifier spec, bool declareStruct)
11095 case baseSpecifier:
11097 if(spec.specifier == THISCLASS)
11101 spec.type = nameSpecifier;
11102 spec.name = ReplaceThisClass(thisClass);
11103 spec.symbol = FindClass(spec.name);
11104 ProcessSpecifier(spec, declareStruct);
11109 case nameSpecifier:
11111 Symbol symbol = FindType(curContext, spec.name);
11113 DeclareType(symbol.type, true, true);
11114 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
11115 DeclareStruct(spec.name, false);
11118 case enumSpecifier:
11123 for(e = spec.list->first; e; e = e.next)
11126 ProcessExpressionType(e.exp);
11131 case structSpecifier:
11132 case unionSpecifier:
11134 if(spec.definitions)
11137 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11139 ProcessClass(spec.definitions, symbol);
11142 for(def = spec.definitions->first; def; def = def.next)
11144 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11145 ProcessDeclaration(def.decl);
11152 case classSpecifier:
11154 Symbol classSym = FindClass(spec.name);
11155 if(classSym && classSym.registered && classSym.registered.type == structClass)
11156 DeclareStruct(spec.name, false);
11164 static void ProcessDeclarator(Declarator decl)
11168 case identifierDeclarator:
11169 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11171 FreeSpecifier(decl.identifier._class);
11172 decl.identifier._class = null;
11175 case arrayDeclarator:
11177 ProcessExpressionType(decl.array.exp);
11178 case structDeclarator:
11179 case bracketsDeclarator:
11180 case functionDeclarator:
11181 case pointerDeclarator:
11182 case extendedDeclarator:
11183 case extendedDeclaratorEnd:
11184 if(decl.declarator)
11185 ProcessDeclarator(decl.declarator);
11186 if(decl.type == functionDeclarator)
11188 Identifier id = GetDeclId(decl);
11189 if(id && id._class)
11193 qualifiers = MkListOne(id._class);
11196 if(!decl.function.parameters)
11197 decl.function.parameters = MkList();
11198 decl.function.parameters->Insert(null, param);
11201 if(decl.function.parameters)
11205 for(param = decl.function.parameters->first; param; param = param.next)
11207 if(param.qualifiers && param.qualifiers->first)
11209 Specifier spec = param.qualifiers->first;
11210 if(spec && spec.specifier == TYPED_OBJECT)
11212 Declarator d = param.declarator;
11215 qualifiers = MkListOne(MkSpecifier(VOID));
11216 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11219 FreeList(param.qualifiers, FreeSpecifier);
11221 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11222 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11224 decl.function.parameters->Insert(param, newParam);
11227 else if(spec && spec.specifier == ANY_OBJECT)
11229 Declarator d = param.declarator;
11231 FreeList(param.qualifiers, FreeSpecifier);
11233 param.qualifiers = MkListOne(MkSpecifier(VOID));
11234 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11236 else if(spec.specifier == THISCLASS)
11240 spec.type = nameSpecifier;
11241 spec.name = ReplaceThisClass(thisClass);
11242 spec.symbol = FindClass(spec.name);
11243 ProcessSpecifier(spec, false);
11248 if(param.declarator)
11249 ProcessDeclarator(param.declarator);
11257 static void ProcessDeclaration(Declaration decl)
11262 case initDeclaration:
11264 bool declareStruct = false;
11266 lineNum = decl.pos.line;
11267 column = decl.pos.col;
11270 if(decl.declarators)
11274 for(d = decl.declarators->first; d; d = d.next)
11276 Type type, subType;
11277 ProcessDeclarator(d.declarator);
11279 type = ProcessType(decl.specifiers, d.declarator);
11283 ProcessInitializer(d.initializer, type);
11285 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11287 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11288 d.initializer.exp.type == instanceExp)
11290 if(type.kind == classType && type._class ==
11291 d.initializer.exp.expType._class)
11293 Instantiation inst = d.initializer.exp.instance;
11294 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11296 d.initializer.exp.instance = null;
11297 if(decl.specifiers)
11298 FreeList(decl.specifiers, FreeSpecifier);
11299 FreeList(decl.declarators, FreeInitDeclarator);
11303 decl.type = instDeclaration;
11308 for(subType = type; subType;)
11310 if(subType.kind == classType)
11312 declareStruct = true;
11315 else if(subType.kind == pointerType)
11317 else if(subType.kind == arrayType)
11318 subType = subType.arrayType;
11328 if(decl.specifiers)
11331 for(s = decl.specifiers->first; s; s = s.next)
11333 ProcessSpecifier(s, declareStruct);
11338 case instDeclaration:
11340 ProcessInstantiationType(decl.inst);
11343 case structDeclaration:
11347 bool declareStruct = false;
11349 if(decl.declarators)
11351 for(d = decl.declarators->first; d; d = d.next)
11353 Type type = ProcessType(decl.specifiers, d.declarator);
11355 ProcessDeclarator(d);
11356 for(subType = type; subType;)
11358 if(subType.kind == classType)
11360 declareStruct = true;
11363 else if(subType.kind == pointerType)
11365 else if(subType.kind == arrayType)
11366 subType = subType.arrayType;
11373 if(decl.specifiers)
11375 for(spec = decl.specifiers->first; spec; spec = spec.next)
11376 ProcessSpecifier(spec, declareStruct);
11383 static FunctionDefinition curFunction;
11385 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11387 char propName[1024], propNameM[1024];
11388 char getName[1024], setName[1024];
11391 DeclareProperty(prop, setName, getName);
11393 // eInstance_FireWatchers(object, prop);
11394 strcpy(propName, "__ecereProp_");
11395 FullClassNameCat(propName, prop._class.fullName, false);
11396 strcat(propName, "_");
11397 // strcat(propName, prop.name);
11398 FullClassNameCat(propName, prop.name, true);
11399 MangleClassName(propName);
11401 strcpy(propNameM, "__ecerePropM_");
11402 FullClassNameCat(propNameM, prop._class.fullName, false);
11403 strcat(propNameM, "_");
11404 // strcat(propNameM, prop.name);
11405 FullClassNameCat(propNameM, prop.name, true);
11406 MangleClassName(propNameM);
11408 if(prop.isWatchable)
11411 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11412 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11413 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11416 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11417 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11418 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11424 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11425 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11426 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11429 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11430 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11431 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11434 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11435 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11436 curFunction.propSet.fireWatchersDone = true;
11439 static void ProcessStatement(Statement stmt)
11443 lineNum = stmt.pos.line;
11444 column = stmt.pos.col;
11449 ProcessStatement(stmt.labeled.stmt);
11452 // This expression should be constant...
11453 if(stmt.caseStmt.exp)
11455 FreeType(stmt.caseStmt.exp.destType);
11456 stmt.caseStmt.exp.destType = curSwitchType;
11457 if(curSwitchType) curSwitchType.refCount++;
11458 ProcessExpressionType(stmt.caseStmt.exp);
11459 ComputeExpression(stmt.caseStmt.exp);
11461 if(stmt.caseStmt.stmt)
11462 ProcessStatement(stmt.caseStmt.stmt);
11466 if(stmt.compound.context)
11471 Statement prevCompound = curCompound;
11472 Context prevContext = curContext;
11474 if(!stmt.compound.isSwitch)
11475 curCompound = stmt;
11476 curContext = stmt.compound.context;
11478 if(stmt.compound.declarations)
11480 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11481 ProcessDeclaration(decl);
11483 if(stmt.compound.statements)
11485 for(s = stmt.compound.statements->first; s; s = s.next)
11486 ProcessStatement(s);
11489 curContext = prevContext;
11490 curCompound = prevCompound;
11494 case expressionStmt:
11497 if(stmt.expressions)
11499 for(exp = stmt.expressions->first; exp; exp = exp.next)
11500 ProcessExpressionType(exp);
11508 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11509 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11510 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11511 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11513 ProcessExpressionType(exp);
11515 if(stmt.ifStmt.stmt)
11516 ProcessStatement(stmt.ifStmt.stmt);
11517 if(stmt.ifStmt.elseStmt)
11518 ProcessStatement(stmt.ifStmt.elseStmt);
11523 Type oldSwitchType = curSwitchType;
11524 if(stmt.switchStmt.exp)
11527 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11537 e.exp.destType = destType;
11540 ProcessExpressionType(exp);
11543 curSwitchType = exp.expType;
11546 ProcessStatement(stmt.switchStmt.stmt);
11547 curSwitchType = oldSwitchType;
11552 if(stmt.whileStmt.exp)
11556 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11557 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11558 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11559 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11561 ProcessExpressionType(exp);
11564 if(stmt.whileStmt.stmt)
11565 ProcessStatement(stmt.whileStmt.stmt);
11570 if(stmt.doWhile.exp)
11574 if(stmt.doWhile.exp->last)
11576 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11577 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11578 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11580 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11582 ProcessExpressionType(exp);
11585 if(stmt.doWhile.stmt)
11586 ProcessStatement(stmt.doWhile.stmt);
11592 if(stmt.forStmt.init)
11593 ProcessStatement(stmt.forStmt.init);
11595 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11597 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11598 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11599 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11602 if(stmt.forStmt.check)
11603 ProcessStatement(stmt.forStmt.check);
11604 if(stmt.forStmt.increment)
11606 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11607 ProcessExpressionType(exp);
11610 if(stmt.forStmt.stmt)
11611 ProcessStatement(stmt.forStmt.stmt);
11616 Identifier id = stmt.forEachStmt.id;
11617 OldList * exp = stmt.forEachStmt.exp;
11618 OldList * filter = stmt.forEachStmt.filter;
11619 Statement block = stmt.forEachStmt.stmt;
11620 char iteratorType[1024];
11623 bool isBuiltin = exp && exp->last &&
11624 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11625 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11626 Expression arrayExp;
11627 char * typeString = null;
11628 int builtinCount = 0;
11630 for(e = exp ? exp->first : null; e; e = e.next)
11634 FreeType(e.destType);
11635 e.destType = ProcessTypeString("Container", false);
11637 if(!isBuiltin || e.next)
11638 ProcessExpressionType(e);
11641 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11642 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11643 eClass_IsDerived(source._class.registered, containerClass)))
11645 Class _class = source ? source._class.registered : null;
11647 Expression expIt = null;
11648 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false, isAVLTree = false;
11649 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11650 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11651 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11652 stmt.type = compoundStmt;
11654 stmt.compound.context = Context { };
11655 stmt.compound.context.parent = curContext;
11656 curContext = stmt.compound.context;
11658 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11660 Class mapClass = eSystem_FindClass(privateModule, "Map");
11661 Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11662 isCustomAVLTree = true;
11663 if(eClass_IsDerived(source._class.registered, avlTreeClass))
11665 else if(eClass_IsDerived(source._class.registered, mapClass))
11668 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11669 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11671 Class listClass = eSystem_FindClass(privateModule, "List");
11673 isList = eClass_IsDerived(source._class.registered, listClass);
11679 OldList * specs = MkList();
11680 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11681 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11682 stmt.compound.declarations = MkListOne(
11683 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11684 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11685 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
11686 MkInitializerAssignment(MkExpBrackets(exp))))));
11691 char typeStringBuf[1024];
11693 // TODO: Merge this code?
11694 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
11695 if(((Expression)exp->last).type == castExp)
11697 TypeName typeName = ((Expression)exp->last).cast.typeName;
11699 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
11702 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
11703 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
11704 arrayExp.destType._class.registered.templateArgs)
11706 Class templateClass = arrayExp.destType._class.registered;
11707 typeString = templateClass.templateArgs[2].dataTypeString;
11709 else if(arrayExp.list)
11711 // Guess type from expressions in the array
11713 for(e = arrayExp.list->first; e; e = e.next)
11715 ProcessExpressionType(e);
11718 if(!type) { type = e.expType; type.refCount++; }
11721 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
11722 if(!MatchTypeExpression(e, type, null, false))
11728 e = arrayExp.list->first;
11729 ProcessExpressionType(e);
11732 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
11733 if(!MatchTypeExpression(e, type, null, false))
11735 FreeType(e.expType);
11746 FreeType(e.expType);
11753 typeStringBuf[0] = '\0';
11754 PrintType(type, typeStringBuf, false, true);
11755 typeString = typeStringBuf;
11761 OldList * initializers = MkList();
11763 OldList * specs = MkList();
11768 builtinCount = arrayExp.list->count;
11769 type = ProcessTypeString(typeString, false);
11770 while(e = arrayExp.list->first)
11772 arrayExp.list->Remove(e);
11775 ProcessExpressionType(e);
11776 ListAdd(initializers, MkInitializerAssignment(e));
11779 delete arrayExp.list;
11781 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
11782 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
11783 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
11785 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
11787 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
11788 ), MkInitializerList(initializers)))));
11789 FreeList(exp, FreeExpression);
11793 arrayExp.expType = ProcessTypeString("Container", false);
11794 Compiler_Error($"Couldn't determine type of array elements\n");
11799 OldList * specs = MkList();
11801 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
11802 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
11803 stmt.compound.declarations = MkListOne(
11804 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11805 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
11806 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
11807 MkInitializerAssignment(MkExpBrackets(exp))))));
11810 else if(isLinkList && !isList)
11813 OldList * specs = MkList();
11814 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11815 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11816 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11817 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
11818 MkInitializerAssignment(MkExpBrackets(exp))))));
11820 /*else if(isCustomAVLTree)
11823 OldList * specs = MkList();
11824 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
11825 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
11826 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
11827 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
11828 MkInitializerAssignment(MkExpBrackets(exp))))));
11830 else if(_class.templateArgs)
11833 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
11835 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
11837 stmt.compound.declarations = MkListOne(
11838 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
11839 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
11840 MkInitializerAssignment(MkExpBrackets(exp)))))))));
11842 symbol = FindSymbol(id.string, curContext, curContext, false, false);
11846 // Reparent sub-contexts in this statement
11850 if(block.compound.context)
11851 block.compound.context.parent = stmt.compound.context;
11854 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
11855 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
11856 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
11857 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
11860 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
11861 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
11864 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
11865 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
11868 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
11869 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
11872 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
11873 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
11876 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
11877 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
11879 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
11882 case expressionStmt:
11888 case badDeclarationStmt:
11889 case fireWatchersStmt:
11890 case stopWatchingStmt:
11897 block = MkIfStmt(filter, block, null);
11901 stmt.compound.statements = MkListOne(MkForStmt(
11902 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
11903 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11904 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11905 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11907 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11908 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11909 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11914 //OldList * specs = MkList();
11915 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11917 sprintf(count, "%d", builtinCount);
11919 stmt.compound.statements = MkListOne(MkForStmt(
11920 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
11921 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11922 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
11923 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11927 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
11928 stmt.compound.statements = MkListOne(MkForStmt(
11929 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
11930 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
11931 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
11932 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
11935 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11936 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11937 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11939 else if(isLinkList && !isList)
11941 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
11942 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
11943 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
11944 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
11946 stmt.compound.statements = MkListOne(MkForStmt(
11947 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11948 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11949 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11954 OldList * specs = MkList();
11955 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
11956 stmt.compound.statements = MkListOne(MkForStmt(
11957 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
11958 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11959 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
11960 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
11961 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
11964 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11965 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11966 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11968 /*else if(isCustomAVLTree)
11970 stmt.compound.statements = MkListOne(MkForStmt(
11971 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
11972 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
11973 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
11974 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
11977 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
11978 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
11979 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
11983 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
11984 MkIdentifier("Next")), null)), block));
11986 ProcessExpressionType(expIt);
11987 if(stmt.compound.declarations->first)
11988 ProcessDeclaration(stmt.compound.declarations->first);
11991 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
11993 ProcessStatement(stmt);
11994 curContext = stmt.compound.context.parent;
11999 Compiler_Error($"Expression is not a container\n");
12012 if(stmt.expressions)
12014 for(exp = stmt.expressions->first; exp; exp = exp.next)
12018 if(curFunction && !curFunction.type)
12019 curFunction.type = ProcessType(
12020 curFunction.specifiers, curFunction.declarator);
12021 FreeType(exp.destType);
12022 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12023 if(exp.destType) exp.destType.refCount++;
12025 ProcessExpressionType(exp);
12030 case badDeclarationStmt:
12032 ProcessDeclaration(stmt.decl);
12038 if(stmt.asmStmt.inputFields)
12040 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12041 if(field.expression)
12042 ProcessExpressionType(field.expression);
12044 if(stmt.asmStmt.outputFields)
12046 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12047 if(field.expression)
12048 ProcessExpressionType(field.expression);
12050 if(stmt.asmStmt.clobberedFields)
12052 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12054 if(field.expression)
12055 ProcessExpressionType(field.expression);
12062 PropertyWatch propWatch;
12063 OldList * watches = stmt._watch.watches;
12064 Expression object = stmt._watch.object;
12065 Expression watcher = stmt._watch.watcher;
12067 ProcessExpressionType(watcher);
12069 ProcessExpressionType(object);
12073 if(watcher || thisClass)
12075 External external = curExternal;
12076 Context context = curContext;
12078 stmt.type = expressionStmt;
12079 stmt.expressions = MkList();
12081 curExternal = external.prev;
12083 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12085 ClassFunction func;
12086 char watcherName[1024];
12087 Class watcherClass = watcher ?
12088 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12089 External createdExternal;
12091 // Create a declaration above
12092 External externalDecl = MkExternalDeclaration(null);
12093 ast->Insert(curExternal.prev, externalDecl);
12095 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12096 if(propWatch.deleteWatch)
12097 strcat(watcherName, "_delete");
12101 for(propID = propWatch.properties->first; propID; propID = propID.next)
12103 strcat(watcherName, "_");
12104 strcat(watcherName, propID.string);
12108 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12110 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
12111 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12112 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
12113 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12114 ProcessClassFunctionBody(func, propWatch.compound);
12115 propWatch.compound = null;
12117 //afterExternal = afterExternal ? afterExternal : curExternal;
12119 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
12120 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12122 createdExternal.symbol.idCode = external.symbol.idCode;
12124 curExternal = createdExternal;
12125 ProcessFunction(createdExternal.function);
12128 // Create a declaration above
12130 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
12131 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
12132 externalDecl.declaration = decl;
12133 if(decl.symbol && !decl.symbol.pointerExternal)
12134 decl.symbol.pointerExternal = externalDecl;
12137 if(propWatch.deleteWatch)
12139 OldList * args = MkList();
12140 ListAdd(args, CopyExpression(object));
12141 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12142 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12143 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12147 Class _class = object.expType._class.registered;
12150 for(propID = propWatch.properties->first; propID; propID = propID.next)
12152 char propName[1024];
12153 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12156 char getName[1024], setName[1024];
12157 OldList * args = MkList();
12159 DeclareProperty(prop, setName, getName);
12161 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12162 strcpy(propName, "__ecereProp_");
12163 FullClassNameCat(propName, prop._class.fullName, false);
12164 strcat(propName, "_");
12165 // strcat(propName, prop.name);
12166 FullClassNameCat(propName, prop.name, true);
12168 ListAdd(args, CopyExpression(object));
12169 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12170 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12171 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12173 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12176 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12181 Compiler_Error($"Invalid watched object\n");
12184 curExternal = external;
12185 curContext = context;
12188 FreeExpression(watcher);
12190 FreeExpression(object);
12191 FreeList(watches, FreePropertyWatch);
12194 Compiler_Error($"No observer specified and not inside a _class\n");
12198 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12200 ProcessStatement(propWatch.compound);
12206 case fireWatchersStmt:
12208 OldList * watches = stmt._watch.watches;
12209 Expression object = stmt._watch.object;
12211 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12212 // printf("%X\n", watches);
12213 // printf("%X\n", stmt._watch.watches);
12215 ProcessExpressionType(object);
12220 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12226 stmt.type = expressionStmt;
12227 stmt.expressions = MkList();
12229 // Check if we're inside a property set
12230 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12232 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12236 //Compiler_Error($"No property specified and not inside a property set\n");
12240 for(propID = watches->first; propID; propID = propID.next)
12242 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12245 CreateFireWatcher(prop, object, stmt);
12248 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12253 // Fire all properties!
12256 for(base = _class; base; base = base.base)
12258 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12260 if(prop.isProperty && prop.isWatchable)
12262 CreateFireWatcher(prop, object, stmt);
12269 FreeExpression(object);
12270 FreeList(watches, FreeIdentifier);
12273 Compiler_Error($"Invalid object specified and not inside a class\n");
12277 case stopWatchingStmt:
12279 OldList * watches = stmt._watch.watches;
12280 Expression object = stmt._watch.object;
12281 Expression watcher = stmt._watch.watcher;
12284 ProcessExpressionType(object);
12286 ProcessExpressionType(watcher);
12289 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12291 if(watcher || thisClass)
12297 stmt.type = expressionStmt;
12298 stmt.expressions = MkList();
12303 // eInstance_StopWatching(object, null, watcher);
12305 ListAdd(args, CopyExpression(object));
12306 ListAdd(args, MkExpConstant("0"));
12307 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12308 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12312 for(propID = watches->first; propID; propID = propID.next)
12314 char propName[1024];
12315 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12318 char getName[1024], setName[1024];
12319 OldList * args = MkList();
12321 DeclareProperty(prop, setName, getName);
12323 // eInstance_StopWatching(object, prop, watcher);
12324 strcpy(propName, "__ecereProp_");
12325 FullClassNameCat(propName, prop._class.fullName, false);
12326 strcat(propName, "_");
12327 // strcat(propName, prop.name);
12328 FullClassNameCat(propName, prop.name, true);
12329 MangleClassName(propName);
12331 ListAdd(args, CopyExpression(object));
12332 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12333 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12334 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12337 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12342 FreeExpression(object);
12344 FreeExpression(watcher);
12345 FreeList(watches, FreeIdentifier);
12348 Compiler_Error($"Invalid object specified and not inside a class\n");
12351 Compiler_Error($"No observer specified and not inside a class\n");
12358 static void ProcessFunction(FunctionDefinition function)
12360 Identifier id = GetDeclId(function.declarator);
12361 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12362 Type type = symbol ? symbol.type : null;
12363 Class oldThisClass = thisClass;
12364 Context oldTopContext = topContext;
12366 yylloc = function.loc;
12367 // Process thisClass
12369 if(type && type.thisClass)
12371 Symbol classSym = type.thisClass;
12372 Class _class = type.thisClass.registered;
12373 char className[1024];
12374 char structName[1024];
12375 Declarator funcDecl;
12378 bool typedObject = false;
12380 if(_class && !_class.base)
12382 _class = currentClass;
12383 if(_class && !_class.symbol)
12384 _class.symbol = FindClass(_class.fullName);
12385 classSym = _class ? _class.symbol : null;
12386 typedObject = true;
12389 thisClass = _class;
12391 if(inCompiler && _class)
12393 if(type.kind == functionType)
12395 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12397 //TypeName param = symbol.type.params.first;
12398 Type param = symbol.type.params.first;
12399 symbol.type.params.Remove(param);
12400 //FreeTypeName(param);
12403 if(type.classObjectType != classPointer)
12405 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12406 symbol.type.staticMethod = true;
12407 symbol.type.thisClass = null;
12409 // HIGH DANGER: VERIFYING THIS...
12410 symbol.type.extraParam = false;
12414 strcpy(className, "__ecereClass_");
12415 FullClassNameCat(className, _class.fullName, true);
12417 MangleClassName(className);
12420 FullClassNameCat(structName, _class.fullName, false);
12425 funcDecl = GetFuncDecl(function.declarator);
12428 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12430 TypeName param = funcDecl.function.parameters->first;
12431 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12433 funcDecl.function.parameters->Remove(param);
12434 FreeTypeName(param);
12438 // DANGER: Watch for this... Check if it's a Conversion?
12439 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12441 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12442 if(!function.propertyNoThis)
12444 TypeName thisParam;
12446 if(type.classObjectType != classPointer)
12448 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12449 if(!funcDecl.function.parameters)
12450 funcDecl.function.parameters = MkList();
12451 funcDecl.function.parameters->Insert(null, thisParam);
12456 if(type.classObjectType != classPointer)
12458 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12459 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12462 thisParam = TypeName
12464 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12465 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12467 funcDecl.function.parameters->Insert(null, thisParam);
12472 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12474 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12475 funcDecl = GetFuncDecl(initDecl.declarator);
12478 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12480 TypeName param = funcDecl.function.parameters->first;
12481 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12483 funcDecl.function.parameters->Remove(param);
12484 FreeTypeName(param);
12488 if(type.classObjectType != classPointer)
12490 // DANGER: Watch for this... Check if it's a Conversion?
12491 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12493 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12495 if(!funcDecl.function.parameters)
12496 funcDecl.function.parameters = MkList();
12497 funcDecl.function.parameters->Insert(null, thisParam);
12504 // Add this to the context
12507 if(type.classObjectType != classPointer)
12509 thisSymbol = Symbol
12511 string = CopyString("this");
12512 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12514 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12516 if(typedObject && thisSymbol.type)
12518 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12519 thisSymbol.type.byReference = type.byReference;
12520 thisSymbol.type.typedByReference = type.byReference;
12522 thisSymbol = Symbol { string = CopyString("class") };
12523 function.body.compound.context.symbols.Add(thisSymbol);
12529 // Pointer to class data
12531 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12533 DataMember member = null;
12536 for(base = _class; base && base.type != systemClass; base = base.next)
12538 for(member = base.membersAndProperties.first; member; member = member.next)
12539 if(!member.isProperty)
12545 for(member = _class.membersAndProperties.first; member; member = member.next)
12546 if(!member.isProperty)
12550 char pointerName[1024];
12553 Initializer initializer;
12554 Expression exp, bytePtr;
12556 strcpy(pointerName, "__ecerePointer_");
12557 FullClassNameCat(pointerName, _class.fullName, false);
12559 char className[1024];
12560 strcpy(className, "__ecereClass_");
12561 FullClassNameCat(className, classSym.string, true);
12562 MangleClassName(className);
12565 DeclareClass(classSym, className);
12569 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12574 sprintf(string, "%d", _class.offset);
12575 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12579 // ([bytePtr] + [className]->offset)
12580 exp = QBrackets(MkExpOp(bytePtr, '+',
12581 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12584 // (this ? [exp] : 0)
12585 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12589 kind = pointerType;
12590 type = Type { refCount = 1, kind = voidType };
12595 yylloc = function.body.loc;
12596 // ([structName] *) [exp]
12597 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12598 initializer = MkInitializerAssignment(
12599 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12601 // [structName] * [pointerName] = [initializer];
12602 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12605 Context prevContext = curContext;
12606 curContext = function.body.compound.context;
12608 decl = MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)),
12609 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12611 curContext = prevContext;
12615 decl.symbol = null;
12617 if(!function.body.compound.declarations)
12618 function.body.compound.declarations = MkList();
12619 function.body.compound.declarations->Insert(null, decl);
12625 // Loop through the function and replace undeclared identifiers
12626 // which are a member of the class (methods, properties or data)
12627 // by "this.[member]"
12634 FreeSpecifier(id._class);
12637 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12639 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12640 id = GetDeclId(initDecl.declarator);
12642 FreeSpecifier(id._class);
12647 topContext = function.body.compound.context;
12649 FunctionDefinition oldFunction = curFunction;
12650 curFunction = function;
12652 ProcessStatement(function.body);
12654 // If this is a property set and no firewatchers has been done yet, add one here
12655 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12657 Statement prevCompound = curCompound;
12658 Context prevContext = curContext;
12660 Statement fireWatchers = MkFireWatchersStmt(null, null);
12661 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12662 ListAdd(function.body.compound.statements, fireWatchers);
12664 curCompound = function.body;
12665 curContext = function.body.compound.context;
12667 ProcessStatement(fireWatchers);
12669 curContext = prevContext;
12670 curCompound = prevCompound;
12674 curFunction = oldFunction;
12677 if(function.declarator)
12679 ProcessDeclarator(function.declarator);
12682 topContext = oldTopContext;
12683 thisClass = oldThisClass;
12686 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
12687 static void ProcessClass(OldList definitions, Symbol symbol)
12690 External external = curExternal;
12691 Class regClass = symbol ? symbol.registered : null;
12693 // Process all functions
12694 for(def = definitions.first; def; def = def.next)
12696 if(def.type == functionClassDef)
12698 if(def.function.declarator)
12699 curExternal = def.function.declarator.symbol.pointerExternal;
12701 curExternal = external;
12703 ProcessFunction((FunctionDefinition)def.function);
12705 else if(def.type == declarationClassDef)
12707 if(def.decl.type == instDeclaration)
12709 thisClass = regClass;
12710 ProcessInstantiationType(def.decl.inst);
12716 Class backThisClass = thisClass;
12717 if(regClass) thisClass = regClass;
12718 ProcessDeclaration(def.decl);
12719 thisClass = backThisClass;
12722 else if(def.type == defaultPropertiesClassDef && def.defProperties)
12724 MemberInit defProperty;
12726 // Add this to the context
12727 Symbol thisSymbol = Symbol
12729 string = CopyString("this");
12730 type = regClass ? MkClassType(regClass.fullName) : null;
12732 globalContext.symbols.Add((BTNode)thisSymbol);
12734 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
12736 thisClass = regClass;
12737 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
12741 globalContext.symbols.Remove((BTNode)thisSymbol);
12742 FreeSymbol(thisSymbol);
12744 else if(def.type == propertyClassDef && def.propertyDef)
12746 PropertyDef prop = def.propertyDef;
12748 // Add this to the context
12750 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
12751 globalContext.symbols.Add(thisSymbol);
12754 thisClass = regClass;
12761 string = CopyString("this");
12762 type = MkClassType(regClass.fullName);
12764 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12767 curExternal = prop.symbol ? prop.symbol.externalSet : null;
12768 ProcessStatement(prop.setStmt);
12776 string = CopyString("this");
12777 type = MkClassType(regClass.fullName);
12779 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12782 curExternal = prop.symbol ? prop.symbol.externalGet : null;
12783 ProcessStatement(prop.getStmt);
12791 string = CopyString("this");
12792 type = MkClassType(regClass.fullName);
12794 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
12797 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
12798 ProcessStatement(prop.issetStmt);
12804 globalContext.symbols.Remove(thisSymbol);
12805 FreeSymbol(thisSymbol);
12808 else if(def.type == propertyWatchClassDef && def.propertyWatch)
12810 PropertyWatch propertyWatch = def.propertyWatch;
12812 thisClass = regClass;
12813 if(propertyWatch.compound)
12817 string = CopyString("this");
12818 type = regClass ? MkClassType(regClass.fullName) : null;
12821 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
12823 curExternal = null;
12824 ProcessStatement(propertyWatch.compound);
12831 void DeclareFunctionUtil(String s)
12833 GlobalFunction function = eSystem_FindFunction(privateModule, s);
12838 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
12839 strcpy(name, "__ecereFunction_");
12840 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
12841 DeclareFunction(function, name);
12845 void ComputeDataTypes()
12849 External after = null;
12851 currentClass = null;
12853 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
12855 for(external = ast->first; external; external = external.next)
12857 if(external.type == declarationExternal)
12859 Declaration decl = external.declaration;
12862 OldList * decls = decl.declarators;
12865 InitDeclarator initDecl = decls->first;
12868 Declarator declarator = initDecl.declarator;
12869 if(declarator && declarator.type == identifierDeclarator)
12871 Identifier id = declarator.identifier;
12872 if(id && id.string)
12874 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
12876 external.symbol.id = -1001, external.symbol.idCode = -1001;
12887 temp.symbol = Symbol { id = -1000, idCode = -1000 };
12888 ast->Insert(after, temp);
12889 curExternal = temp;
12891 DeclareFunctionUtil("eSystem_New");
12892 DeclareFunctionUtil("eSystem_New0");
12893 DeclareFunctionUtil("eSystem_Renew");
12894 DeclareFunctionUtil("eSystem_Renew0");
12895 DeclareFunctionUtil("eSystem_Delete");
12896 DeclareFunctionUtil("eClass_GetProperty");
12897 DeclareFunctionUtil("eInstance_FireSelfWatchers");
12899 DeclareStruct("ecere::com::Class", false);
12900 DeclareStruct("ecere::com::Instance", false);
12901 DeclareStruct("ecere::com::Property", false);
12902 DeclareStruct("ecere::com::DataMember", false);
12903 DeclareStruct("ecere::com::Method", false);
12904 DeclareStruct("ecere::com::SerialBuffer", false);
12905 DeclareStruct("ecere::com::ClassTemplateArgument", false);
12909 for(external = ast->first; external; external = external.next)
12911 afterExternal = curExternal = external;
12912 if(external.type == functionExternal)
12914 currentClass = external.function._class;
12915 ProcessFunction(external.function);
12917 // There shouldn't be any _class member access here anyways...
12918 else if(external.type == declarationExternal)
12920 currentClass = null;
12921 if(external.declaration)
12922 ProcessDeclaration(external.declaration);
12924 else if(external.type == classExternal)
12926 ClassDefinition _class = external._class;
12927 currentClass = external.symbol.registered;
12928 if(_class.definitions)
12930 ProcessClass(_class.definitions, _class.symbol);
12934 // Free class data...
12935 ast->Remove(external);
12939 else if(external.type == nameSpaceExternal)
12941 thisNameSpace = external.id.string;
12944 currentClass = null;
12945 thisNameSpace = null;
12946 curExternal = null;
12948 delete temp.symbol;