3 // UNTIL IMPLEMENTED IN GRAMMAR
4 #define ACCESS_CLASSDATA(_class, baseClass) \
5 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
7 #define YYLTYPE Location
11 extern int returnCode;
12 extern Expression parsedExpression;
14 public void SetYydebug(bool b) { yydebug = b; }
19 // TODO: Reset this to 0 on reinitialization
22 int expression_yyparse();
23 static Statement curCompound;
24 External curExternal, afterExternal;
25 static Type curSwitchType;
26 static Class currentClass;
28 public void SetThisClass(Class c) { thisClass = c; } public Class GetThisClass() { return thisClass; }
29 static char * thisNameSpace;
30 /*static */Class containerClass;
31 bool thisClassParams = true;
33 uint internalValueCounter;
36 Time findSymbolTotalTime;
39 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
40 /*static */public void PrintExpression(Expression exp, char * string)
46 bool backOutputLineNumbers = outputLineNumbers;
47 outputLineNumbers = false;
50 OutputExpression(exp, f);
52 count = strlen(string);
53 count += f.Read(string + count, 1, 1023);
57 outputLineNumbers = backOutputLineNumbers;
61 Type ProcessTemplateParameterType(TemplateParameter param)
63 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
65 // TOFIX: Will need to free this Type
68 if(param.dataTypeString)
69 param.baseType = ProcessTypeString(param.dataTypeString, false);
71 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
73 return param.baseType;
78 bool NeedCast(Type type1, Type type2)
80 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
82 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
87 if(type1.kind == type2.kind)
98 if(type1.passAsTemplate && !type2.passAsTemplate)
100 return type1.isSigned != type2.isSigned;
102 return type1._class != type2._class;
104 return (type1.type && type2.type && type1.type.constant != type2.type.constant) || NeedCast(type1.type, type2.type);
106 return true; //false; ????
112 static void ReplaceClassMembers(Expression exp, Class _class)
114 if(exp.type == identifierExp && exp.identifier)
116 Identifier id = exp.identifier;
118 Symbol symbol = null;
119 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
121 // First, check if the identifier is declared inside the function
122 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
124 symbol = (Symbol)ctx.symbols.FindString(id.string);
129 // If it is not, check if it is a member of the _class
130 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
132 Property prop = eClass_FindProperty(_class, id.string, privateModule);
133 Method method = null;
134 DataMember member = null;
135 ClassProperty classProp = null;
138 method = eClass_FindMethod(_class, id.string, privateModule);
141 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
142 if(!prop && !method && !member)
144 classProp = eClass_FindClassProperty(_class, id.string);
146 if(prop || method || member || classProp)
148 // Replace by this.[member]
149 exp.type = memberExp;
150 exp.member.member = id;
151 exp.member.memberType = unresolvedMember;
152 exp.member.exp = QMkExpId("this");
153 //exp.member.exp.loc = exp.loc;
154 exp.addedThis = true;
156 else if(_class && _class.templateParams.first)
159 for(sClass = _class; sClass; sClass = sClass.base)
161 if(sClass.templateParams.first)
163 ClassTemplateParameter param;
164 for(param = sClass.templateParams.first; param; param = param.next)
166 if(param.type == expression && !strcmp(param.name, id.string))
168 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
173 OldList * specs = MkList();
175 FreeIdentifier(exp.member.member);
177 ProcessExpressionType(argExp);
179 decl = SpecDeclFromString(param.dataTypeString, specs, null);
181 exp.expType = ProcessType(specs, decl);
183 // *[expType] *[argExp]
184 exp.type = bracketsExp;
185 exp.list = MkListOne(MkExpOp(null, '*',
186 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
197 ////////////////////////////////////////////////////////////////////////
198 // PRINTING ////////////////////////////////////////////////////////////
199 ////////////////////////////////////////////////////////////////////////
201 public char * PrintInt(int64 result)
205 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
207 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
208 if(result > MAXINT || result < MININT)
210 return CopyString(temp);
213 public char * PrintUInt(uint64 result)
216 if(result > MAXDWORD)
217 sprintf(temp, FORMAT64HEXLL /*"0x%I64X"*/, result);
218 else if(result > MAXINT)
219 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
221 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
222 return CopyString(temp);
225 public char * PrintInt64(int64 result)
228 if(result > MAXINT || result < MININT)
229 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
231 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
232 return CopyString(temp);
235 public char * PrintUInt64(uint64 result)
238 if(result > MAXDWORD)
239 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
240 else if(result > MAXINT)
241 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
243 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
244 return CopyString(temp);
247 public char * PrintHexUInt(uint64 result)
250 if(result > MAXDWORD)
251 sprintf(temp, FORMAT64HEX /*"0x%I64xLL"*/, result);
253 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
254 if(result > MAXDWORD)
256 return CopyString(temp);
259 public char * PrintHexUInt64(uint64 result)
262 if(result > MAXDWORD)
263 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
265 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
266 return CopyString(temp);
269 public char * PrintShort(short result)
272 sprintf(temp, "%d", (unsigned short)result);
273 return CopyString(temp);
276 public char * PrintUShort(unsigned short result)
280 sprintf(temp, "0x%X", (int)result);
282 sprintf(temp, "%d", (int)result);
283 return CopyString(temp);
286 public char * PrintChar(char result)
289 if(result > 0 && isprint(result))
290 sprintf(temp, "'%c'", result);
292 sprintf(temp, "%d", (int)result);
294 //sprintf(temp, "%#X", result);
295 sprintf(temp, "0x%X", (unsigned char)result);
296 return CopyString(temp);
299 public char * PrintUChar(unsigned char result)
302 sprintf(temp, "0x%X", result);
303 return CopyString(temp);
306 public char * PrintFloat(float result)
312 strcpy(temp, "-inf");
316 else if(result.isNan)
319 strcpy(temp, "-nan");
324 sprintf(temp, "%.16ff", result);
325 return CopyString(temp);
328 public char * PrintDouble(double result)
334 strcpy(temp, "-inf");
338 else if(result.isNan)
341 strcpy(temp, "-nan");
346 sprintf(temp, "%.16f", result);
347 return CopyString(temp);
350 ////////////////////////////////////////////////////////////////////////
351 ////////////////////////////////////////////////////////////////////////
353 //public Operand GetOperand(Expression exp);
355 #define GETVALUE(name, t) \
356 public bool GetOp##name(Operand op2, t * value2) \
358 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
359 else if(op2.kind == intType) *value2 = (t) op2.ui; \
360 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
361 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
362 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
363 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
364 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
365 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
366 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
367 else if(op2.kind == shortType) *value2 = (t) op2.us; \
368 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
369 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
370 else if(op2.kind == floatType) *value2 = (t) op2.f; \
371 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
372 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
377 public bool Get##name(Expression exp, t * value2) \
379 Operand op2 = GetOperand(exp); \
380 return GetOp##name(op2, value2); \
383 // To help the debugger currently not preprocessing...
386 GETVALUE(Int, HELP(int));
387 GETVALUE(UInt, HELP(unsigned int));
388 GETVALUE(Int64, HELP(int64));
389 GETVALUE(UInt64, HELP(uint64));
390 GETVALUE(IntPtr, HELP(intptr));
391 GETVALUE(UIntPtr, HELP(uintptr));
392 GETVALUE(IntSize, HELP(intsize));
393 GETVALUE(UIntSize, HELP(uintsize));
394 GETVALUE(Short, HELP(short));
395 GETVALUE(UShort, HELP(unsigned short));
396 GETVALUE(Char, HELP(char));
397 GETVALUE(UChar, HELP(unsigned char));
398 GETVALUE(Float, HELP(float));
399 GETVALUE(Double, HELP(double));
401 void ComputeExpression(Expression exp);
403 void ComputeClassMembers(Class _class, bool isMember)
405 DataMember member = isMember ? (DataMember) _class : null;
406 Context context = isMember ? null : SetupTemplatesContext(_class);
407 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
408 (_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; type.pointerAlignment = true; break;
735 case intSizeType: type.alignment = size = targetBits / 8; type.pointerAlignment = true; 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 type.pointerAlignment = (bool)_class.pointerAlignment;
750 size = _class.structSize;
751 if(type.alignment && size % type.alignment)
752 size += type.alignment - (size % type.alignment);
755 else if(_class && (_class.type == unitClass ||
756 _class.type == enumClass ||
757 _class.type == bitClass))
760 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
761 size = type.alignment = ComputeTypeSize(_class.dataType);
765 size = type.alignment = targetBits / 8; // sizeof(Instance *);
766 type.pointerAlignment = true;
770 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */ type.pointerAlignment = true; break;
772 if(type.arraySizeExp)
774 ProcessExpressionType(type.arraySizeExp);
775 ComputeExpression(type.arraySizeExp);
776 if(!type.arraySizeExp.isConstant || (type.arraySizeExp.expType.kind != intType &&
777 type.arraySizeExp.expType.kind != shortType &&
778 type.arraySizeExp.expType.kind != charType &&
779 type.arraySizeExp.expType.kind != longType &&
780 type.arraySizeExp.expType.kind != int64Type &&
781 type.arraySizeExp.expType.kind != intSizeType &&
782 type.arraySizeExp.expType.kind != intPtrType &&
783 type.arraySizeExp.expType.kind != enumType &&
784 (type.arraySizeExp.expType.kind != classType || !type.arraySizeExp.expType._class.registered || type.arraySizeExp.expType._class.registered.type != enumClass)))
786 Location oldLoc = yylloc;
787 // bool isConstant = type.arraySizeExp.isConstant;
788 char expression[10240];
789 expression[0] = '\0';
790 type.arraySizeExp.expType = null;
791 yylloc = type.arraySizeExp.loc;
793 PrintExpression(type.arraySizeExp, expression);
794 Compiler_Error($"Array size not constant int (%s)\n", expression);
797 GetInt(type.arraySizeExp, &type.arraySize);
799 else if(type.enumClass)
801 if(type.enumClass && type.enumClass.registered && type.enumClass.registered.type == enumClass)
803 type.arraySize = (int)eClass_GetProperty(type.enumClass.registered, "enumSize");
810 // Unimplemented auto size
814 size = ComputeTypeSize(type.type) * type.arraySize;
817 type.alignment = type.type.alignment;
818 type.pointerAlignment = type.type.pointerAlignment;
824 if(!type.members.first && type.enumName)
826 Symbol symbol = FindStruct(curContext, type.enumName);
827 if(symbol && symbol.type)
829 ComputeTypeSize(symbol.type);
830 size = symbol.type.size;
836 for(member = type.members.first; member; member = member.next)
838 uint addSize = ComputeTypeSize(member);
840 member.offset = size;
841 if(member.alignment && size % member.alignment)
842 member.offset += member.alignment - (size % member.alignment);
843 size = member.offset;
845 if(member.pointerAlignment && type.size <= 4)
846 type.pointerAlignment = true;
847 else if(!member.pointerAlignment && member.alignment >= 8)
848 type.pointerAlignment = false;
850 type.alignment = Max(type.alignment, member.alignment);
853 if(type.alignment && size % type.alignment)
854 size += type.alignment - (size % type.alignment);
860 if(!type.members.first && type.enumName)
862 Symbol symbol = FindStruct(curContext, type.enumName);
863 if(symbol && symbol.type)
865 ComputeTypeSize(symbol.type);
866 size = symbol.type.size;
867 type.alignment = symbol.type.alignment;
873 for(member = type.members.first; member; member = member.next)
875 uint addSize = ComputeTypeSize(member);
877 member.offset = size;
878 if(member.alignment && size % member.alignment)
879 member.offset += member.alignment - (size % member.alignment);
880 size = member.offset;
882 if(member.pointerAlignment && type.size <= 4)
883 type.pointerAlignment = true;
884 else if(!member.pointerAlignment && member.alignment >= 8)
885 type.pointerAlignment = false;
887 type.alignment = Max(type.alignment, member.alignment);
889 size = Max(size, addSize);
891 if(type.alignment && size % type.alignment)
892 size += type.alignment - (size % type.alignment);
898 TemplateParameter param = type.templateParameter;
899 Type baseType = ProcessTemplateParameterType(param);
902 size = ComputeTypeSize(baseType);
903 type.alignment = baseType.alignment;
904 type.pointerAlignment = baseType.pointerAlignment;
907 type.alignment = size = sizeof(uint64);
912 type.alignment = size = sizeof(enum { test });
917 type.alignment = size = targetBits / 8; //sizeof(void *);
918 type.pointerAlignment = true;
923 type.computing = false;
929 /*static */int AddMembers(External neededBy, OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
931 // This function is in need of a major review when implementing private members etc.
932 DataMember topMember = isMember ? (DataMember) _class : null;
939 Context context = isMember ? null : SetupTemplatesContext(_class);
941 *addedPadding = false;
943 if(!isMember && _class.base)
945 maxSize = _class.structSize;
946 //if(_class.base.type != systemClass) // Commented out with new Instance _class
948 // DANGER: Testing this noHeadClass here...
949 if(_class.type == structClass || _class.type == noHeadClass)
950 /*totalSize = */AddMembers(neededBy, declarations, _class.base, false, &totalSize, topClass, null);
953 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
954 if(maxSize > baseSize)
962 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
964 if(!member.isProperty)
970 if(member.dataTypeString)
972 OldList * specs = MkList(), * decls = MkList();
975 decl = SpecDeclFromString(member.dataTypeString, specs,
976 MkDeclaratorIdentifier(MkIdentifier(member.name)));
977 ListAdd(decls, MkStructDeclarator(decl, null));
978 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
981 member.dataType = ProcessType(specs, decl);
983 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
986 Type type = ProcessType(specs, decl);
987 DeclareType(neededBy, member.dataType, true, false);
991 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
992 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
993 DeclareStruct(member.dataType._class.string, false);
996 ComputeTypeSize(member.dataType);
997 size = member.dataType.size;
998 alignment = member.dataType.alignment;
1002 if(totalSize % alignment)
1003 totalSize += alignment - (totalSize % alignment);
1012 OldList * specs = MkList(), * list = MkList();
1014 sprintf(id, "__anon%d", anonID++);
1017 AddMembers(neededBy, list, (Class)member, true, &size, topClass, null);
1019 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
1020 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, MkListOne(MkDeclaratorIdentifier(MkIdentifier(id))),null)));
1021 alignment = member.structAlignment;
1025 if(totalSize % alignment)
1026 totalSize += alignment - (totalSize % alignment);
1036 if(topMember && topMember.type == unionMember)
1037 *retSize = Max(*retSize, totalSize);
1039 *retSize += totalSize;
1041 else if(totalSize < maxSize && _class.type != systemClass)
1043 int autoPadding = 0;
1044 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
1045 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
1046 if(totalSize + autoPadding < maxSize)
1048 char sizeString[50];
1049 sprintf(sizeString, "%d", maxSize - totalSize);
1050 ListAdd(declarations,
1051 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1052 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1054 *addedPadding = true;
1058 FinishTemplatesContext(context);
1059 return topMember ? topMember.memberID : _class.memberID;
1062 static int DeclareMembers(External neededBy, Class _class, bool isMember)
1064 DataMember topMember = isMember ? (DataMember) _class : null;
1066 Context context = isMember ? null : SetupTemplatesContext(_class);
1068 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1069 DeclareMembers(neededBy, _class.base, false);
1071 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1073 if(!member.isProperty)
1079 if(!member.dataType && member.dataTypeString)
1080 member.dataType = ProcessTypeString(member.dataTypeString, false);
1082 DeclareType(neededBy, member.dataType, true, false);
1088 DeclareMembers(neededBy, (Class)member, true);
1095 FinishTemplatesContext(context);
1097 return topMember ? topMember.memberID : _class.memberID;
1100 static void IdentifyAnonStructs(OldList/*<ClassDef>*/ * definitions)
1104 for(def = definitions->first; def; def = def.next)
1106 if(def.type == declarationClassDef)
1108 Declaration decl = def.decl;
1109 if(decl && decl.specifiers)
1112 bool isStruct = false;
1113 for(spec = decl.specifiers->first; spec; spec = spec.next)
1115 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1117 if(spec.definitions)
1118 IdentifyAnonStructs(spec.definitions);
1124 Declarator d = null;
1125 if(decl.declarators)
1127 for(d = decl.declarators->first; d; d = d.next)
1129 Identifier idDecl = GetDeclId(d);
1137 sprintf(id, "__anon%d", anonID++);
1138 if(!decl.declarators)
1139 decl.declarators = MkList();
1140 ListAdd(decl.declarators, MkDeclaratorIdentifier(MkIdentifier(id)));
1148 External DeclareStruct(External neededBy, const char * name, bool skipNoHead, bool needDereference)
1150 return _DeclareStruct(neededBy, name, skipNoHead, needDereference, false);
1153 External _DeclareStruct(External neededBy, const char * name, bool skipNoHead, bool needDereference, bool fwdDecl)
1155 External external = null;
1156 Symbol classSym = FindClass(name);
1157 OldList * curDeclarations = null;
1158 Specifier curSpec = null;
1160 if(!inCompiler || !classSym) return null;
1162 // We don't need any declaration for bit classes...
1163 if(classSym.registered &&
1164 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1167 if(!classSym.registered || (classSym.registered.type == normalClass && classSym.registered.structSize && classSym.registered.base && classSym.registered.base.base))
1168 _DeclareStruct(neededBy, "ecere::com::Instance", false, true, fwdDecl);
1170 external = classSym.structExternal;
1172 if(external && external.declaration)
1175 for(spec = external.declaration.specifiers ? external.declaration.specifiers->first : null; spec; spec = spec.next)
1176 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1179 curDeclarations = spec.definitions;
1184 if(classSym.registered && !classSym.declaring && classSym.imported && (!classSym.declaredStructSym || (classSym.registered.type == noHeadClass && !skipNoHead && external && !curDeclarations)))
1186 OldList * specifiers, * declarators;
1187 OldList * declarations = null;
1188 char structName[1024];
1189 bool addedPadding = false;
1191 classSym.declaring++;
1193 if(strchr(classSym.string, '<'))
1195 if(classSym.registered.templateClass)
1197 external = _DeclareStruct(neededBy, classSym.registered.templateClass.fullName, skipNoHead, needDereference, fwdDecl);
1198 classSym.declaring--;
1204 FullClassNameCat(structName, name, false);
1206 classSym.declaredStructSym = true;
1207 if(!external || (classSym.registered.type == noHeadClass && !skipNoHead && !curDeclarations))
1212 external = MkExternalDeclaration(null);
1213 classSym.structExternal = external;
1214 external.symbol = classSym;
1221 declarations = MkList();
1222 AddMembers(external, declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1225 if(declarations && (!declarations->count || (declarations->count == 1 && addedPadding)))
1227 FreeList(declarations, FreeClassDef);
1228 declarations = null;
1231 if(classSym.registered.type != noHeadClass && !declarations)
1233 FreeExternal(external);
1235 classSym.structExternal = null;
1240 curSpec.definitions = declarations;
1243 char className[1024];
1244 strcpy(className, "__ecereClass_");
1245 FullClassNameCat(className, classSym.string, true);
1247 specifiers = MkList();
1248 declarators = MkList();
1249 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1250 external.declaration = MkDeclaration(specifiers, declarators);
1256 classSym.declaring--;
1258 else if(!classSym.declaredStructSym && classSym.structExternal)
1260 classSym.declaredStructSym = true;
1262 if(classSym.registered)
1263 DeclareMembers(classSym.structExternal, classSym.registered, false);
1265 if(classSym.structExternal.declaration && classSym.structExternal.declaration.specifiers)
1268 for(spec = classSym.structExternal.declaration.specifiers->first; spec; spec = spec.next)
1270 if(spec.definitions)
1271 IdentifyAnonStructs(spec.definitions);
1275 if(inCompiler && neededBy && (external || !classSym.imported))
1279 classSym.structExternal = external = MkExternalDeclaration(null);
1280 external.symbol = classSym;
1285 External e = external.fwdDecl ? external.fwdDecl : external;
1286 if(e.incoming.count)
1287 neededBy.CreateUniqueEdge(e, !needDereference && !external.fwdDecl);
1290 neededBy.CreateUniqueEdge(external, !needDereference);
1295 void DeclareProperty(External neededBy, Property prop, char * setName, char * getName)
1297 Symbol symbol = prop.symbol;
1298 bool imported = false;
1299 bool dllImport = false;
1300 External structExternal = null;
1301 External instExternal = null;
1303 strcpy(setName, "__ecereProp_");
1304 FullClassNameCat(setName, prop._class.fullName, false);
1305 strcat(setName, "_Set_");
1306 FullClassNameCat(setName, prop.name, true);
1308 strcpy(getName, "__ecereProp_");
1309 FullClassNameCat(getName, prop._class.fullName, false);
1310 strcat(getName, "_Get_");
1311 FullClassNameCat(getName, prop.name, true);
1313 if(!symbol || symbol._import)
1319 if(!prop._class.symbol)
1320 prop._class.symbol = FindClass(prop._class.fullName);
1321 classSym = prop._class.symbol;
1322 if(classSym && !classSym._import)
1324 ModuleImport module;
1326 if(prop._class.module)
1327 module = FindModule(prop._class.module);
1329 module = mainModule;
1331 classSym._import = ClassImport
1333 name = CopyString(prop._class.fullName);
1334 isRemote = prop._class.isRemote;
1336 module.classes.Add(classSym._import);
1338 symbol = prop.symbol = Symbol { };
1339 symbol._import = (ClassImport)PropertyImport
1341 name = CopyString(prop.name);
1342 isVirtual = false; //prop.isVirtual;
1343 hasSet = prop.Set ? true : false;
1344 hasGet = prop.Get ? true : false;
1347 classSym._import.properties.Add(symbol._import);
1350 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1351 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1352 prop._class.module.importType != staticImport)
1358 Context context = SetupTemplatesContext(prop._class);
1359 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1360 FinishTemplatesContext(context);
1363 if((prop.Get && !symbol.externalGet) || (prop.Set && !symbol.externalSet))
1365 if(prop._class.type == normalClass && prop._class.structSize)
1366 instExternal = DeclareStruct(null, "ecere::com::Instance", false, true);
1367 structExternal = DeclareStruct(null, prop._class.fullName, prop._class.type != structClass /*true*/, false);
1371 if(prop.Get && !symbol.externalGet)
1374 OldList * specifiers, * declarators;
1377 Specifier spec = null;
1379 Declarator typeDecl;
1380 bool simple = false;
1383 specifiers = MkList();
1384 declarators = MkList();
1387 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName(prop._class.fullName)),
1388 MkDeclaratorIdentifier(MkIdentifier("this"))));
1390 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1393 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1396 Context context = SetupTemplatesContext(prop._class);
1397 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1398 FinishTemplatesContext(context);
1401 // Make sure the simple _class's type is declared
1402 needReference = !typeDecl || typeDecl.type == identifierDeclarator;
1403 for(spec = specifiers->first; spec; spec = spec.next)
1405 if(spec.type == nameSpecifier)
1407 Symbol classSym = spec.symbol;
1410 symbol._class = classSym.registered;
1411 if(classSym.registered && classSym.registered.type == structClass)
1419 d = PlugDeclarator(typeDecl, d);
1422 ListAdd(params, MkTypeName(specifiers,
1423 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1424 specifiers = MkList();
1427 d = MkDeclaratorFunction(d, params);
1431 specifiers->Insert(null, MkSpecifier(EXTERN));
1432 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1433 specifiers->Insert(null, MkSpecifier(STATIC));
1435 ListAdd(specifiers, MkSpecifier(VOID));
1437 ListAdd(declarators, MkInitDeclarator(d, null));
1439 decl = MkDeclaration(specifiers, declarators);
1441 external = MkExternalDeclaration(decl);
1444 external.CreateEdge(structExternal, false);
1446 external.CreateEdge(instExternal, false);
1449 DeclareStruct(external, spec.name, false, needReference);
1452 external.symbol = symbol;
1453 symbol.externalGet = external;
1455 ReplaceThisClassSpecifiers(specifiers, prop._class);
1458 FreeDeclarator(typeDecl);
1462 if(prop.Set && !symbol.externalSet)
1465 OldList * specifiers, * declarators;
1468 Specifier spec = null;
1470 Declarator typeDecl;
1473 declarators = MkList();
1476 if(!prop.conversion || prop._class.type == structClass)
1478 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName(prop._class.fullName)),
1479 MkDeclaratorIdentifier(MkIdentifier("this"))));
1482 specifiers = MkList();
1485 Context context = SetupTemplatesContext(prop._class);
1486 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1487 MkDeclaratorIdentifier(MkIdentifier("value")));
1488 FinishTemplatesContext(context);
1490 if(!strcmp(prop._class.base.fullName, "eda::Row") || !strcmp(prop._class.base.fullName, "eda::Id"))
1491 specifiers->Insert(null, MkSpecifier(CONST));
1493 ListAdd(params, MkTypeName(specifiers, d));
1495 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1497 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1498 d = MkDeclaratorFunction(d, params);
1500 // Make sure the simple _class's type is declared
1501 needReference = !typeDecl || typeDecl.type == identifierDeclarator;
1502 for(spec = specifiers->first; spec; spec = spec.next)
1504 if(spec.type == nameSpecifier)
1506 Symbol classSym = spec.symbol;
1508 symbol._class = classSym.registered;
1513 ListAdd(declarators, MkInitDeclarator(d, null));
1515 specifiers = MkList();
1517 specifiers->Insert(null, MkSpecifier(EXTERN));
1518 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1519 specifiers->Insert(null, MkSpecifier(STATIC));
1521 if(!prop.conversion || prop._class.type == structClass)
1522 ListAdd(specifiers, MkSpecifier(VOID));
1524 ListAdd(specifiers, MkSpecifierName(prop._class.fullName));
1526 decl = MkDeclaration(specifiers, declarators);
1528 external = MkExternalDeclaration(decl);
1531 external.CreateEdge(structExternal, false);
1533 external.CreateEdge(instExternal, false);
1536 DeclareStruct(external, spec.name, false, needReference);
1539 external.symbol = symbol;
1540 symbol.externalSet = external;
1542 ReplaceThisClassSpecifiers(specifiers, prop._class);
1545 // Property (for Watchers)
1546 if(!symbol.externalPtr)
1550 OldList * specifiers = MkList();
1551 char propName[1024];
1554 specifiers->Insert(null, MkSpecifier(EXTERN));
1557 specifiers->Insert(null, MkSpecifier(STATIC));
1558 specifiers->Add(MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
1561 ListAdd(specifiers, MkSpecifierName("Property"));
1563 strcpy(propName, "__ecereProp_");
1564 FullClassNameCat(propName, prop._class.fullName, false);
1565 strcat(propName, "_");
1566 FullClassNameCat(propName, prop.name, true);
1569 OldList * list = MkList();
1570 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1574 strcpy(propName, "__ecerePropM_");
1575 FullClassNameCat(propName, prop._class.fullName, false);
1576 strcat(propName, "_");
1577 FullClassNameCat(propName, prop.name, true);
1579 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1581 decl = MkDeclaration(specifiers, list);
1584 external = MkExternalDeclaration(decl);
1585 ast->Insert(curExternal.prev, external);
1586 external.symbol = symbol;
1587 symbol.externalPtr = external;
1590 if(inCompiler && neededBy)
1592 // Could improve this to create edge on only what is needed...
1593 if(symbol.externalPtr)
1594 neededBy.CreateUniqueEdge(symbol.externalPtr, false);
1596 if(symbol.externalGet)
1597 neededBy.CreateUniqueEdge(symbol.externalGet, symbol.externalGet.type == functionExternal);
1599 if(symbol.externalSet)
1600 neededBy.CreateUniqueEdge(symbol.externalSet, symbol.externalSet.type == functionExternal);
1606 // ***************** EXPRESSION PROCESSING ***************************
1607 public Type Dereference(Type source)
1612 if(source.kind == pointerType || source.kind == arrayType)
1615 source.type.refCount++;
1617 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1625 // Support dereferencing of no head classes for now...
1626 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1632 Compiler_Error($"cannot dereference type\n");
1637 static Type Reference(Type source)
1653 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1655 Identifier ident = member.identifiers ? member.identifiers->first : null;
1657 DataMember dataMember = null;
1658 Method method = null;
1659 bool freeType = false;
1661 yylloc = member.loc;
1667 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1671 dataMember = *curMember;
1677 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1678 DataMember _subMemberStack[256];
1679 int _subMemberStackPos = 0;
1681 // FILL MEMBER STACK
1683 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1686 dataMember = thisMember;
1687 if(curMember && thisMember.memberAccess == publicAccess)
1689 *curMember = thisMember;
1690 *curClass = thisMember._class;
1691 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1692 *subMemberStackPos = _subMemberStackPos;
1699 method = eClass_FindMethod(_class, ident.string, privateModule);
1700 if(method && method.type == virtualMethod)
1712 if(!dataMember.dataType && dataMember.dataTypeString)
1714 //Context context = SetupTemplatesContext(dataMember._class);
1715 Context context = SetupTemplatesContext(_class);
1716 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1717 FinishTemplatesContext(context);
1719 type = dataMember.dataType;
1723 // This is for destination type...
1724 if(!method.dataType)
1725 ProcessMethodType(method);
1726 //DeclareMethod(method);
1727 // method.dataType = ((Symbol)method.symbol)->type;
1728 type = method.dataType;
1731 if(ident && ident.next)
1733 for(ident = ident.next; ident && type; ident = ident.next)
1735 if(type.kind == classType)
1737 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1739 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1741 type = dataMember.dataType;
1743 else if(type.kind == structType || type.kind == unionType)
1746 for(memberType = type.members.first; memberType; memberType = memberType.next)
1748 if(!strcmp(memberType.name, ident.string))
1758 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1759 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1762 ClassTemplateParameter curParam = null;
1764 for(sClass = _class; sClass; sClass = sClass.base)
1767 if(sClass.templateClass) sClass = sClass.templateClass;
1768 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1770 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1772 for(sClass = sClass.base; sClass; sClass = sClass.base)
1774 if(sClass.templateClass) sClass = sClass.templateClass;
1775 id += sClass.templateParams.count;
1786 ClassTemplateArgument arg = _class.templateArgs[id];
1787 if(arg.dataTypeString)
1789 bool constant = type.constant;
1791 type = ProcessTypeString(arg.dataTypeString, false);
1792 if(type.kind == classType && constant) type.constant = true;
1793 else if(type.kind == pointerType)
1796 while(t.kind == pointerType) t = t.type;
1797 if(constant) t.constant = constant;
1800 if(type && _class.templateClass)
1801 type.passAsTemplate = true;
1807 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1808 exp.destType.refCount++;
1814 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1816 Class expClass = type._class.registered;
1817 Class cClass = null;
1821 char templateString[1024];
1822 ClassTemplateParameter param;
1823 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1824 for(cClass = expClass; cClass; cClass = cClass.base)
1827 if(cClass.templateClass) cClass = cClass.templateClass;
1828 for(param = cClass.templateParams.first; param; param = param.next)
1832 ClassTemplateArgument arg;
1833 for(sClass = cClass.base; sClass; sClass = sClass.base)
1835 if(sClass.templateClass) sClass = sClass.templateClass;
1836 id += sClass.templateParams.count;
1838 arg = expClass.templateArgs[id];
1840 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1842 ClassTemplateParameter cParam;
1843 //int p = numParams - sClass.templateParams.count;
1846 if(sClass.templateClass) sClass = sClass.templateClass;
1848 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1850 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1851 p += nextClass.templateParams.count;
1854 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1856 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1858 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1860 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1861 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1873 strcat(argument, arg.name.string);
1874 strcat(argument, " = ");
1880 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1881 char expString[1024];
1882 OldList * specs = MkList();
1883 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1885 char * string = PrintHexUInt64(arg.expression.ui64);
1886 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1889 ProcessExpressionType(exp);
1890 ComputeExpression(exp);
1891 expString[0] = '\0';
1892 PrintExpression(exp, expString);
1893 strcat(argument, expString);
1895 FreeExpression(exp);
1900 strcat(argument, arg.member.name);
1903 case TemplateParameterType::type:
1905 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1906 strcat(argument, arg.dataTypeString);
1912 if(paramCount) strcat(templateString, ", ");
1913 if(lastParam != p - 1)
1915 strcat(templateString, param.name);
1916 strcat(templateString, " = ");
1918 strcat(templateString, argument);
1927 int len = strlen(templateString);
1928 if(templateString[len-1] == '<')
1932 if(templateString[len-1] == '>')
1933 templateString[len++] = ' ';
1934 templateString[len++] = '>';
1936 templateString[len++] = '\0';
1939 Context context = SetupTemplatesContext(_class);
1940 if(freeType) FreeType(type);
1941 type = ProcessTypeString(templateString, false);
1943 FinishTemplatesContext(context);
1947 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1949 ProcessExpressionType(member.initializer.exp);
1950 if(!member.initializer.exp.expType)
1954 char expString[10240];
1955 expString[0] = '\0';
1956 PrintExpression(member.initializer.exp, expString);
1957 ChangeCh(expString, '\n', ' ');
1958 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
1961 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
1962 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
1964 Compiler_Error($"incompatible instance method %s\n", ident.string);
1967 else if(member.initializer)
1970 FreeType(member.exp.destType);
1971 member.exp.destType = type;
1972 if(member.exp.destType)
1973 member.exp.destType.refCount++;
1974 ProcessExpressionType(member.exp);
1977 ProcessInitializer(member.initializer, type);
1979 if(freeType) FreeType(type);
1983 if(_class && _class.type == unitClass)
1985 if(member.initializer)
1988 FreeType(member.exp.destType);
1989 member.exp.destType = MkClassType(_class.fullName);
1990 ProcessExpressionType(member.initializer, type);
1992 Type type = MkClassType(_class.fullName);
1993 ProcessInitializer(member.initializer, type);
1999 if(member.initializer)
2001 //ProcessExpressionType(member.exp);
2002 ProcessInitializer(member.initializer, null);
2008 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
2012 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
2014 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
2018 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
2023 void ProcessInstantiationType(Instantiation inst)
2028 MembersInit members;
2032 classSym = inst._class.symbol;
2033 _class = classSym ? classSym.registered : null;
2035 if(!_class || _class.type != noHeadClass)
2036 DeclareStruct(curExternal, inst._class.name, false, true);
2038 afterExternal = afterExternal ? afterExternal : curExternal;
2041 ProcessExpressionType(inst.exp);
2043 inst.isConstant = true;
2046 DataMember curMember = null;
2047 Class curClass = null;
2048 DataMember subMemberStack[256];
2049 int subMemberStackPos = 0;
2051 for(members = inst.members->first; members; members = members.next)
2053 switch(members.type)
2055 case methodMembersInit:
2058 static uint instMethodID = 0;
2059 External external = curExternal;
2060 Context context = curContext;
2061 Declarator declarator = members.function.declarator;
2062 Identifier nameID = GetDeclId(declarator);
2063 char * unmangled = nameID ? nameID.string : null;
2065 External createdExternal = null;
2070 strcpy(name, "__ecereInstMeth_");
2071 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2073 strcat(name, nameID.string);
2075 sprintf(number, "_%08d", instMethodID++);
2076 strcat(name, number);
2077 nameID.string = CopyString(name);
2080 // Do modifications here...
2083 Symbol symbol = declarator.symbol;
2084 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2086 if(method && method.type == virtualMethod)
2088 symbol.method = method;
2089 ProcessMethodType(method);
2091 if(!symbol.type.thisClass)
2093 if(method.dataType.thisClass && currentClass &&
2094 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2096 if(!currentClass.symbol)
2097 currentClass.symbol = FindClass(currentClass.fullName);
2098 symbol.type.thisClass = currentClass.symbol;
2103 _class.symbol = FindClass(_class.fullName);
2104 symbol.type.thisClass = _class.symbol;
2107 DeclareType(curExternal, symbol.type, true, true);
2112 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2113 unmangled, classSym.string);
2117 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2121 FreeSpecifier(nameID._class);
2122 nameID._class = null;
2125 curExternal = createdExternal;
2128 if(createdExternal.function)
2129 ProcessFunction(createdExternal.function);
2133 curExternal = declarator.symbol.pointerExternal;
2134 ProcessFunction((FunctionDefinition)members.function);
2136 curExternal = external;
2137 curContext = context;
2141 FreeClassFunction(members.function);
2143 // In this pass, turn this into a MemberInitData
2144 exp = QMkExpId(name);
2145 members.type = dataMembersInit;
2146 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2152 case dataMembersInit:
2154 if(members.dataMembers && classSym)
2157 Location oldyyloc = yylloc;
2158 for(member = members.dataMembers->first; member; member = member.next)
2160 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2161 if(member.initializer && !member.initializer.isConstant)
2162 inst.isConstant = false;
2174 void DeclareType(External neededFor, Type type, bool needDereference, bool forFunctionDef)
2176 _DeclareType(neededFor, type, needDereference, forFunctionDef, false);
2179 void DeclareTypeForwardDeclare(External neededFor, Type type, bool needDereference, bool forFunctionDef)
2181 _DeclareType(neededFor, type, needDereference, forFunctionDef, true);
2184 static void _DeclareType(External neededFor, Type type, bool needDereference, bool forFunctionDef, bool fwdDecl)
2188 if(type.kind == functionType)
2191 for(param = type.params.first; param; param = param.next)
2192 _DeclareType(neededFor, param, forFunctionDef, false, fwdDecl);
2193 _DeclareType(neededFor, type.returnType, forFunctionDef, false, fwdDecl);
2195 else if(type.kind == pointerType)
2196 _DeclareType(neededFor, type.type, false, false, fwdDecl);
2197 else if(type.kind == classType)
2199 Class c = type._class.registered;
2200 _DeclareStruct(neededFor, c ? c.fullName : "ecere::com::Instance", c ? c.type == noHeadClass : false, needDereference && c && c.type == structClass, fwdDecl);
2202 else if(type.kind == structType || type.kind == unionType)
2205 for(member = type.members.first; member; member = member.next)
2206 _DeclareType(neededFor, member, needDereference, forFunctionDef, fwdDecl);
2208 else if(type.kind == arrayType)
2209 _DeclareType(neededFor, type.arrayType, true, false, fwdDecl);
2213 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2215 ClassTemplateArgument * arg = null;
2217 ClassTemplateParameter curParam = null;
2219 for(sClass = _class; sClass; sClass = sClass.base)
2222 if(sClass.templateClass) sClass = sClass.templateClass;
2223 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2225 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2227 for(sClass = sClass.base; sClass; sClass = sClass.base)
2229 if(sClass.templateClass) sClass = sClass.templateClass;
2230 id += sClass.templateParams.count;
2240 arg = &_class.templateArgs[id];
2241 if(arg && param.type == type)
2242 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2247 public Context SetupTemplatesContext(Class _class)
2249 Context context = PushContext();
2250 context.templateTypesOnly = true;
2251 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2253 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2254 for(; param; param = param.next)
2256 if(param.type == type && param.identifier)
2258 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2259 curContext.templateTypes.Add((BTNode)type);
2266 for(sClass = _class; sClass; sClass = sClass.base)
2268 ClassTemplateParameter p;
2269 for(p = sClass.templateParams.first; p; p = p.next)
2271 //OldList * specs = MkList();
2272 //Declarator decl = null;
2273 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2276 TemplateParameter param = p.param;
2280 // ADD DATA TYPE HERE...
2281 p.param = param = TemplateParameter
2283 identifier = MkIdentifier(p.name), type = p.type,
2284 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2287 type = TemplatedType { key = (uintptr)p.name, param = param };
2288 curContext.templateTypes.Add((BTNode)type);
2296 public void FinishTemplatesContext(Context context)
2298 PopContext(context);
2299 FreeContext(context);
2303 public void ProcessMethodType(Method method)
2305 if(!method.dataType)
2307 Context context = SetupTemplatesContext(method._class);
2309 method.dataType = ProcessTypeString(method.dataTypeString, false);
2311 FinishTemplatesContext(context);
2313 if(method.type != virtualMethod && method.dataType)
2315 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2317 if(!method._class.symbol)
2318 method._class.symbol = FindClass(method._class.fullName);
2319 method.dataType.thisClass = method._class.symbol;
2323 // Why was this commented out? Working fine without now...
2326 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2327 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2334 char * par = strstr(type, "(");
2335 char * classOp = null;
2340 for(c = par-type-1; c >= 0; c++)
2342 if(type[c] == ':' && type[c+1] == ':')
2344 classOp = type + c - 1;
2345 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2352 else if(!isspace(type[c]))
2359 int typeLen = strlen(type);
2360 memcpy(temp, classOp, classOpLen);
2361 temp[classOpLen] = '\0';
2363 _class = eSystem_FindClass(module, temp);
2366 method.dataTypeString = new char[typeLen - classOpLen + 1];
2367 memcpy(method.dataTypeString, type, classOp - type);
2368 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2371 method.dataTypeString = type;
2377 public void ProcessPropertyType(Property prop)
2381 Context context = SetupTemplatesContext(prop._class);
2382 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2383 FinishTemplatesContext(context);
2387 public void DeclareMethod(External neededFor, Method method, const char * name)
2389 Symbol symbol = method.symbol;
2390 if(!symbol || (!symbol.pointerExternal && (!symbol.methodCodeExternal || method.type == virtualMethod)))
2392 bool dllImport = false;
2394 if(!method.dataType)
2395 method.dataType = ProcessTypeString(method.dataTypeString, false);
2397 //if(!symbol || symbol._import || method.type == virtualMethod)
2399 if(!symbol || method.type == virtualMethod)
2402 if(!method._class.symbol)
2403 method._class.symbol = FindClass(method._class.fullName);
2404 classSym = method._class.symbol;
2405 if(!classSym._import)
2407 ModuleImport module;
2409 if(method._class.module && method._class.module.name)
2410 module = FindModule(method._class.module);
2412 module = mainModule;
2413 classSym._import = ClassImport
2415 name = CopyString(method._class.fullName);
2416 isRemote = method._class.isRemote;
2418 module.classes.Add(classSym._import);
2422 symbol = method.symbol = Symbol { };
2426 symbol._import = (ClassImport)MethodImport
2428 name = CopyString(method.name);
2429 isVirtual = method.type == virtualMethod;
2431 classSym._import.methods.Add(symbol._import);
2435 symbol.type = method.dataType;
2436 if(symbol.type) symbol.type.refCount++;
2439 if(!method.dataType.dllExport)
2441 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2448 // We need a declaration here :)
2450 OldList * specifiers, * declarators;
2452 Declarator funcDecl;
2455 specifiers = MkList();
2456 declarators = MkList();
2459 ListAdd(specifiers, MkSpecifier(EXTERN));
2460 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2461 ListAdd(specifiers, MkSpecifier(STATIC));
2463 if(method.type == virtualMethod)
2465 ListAdd(specifiers, MkSpecifier(INT));
2466 d = MkDeclaratorIdentifier(MkIdentifier(name));
2470 d = MkDeclaratorIdentifier(MkIdentifier(name));
2472 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2474 Context context = SetupTemplatesContext(method._class);
2475 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2476 FinishTemplatesContext(context);
2478 funcDecl = GetFuncDecl(d);
2482 Specifier spec, next;
2483 for(spec = specifiers->first; spec; spec = next)
2486 if(spec.type == extendedSpecifier)
2488 specifiers->Remove(spec);
2489 FreeSpecifier(spec);
2494 // Add this parameter if not a static method
2495 if(method.dataType && !method.dataType.staticMethod)
2497 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2499 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2500 TypeName thisParam = MkTypeName(MkListOne(
2501 MkSpecifierName(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2502 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2503 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2504 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2506 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2508 TypeName param = funcDecl.function.parameters->first;
2509 funcDecl.function.parameters->Remove(param);
2510 FreeTypeName(param);
2513 if(!funcDecl.function.parameters)
2514 funcDecl.function.parameters = MkList();
2515 funcDecl.function.parameters->Insert(null, thisParam);
2519 ProcessDeclarator(d, true);
2521 ListAdd(declarators, MkInitDeclarator(d, null));
2523 decl = MkDeclaration(specifiers, declarators);
2525 ReplaceThisClassSpecifiers(specifiers, method._class);
2527 external = MkExternalDeclaration(decl);
2528 external.symbol = symbol;
2529 symbol.pointerExternal = external;
2531 DeclareStruct(external, method._class.fullName, true, true);
2533 DeclareType(external, method.dataType, true, true);
2536 if(inCompiler && neededFor)
2538 External external = symbol.pointerExternal ? symbol.pointerExternal : symbol.methodCodeExternal;
2539 neededFor.CreateUniqueEdge(external, external.type == functionExternal);
2543 char * ReplaceThisClass(Class _class)
2545 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2549 ClassTemplateParameter param;
2552 char className[1024];
2553 strcpy(className, _class.fullName);
2554 for(param = _class.templateParams.first; param; param = param.next)
2556 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2558 if(first) strcat(className, "<");
2559 if(!first) strcat(className, ", ");
2560 if(lastParam + 1 != p)
2562 strcat(className, param.name);
2563 strcat(className, " = ");
2565 strcat(className, param.name);
2573 int len = strlen(className);
2574 if(className[len-1] == '>') className[len++] = ' ';
2575 className[len++] = '>';
2576 className[len++] = '\0';
2578 return CopyString(className);
2581 return CopyString(_class.fullName);
2584 Type ReplaceThisClassType(Class _class)
2587 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2591 ClassTemplateParameter param;
2593 char className[1024];
2594 strcpy(className, _class.fullName);
2596 for(param = _class.templateParams.first; param; param = param.next)
2598 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2600 if(first) strcat(className, "<");
2601 if(!first) strcat(className, ", ");
2602 if(lastParam + 1 != p)
2604 strcat(className, param.name);
2605 strcat(className, " = ");
2607 strcat(className, param.name);
2615 int len = strlen(className);
2616 if(className[len-1] == '>') className[len++] = ' ';
2617 className[len++] = '>';
2618 className[len++] = '\0';
2620 type = MkClassType(className);
2621 //type = ProcessTypeString(className, false);
2625 type = MkClassType(_class.fullName);
2626 //type = ProcessTypeString(_class.fullName, false);
2628 //type.wasThisClass = true;
2632 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2634 if(specs != null && _class)
2637 for(spec = specs.first; spec; spec = spec.next)
2639 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2641 spec.type = nameSpecifier;
2642 spec.name = ReplaceThisClass(_class);
2643 spec.symbol = FindClass(spec.name); //_class.symbol;
2649 // Returns imported or not
2650 bool DeclareFunction(External neededFor, GlobalFunction function, char * name)
2652 Symbol symbol = function.symbol;
2653 // TOCHECK: Might get rid of the pointerExternal check in favor of marking the edge as breakable
2654 if(!symbol || !symbol.pointerExternal)
2656 bool imported = false;
2657 bool dllImport = false;
2659 if(!function.dataType)
2661 function.dataType = ProcessTypeString(function.dataTypeString, false);
2662 if(!function.dataType.thisClass)
2663 function.dataType.staticMethod = true;
2670 ModuleImport module = FindModule(function.module);
2671 // WARNING: This is not added anywhere...
2672 symbol = function.symbol = Symbol { };
2676 if(!function.dataType.dllExport)
2678 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2679 module.functions.Add(symbol._import);
2682 // Set the symbol type
2684 symbol.type = ProcessTypeString(function.dataTypeString, false);
2685 if(!symbol.type.thisClass)
2686 symbol.type.staticMethod = true;
2689 imported = symbol._import ? true : false;
2690 if(imported && function.module != privateModule && function.module.importType != staticImport)
2696 // TOCHECK: What's with the functionExternal check here? Is it Edge breaking / forward declaration?
2697 //if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2699 // We need a declaration here :)
2701 OldList * specifiers, * declarators;
2703 Declarator funcDecl;
2706 specifiers = MkList();
2707 declarators = MkList();
2709 ListAdd(specifiers, MkSpecifier(EXTERN));
2711 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2713 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2715 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2716 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2717 if(function.module.importType == staticImport)
2720 for(spec = specifiers->first; spec; spec = spec.next)
2721 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2723 specifiers->Remove(spec);
2724 FreeSpecifier(spec);
2729 funcDecl = GetFuncDecl(d);
2731 // Make sure we don't have empty parameter declarations for static methods...
2732 if(funcDecl && !funcDecl.function.parameters)
2734 funcDecl.function.parameters = MkList();
2735 funcDecl.function.parameters->Insert(null,
2736 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2739 ListAdd(declarators, MkInitDeclarator(d, null));
2742 Context oldCtx = curContext;
2743 curContext = globalContext;
2744 decl = MkDeclaration(specifiers, declarators);
2745 curContext = oldCtx;
2748 // Keep a different symbol for the function definition than the declaration...
2749 /* Note: This should be handled by the edge breaking...
2750 if(symbol.pointerExternal && symbol.pointerExternal.type == functionExternal)
2752 Symbol functionSymbol { };
2755 *functionSymbol = *symbol;
2756 functionSymbol.string = CopyString(symbol.string);
2757 if(functionSymbol.type)
2758 functionSymbol.type.refCount++;
2761 excludedSymbols->Add(functionSymbol);
2763 symbol.pointerExternal.symbol = functionSymbol;
2766 external = MkExternalDeclaration(decl);
2768 external.symbol = symbol;
2769 symbol.pointerExternal = external;
2771 DeclareType(external, function.dataType, true, true);
2775 if(inCompiler && neededFor && symbol && symbol.pointerExternal)
2776 neededFor.CreateUniqueEdge(symbol.pointerExternal, symbol.pointerExternal.type == functionExternal);
2777 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2780 void DeclareGlobalData(External neededFor, GlobalData data)
2782 Symbol symbol = data.symbol;
2783 // TOCHECK: Might get rid of the pointerExternal check in favor of marking the edge as breakable
2784 if(!symbol || !symbol.pointerExternal)
2789 symbol = data.symbol = Symbol { };
2792 data.dataType = ProcessTypeString(data.dataTypeString, false);
2796 // We need a declaration here :)
2798 OldList * specifiers, * declarators;
2802 specifiers = MkList();
2803 declarators = MkList();
2805 ListAdd(specifiers, MkSpecifier(EXTERN));
2806 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2807 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2809 ListAdd(declarators, MkInitDeclarator(d, null));
2811 decl = MkDeclaration(specifiers, declarators);
2812 external = MkExternalDeclaration(decl);
2814 ast->Insert(curExternal.prev, external);
2815 external.symbol = symbol;
2816 symbol.pointerExternal = external;
2818 DeclareType(external, data.dataType, true, true);
2821 if(inCompiler && neededFor && symbol && symbol.pointerExternal)
2822 neededFor.CreateUniqueEdge(symbol.pointerExternal, false);
2825 class Conversion : struct
2827 Conversion prev, next;
2833 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
2836 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
2837 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
2839 Class sourceClass = source.kind == classType ? source._class.registered : null;
2840 Class destClass = dest.kind == classType ? dest._class.registered : null;
2841 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
2842 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
2844 Type sourceType = source, destType = dest;
2845 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
2846 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
2847 if(!destType.constant && sourceType.constant)
2851 Compiler_Warning($"discarding const qualifier\n");
2858 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
2859 bool isConversionExploration, bool warnConst)
2864 CheckConstCompatibility(source, dest, true);
2865 // Property convert;
2867 if(source.kind == templateType && dest.kind != templateType)
2869 Type type = ProcessTemplateParameterType(source.templateParameter);
2870 if(type) source = type;
2873 if(dest.kind == templateType && source.kind != templateType)
2875 Type type = ProcessTemplateParameterType(dest.templateParameter);
2876 if(type) dest = type;
2879 if(dest.classObjectType == typedObject && dest.kind != functionType)
2881 if(source.classObjectType != anyObject)
2885 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
2886 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
2894 if(source.kind != functionType && source.classObjectType == anyObject)
2896 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
2900 if((dest.kind == structType && source.kind == structType) ||
2901 (dest.kind == unionType && source.kind == unionType))
2903 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
2904 (source.members.first && source.members.first == dest.members.first))
2908 if(dest.kind == ellipsisType && source.kind != voidType)
2911 if(dest.kind == pointerType && dest.type.kind == voidType &&
2912 ((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))
2913 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
2915 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
2917 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
2919 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
2920 ((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))
2921 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
2922 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
2924 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
2927 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
2929 if(source._class.registered && source._class.registered.type == unitClass)
2931 if(conversions != null)
2933 if(source._class.registered == dest._class.registered)
2938 Class sourceBase, destBase;
2939 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
2940 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
2941 if(sourceBase == destBase)
2945 // Don't match enum inheriting from other enum if resolving enumeration values
2946 // TESTING: !dest.classObjectType
2947 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
2949 (!source._class.registered || source._class.registered.type != enumClass) ||
2950 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
2954 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
2956 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
2957 ((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)
2959 if(eClass_IsDerived(dest._class.registered, source._class.registered))
2967 // JUST ADDED THIS...
2968 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
2973 // Just added this for Straight conversion of ColorAlpha => Color
2974 if(source.kind == classType)
2977 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
2980 for(convert = _class.conversions.first; convert; convert = convert.next)
2982 if(convert.memberAccess == publicAccess || _class.module == privateModule)
2984 Conversion after = (conversions != null) ? conversions.last : null;
2986 if(!convert.dataType)
2987 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
2988 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
2989 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
2990 MatchTypes(convert.dataType, dest, conversions, null, null,
2991 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
2992 convert.dataType.kind == classType, false, true, warnConst))
2994 if(!conversions && !convert.Get)
2996 else if(conversions != null)
2998 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
2999 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3000 (dest.kind != classType || dest._class.registered != _class.base))
3004 Conversion conv { convert = convert, isGet = true };
3005 // conversions.Add(conv);
3006 conversions.Insert(after, conv);
3019 if(dest.kind == classType)
3022 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3025 for(convert = _class.conversions.first; convert; convert = convert.next)
3027 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3029 Type constType = null;
3030 bool success = false;
3031 // Conversion after = (conversions != null) ? conversions.last : null;
3033 if(!convert.dataType)
3034 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3036 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3039 constType = { kind = pointerType, refCount = 1, type = ptrType };
3040 CopyTypeInto(ptrType, convert.dataType.type);
3041 ptrType.constant = true;
3044 // Just added this equality check to prevent recursion.... Make it safer?
3045 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3046 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3048 if(!conversions && !convert.Set)
3050 else if(conversions != null)
3052 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3053 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3054 (source.kind != classType || source._class.registered != _class.base))
3058 // *** Testing this! ***
3059 Conversion conv { convert = convert };
3060 conversions.Add(conv);
3061 //conversions.Insert(after, conv);
3067 FreeType(constType);
3073 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3075 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3076 (source.kind != classType || source._class.registered.type != structClass))
3080 // TESTING THIS... IS THIS OK??
3081 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3083 if(!dest._class.registered.dataType)
3084 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3085 // Only support this for classes...
3086 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3087 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3089 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3098 if(source.kind == classType)
3101 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3104 for(convert = _class.conversions.first; convert; convert = convert.next)
3106 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3108 Conversion after = (conversions != null) ? conversions.last : null;
3110 if(!convert.dataType)
3111 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3112 if(convert.dataType != source &&
3113 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3114 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3116 if(!conversions && !convert.Get)
3118 else if(conversions != null)
3120 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3121 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3122 (dest.kind != classType || dest._class.registered != _class.base))
3126 Conversion conv { convert = convert, isGet = true };
3128 // conversions.Add(conv);
3129 conversions.Insert(after, conv);
3138 // TESTING THIS... IS THIS OK??
3139 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3141 if(!source._class.registered.dataType)
3142 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3143 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3145 if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, source._class.registered.dataType.kind == classType, source._class.registered.dataType.kind == classType, false, false, warnConst))
3147 // For bool to be accepted by byte, short, etc.
3148 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3155 if(source.kind == classType || source.kind == subClassType)
3157 else if(dest.kind == source.kind &&
3158 (dest.kind != structType && dest.kind != unionType &&
3159 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3161 // RECENTLY ADDED THESE
3162 else if(dest.kind == doubleType && source.kind == floatType)
3164 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3166 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3168 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3170 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3172 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3174 else if(source.kind == enumType &&
3175 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3177 else if(dest.kind == enumType && !isConversionExploration &&
3178 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3180 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3181 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3183 Type paramSource, paramDest;
3185 if(dest.kind == methodType)
3186 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3187 if(source.kind == methodType)
3188 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3190 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3191 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3192 if(dest.kind == methodType)
3193 dest = dest.method.dataType;
3194 if(source.kind == methodType)
3195 source = source.method.dataType;
3197 paramSource = source.params.first;
3198 if(paramSource && paramSource.kind == voidType) paramSource = null;
3199 paramDest = dest.params.first;
3200 if(paramDest && paramDest.kind == voidType) paramDest = null;
3203 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3204 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3206 // Source thisClass must be derived from destination thisClass
3207 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3208 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3210 if(paramDest && paramDest.kind == classType)
3211 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3213 Compiler_Error($"method class should not take an object\n");
3216 paramDest = paramDest.next;
3218 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3220 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3224 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3226 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3232 // THIS WAS BACKWARDS:
3233 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3234 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3237 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3239 Compiler_Error($"overriding class expected to be derived from method class\n");
3243 paramSource = paramSource.next;
3249 // Source thisClass must be derived from destination thisClass
3250 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3252 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3258 // THIS WAS BACKWARDS TOO??
3259 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3260 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3263 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3265 //Compiler_Error($"overriding class expected to be derived from method class\n");
3273 // Source return type must be derived from destination return type
3274 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3276 Compiler_Warning($"incompatible return type for function\n");
3279 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3281 CheckConstCompatibility(dest.returnType, source.returnType, true);
3285 for(; paramDest; paramDest = paramDest.next)
3289 //Compiler_Warning($"not enough parameters\n");
3290 Compiler_Error($"not enough parameters\n");
3294 Type paramDestType = paramDest;
3295 Type paramSourceType = paramSource;
3296 Type type = paramDestType;
3298 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3299 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3300 paramSource.kind != templateType)
3303 ClassTemplateParameter curParam = null;
3305 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3308 if(sClass.templateClass) sClass = sClass.templateClass;
3309 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3311 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3313 for(sClass = sClass.base; sClass; sClass = sClass.base)
3315 if(sClass.templateClass) sClass = sClass.templateClass;
3316 id += sClass.templateParams.count;
3327 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3328 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3332 // paramDest must be derived from paramSource
3333 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3334 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3338 PrintType(paramDest, type, false, true);
3339 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3341 if(paramDestType != paramDest)
3342 FreeType(paramDestType);
3345 if(paramDestType != paramDest)
3346 FreeType(paramDestType);
3349 paramSource = paramSource.next;
3353 Compiler_Error($"too many parameters\n");
3358 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3362 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3363 (source.kind == arrayType || source.kind == pointerType))
3365 // Pointers to pointer is incompatible with non normal/nohead classes
3366 if(!(dest.type && dest.type.kind == pointerType && source.type.kind == classType && source.type._class &&
3367 source.type._class.registered && (source.type._class.registered.type != normalClass && source.type._class.registered.type != noHeadClass) && !source.type.byReference))
3369 ComputeTypeSize(source.type);
3370 ComputeTypeSize(dest.type);
3371 if(source.type.size == dest.type.size && MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3379 static void FreeConvert(Conversion convert)
3381 if(convert.resultType)
3382 FreeType(convert.resultType);
3385 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3386 char * string, OldList conversions)
3390 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3392 Class _class = link.data;
3393 if(_class.type == enumClass)
3395 OldList converts { };
3397 type.kind = classType;
3400 _class.symbol = FindClass(_class.fullName);
3401 type._class = _class.symbol;
3403 if(MatchTypes(type, dest, &converts, null, null, dest.kind != classType || !dest._class || strcmp(dest._class.string, "bool"),
3404 false, false, false, false))
3407 Class enumClass = eSystem_FindClass(privateModule, "enum");
3411 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3413 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3414 for(value = e.values.first; value; value = value.next)
3416 if(!strcmp(value.name, string))
3421 FreeType(sourceExp.expType);
3423 sourceExp.isConstant = true;
3424 sourceExp.expType = MkClassType(baseClass.fullName);
3425 if(inCompiler || inPreCompiler || inDebugger)
3428 FreeExpContents(sourceExp);
3430 sourceExp.type = constantExp;
3431 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "short") || !strcmp(baseClass.dataTypeString, "char"))
3432 sprintf(constant, FORMAT64D, value.data);
3434 sprintf(constant, FORMAT64HEXLL, value.data);
3435 sourceExp.constant = CopyString(constant);
3436 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3439 while(converts.first)
3441 Conversion convert = converts.first;
3442 converts.Remove(convert);
3443 conversions.Add(convert);
3452 converts.Free(FreeConvert);
3456 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3457 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3462 public bool ModuleVisibility(Module searchIn, Module searchFor)
3464 SubModule subModule;
3466 if(searchFor == searchIn)
3469 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3471 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3473 if(ModuleVisibility(subModule.module, searchFor))
3480 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3484 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3486 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3488 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3491 for(module = mainModule.application.allModules.first; module; module = module.next)
3493 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3499 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3502 Type realDest = dest;
3503 Type backupSourceExpType = null;
3504 Expression computedExp = sourceExp;
3507 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3508 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3510 computedExp = CopyExpression(sourceExp); // Keep the original expression, but compute for checking enum ranges
3511 ComputeExpression(computedExp /*sourceExp*/);
3514 source = sourceExp.expType;
3516 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3518 if(computedExp != sourceExp)
3520 FreeExpression(computedExp);
3521 computedExp = sourceExp;
3527 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3529 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3531 Class sourceBase, destBase;
3532 for(sourceBase = source._class.registered;
3533 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3534 sourceBase = sourceBase.base);
3535 for(destBase = dest._class.registered;
3536 destBase && destBase.base && destBase.base.type != systemClass;
3537 destBase = destBase.base);
3538 //if(source._class.registered == dest._class.registered)
3539 if(sourceBase == destBase)
3541 if(computedExp != sourceExp)
3543 FreeExpression(computedExp);
3544 computedExp = sourceExp;
3556 int64 value = MAXINT;
3560 if(computedExp.type == constantExp)
3563 value = strtoll(computedExp.constant, null, 0);
3565 value = strtoull(computedExp.constant, null, 0);
3567 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3570 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3572 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3574 if(computedExp != sourceExp)
3576 FreeExpression(computedExp);
3577 computedExp = sourceExp;
3580 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3581 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3584 source = Type { kind = intType, isSigned = false, refCount = 1 };
3587 if(dest.kind == classType)
3589 Class _class = dest._class ? dest._class.registered : null;
3591 if(_class && _class.type == unitClass)
3593 if(source.kind != classType)
3596 Type tempDest, tempSource;
3598 for(; _class.base.type != systemClass; _class = _class.base);
3600 tempDest = tempType;
3602 tempType.kind = classType;
3604 _class.symbol = FindClass(_class.fullName);
3606 tempType._class = _class.symbol;
3607 tempType.truth = dest.truth;
3609 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3611 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3612 backupSourceExpType = sourceExp.expType;
3613 if(dest.passAsTemplate)
3615 // Don't carry passAsTemplate
3616 sourceExp.expType = { };
3617 CopyTypeInto(sourceExp.expType, dest);
3618 sourceExp.expType.passAsTemplate = false;
3622 sourceExp.expType = dest;
3625 //sourceExp.expType = MkClassType(_class.fullName);
3633 // Why wasn't there something like this?
3634 if(_class && _class.type == bitClass && source.kind != classType)
3636 if(!dest._class.registered.dataType)
3637 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3638 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3641 FreeType(sourceExp.expType);
3642 source = sourceExp.expType = MkClassType(dest._class.string);
3645 //source.kind = classType;
3646 //source._class = dest._class;
3650 // Adding two enumerations
3652 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3654 if(!source._class.registered.dataType)
3655 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3656 if(!dest._class.registered.dataType)
3657 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3659 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3662 source = sourceExp.expType = MkClassType(dest._class.string);
3665 //source.kind = classType;
3666 //source._class = dest._class;
3670 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3672 OldList * specs = MkList();
3676 ReadString(string, sourceExp.string);
3677 decl = SpecDeclFromString(string, specs, null);
3679 FreeExpContents(sourceExp);
3680 FreeType(sourceExp.expType);
3682 sourceExp.type = classExp;
3683 sourceExp._classExp.specifiers = specs;
3684 sourceExp._classExp.decl = decl;
3685 sourceExp.expType = dest;
3690 if(backupSourceExpType) FreeType(backupSourceExpType);
3694 else if(source.kind == classType)
3696 Class _class = source._class ? source._class.registered : null;
3698 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3701 if(dest.kind != classType)
3703 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3704 if(!source._class.registered.dataType)
3705 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3708 dest = MkClassType(source._class.string);
3709 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3710 // dest = MkClassType(source._class.string);
3714 if(dest.kind != classType)
3717 Type tempDest, tempSource;
3719 if(!source._class.registered.dataType)
3720 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3722 for(; _class.base.type != systemClass; _class = _class.base);
3724 tempSource = tempType;
3725 tempType.kind = classType;
3726 tempType._class = FindClass(_class.fullName);
3727 tempType.truth = source.truth;
3728 tempType.classObjectType = source.classObjectType;
3731 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3733 // PUT THIS BACK TESTING UNITS?
3734 if(conversions && conversions.last)
3736 ((Conversion)(conversions.last)).resultType = dest;
3740 FreeType(sourceExp.expType);
3741 sourceExp.expType = MkClassType(_class.fullName);
3742 sourceExp.expType.truth = source.truth;
3743 sourceExp.expType.classObjectType = source.classObjectType;
3745 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3747 if(!sourceExp.destType)
3749 FreeType(sourceExp.destType);
3750 sourceExp.destType = sourceExp.expType;
3751 if(sourceExp.expType)
3752 sourceExp.expType.refCount++;
3755 //source = _class.dataType;
3758 // TOCHECK: TESTING THIS NEW CODE
3759 if(!_class.dataType)
3760 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3762 dest = MkClassType(source._class.string);
3763 dest.truth = source.truth;
3764 dest.classObjectType = source.classObjectType;
3767 source = _class.dataType;
3777 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3787 if(source.kind == classType)
3789 Class _class = source._class.registered;
3790 if(_class.type == unitClass)
3792 if(!_class.dataType)
3793 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3794 source = _class.dataType;
3798 if(dest.kind == classType)
3800 Class _class = dest._class ? dest._class.registered : null;
3801 bool fittingValue = false;
3802 if(_class && _class.type == enumClass)
3804 Class enumClass = eSystem_FindClass(privateModule, "enum");
3805 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3806 if(c && value >= 0 && value <= c.largest)
3807 fittingValue = true;
3810 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3811 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3813 if(_class.type == normalClass || _class.type == noHeadClass)
3815 Expression newExp { };
3816 *newExp = *sourceExp;
3817 if(sourceExp.destType) sourceExp.destType.refCount++;
3818 if(sourceExp.expType) sourceExp.expType.refCount++;
3819 sourceExp.type = castExp;
3820 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3821 sourceExp.cast.exp = newExp;
3822 FreeType(sourceExp.expType);
3823 sourceExp.expType = null;
3824 ProcessExpressionType(sourceExp);
3826 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
3829 FreeType(sourceExp.expType);
3830 sourceExp.expType = dest;
3834 if(inCompiler) FreeType(dest);
3836 if(backupSourceExpType) FreeType(backupSourceExpType);
3840 if(!_class.dataType)
3841 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3843 dest = _class.dataType;
3847 // Accept lower precision types for units, since we want to keep the unit type
3848 if(dest.kind == doubleType &&
3849 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
3850 source.kind == charType || source.kind == _BoolType))
3852 specs = MkListOne(MkSpecifier(DOUBLE));
3854 else if(dest.kind == floatType &&
3855 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3856 source.kind == _BoolType || source.kind == doubleType))
3858 specs = MkListOne(MkSpecifier(FLOAT));
3860 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
3861 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3864 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3865 ListAdd(specs, MkSpecifier(INT64));
3867 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
3868 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
3871 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3872 ListAdd(specs, MkSpecifier(INT));
3874 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
3875 source.kind == floatType || source.kind == doubleType))
3878 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3879 ListAdd(specs, MkSpecifier(SHORT));
3881 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
3882 source.kind == floatType || source.kind == doubleType))
3885 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3886 ListAdd(specs, MkSpecifier(CHAR));
3892 if(backupSourceExpType)
3894 // Failed to convert: revert previous exp type
3895 if(sourceExp.expType) FreeType(sourceExp.expType);
3896 sourceExp.expType = backupSourceExpType;
3901 else if(dest.kind == doubleType &&
3902 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
3903 source.kind == _BoolType || source.kind == charType))
3905 specs = MkListOne(MkSpecifier(DOUBLE));
3907 else if(dest.kind == floatType &&
3908 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3910 specs = MkListOne(MkSpecifier(FLOAT));
3912 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3913 (value == 1 || value == 0))
3916 ListAdd(specs, MkSpecifier(BOOL));
3918 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
3919 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
3922 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3923 ListAdd(specs, MkSpecifier(CHAR));
3925 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
3926 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
3929 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3930 ListAdd(specs, MkSpecifier(SHORT));
3932 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
3935 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3936 ListAdd(specs, MkSpecifier(INT));
3938 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
3941 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
3942 ListAdd(specs, MkSpecifier(INT64));
3944 else if(dest.kind == enumType &&
3945 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
3947 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
3953 if(backupSourceExpType)
3955 // Failed to convert: revert previous exp type
3956 if(sourceExp.expType) FreeType(sourceExp.expType);
3957 sourceExp.expType = backupSourceExpType;
3962 if(!flag && !sourceExp.opDestType)
3964 Expression newExp { };
3965 *newExp = *sourceExp;
3968 if(sourceExp.destType) sourceExp.destType.refCount++;
3969 if(sourceExp.expType) sourceExp.expType.refCount++;
3971 sourceExp.type = castExp;
3972 if(realDest.kind == classType)
3974 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
3975 FreeList(specs, FreeSpecifier);
3978 sourceExp.cast.typeName = MkTypeName(specs, null);
3979 if(newExp.type == opExp)
3981 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
3984 sourceExp.cast.exp = newExp;
3986 FreeType(sourceExp.expType);
3987 sourceExp.expType = null;
3988 ProcessExpressionType(sourceExp);
3991 FreeList(specs, FreeSpecifier);
3995 if(backupSourceExpType) FreeType(backupSourceExpType);
4001 if(computedExp != sourceExp)
4003 FreeExpression(computedExp);
4004 computedExp = sourceExp;
4007 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4008 if(sourceExp.type == identifierExp)
4010 Identifier id = sourceExp.identifier;
4011 if(dest.kind == classType)
4013 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4015 Class _class = dest._class.registered;
4016 Class enumClass = eSystem_FindClass(privateModule, "enum");
4019 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4022 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4023 for(value = e.values.first; value; value = value.next)
4025 if(!strcmp(value.name, id.string))
4030 FreeType(sourceExp.expType);
4032 sourceExp.isConstant = true;
4033 sourceExp.expType = MkClassType(_class.fullName);
4034 if(inCompiler || inPreCompiler || inDebugger)
4036 FreeExpContents(sourceExp);
4038 sourceExp.type = constantExp;
4039 if(_class.dataTypeString && (!strcmp(_class.dataTypeString, "int") || !strcmp(_class.dataTypeString, "int64") || !strcmp(_class.dataTypeString, "short") || !strcmp(_class.dataTypeString, "char"))) // _class cannot be null here!
4040 sourceExp.constant = PrintInt64(value.data);
4042 sourceExp.constant = PrintUInt64(value.data);
4043 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4053 // Loop through all enum classes
4054 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4065 #define TERTIARY(o, name, m, t, p) \
4066 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4068 exp.type = constantExp; \
4069 exp.string = p(op1.m ? op2.m : op3.m); \
4071 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4075 #define BINARY(o, name, m, t, p) \
4076 static bool name(Expression exp, Operand op1, Operand op2) \
4079 exp.type = constantExp; \
4080 exp.string = p((t)(op1.m o value2)); \
4082 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4086 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4087 static bool name(Expression exp, Operand op1, Operand op2) \
4090 exp.type = constantExp; \
4091 exp.string = p(value2 ? (op1.m o value2) : 0); \
4093 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4097 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4098 static bool name(Expression exp, Operand op1, Operand op2) \
4101 exp.type = constantExp; \
4102 exp.string = p(op1.m o value2); \
4104 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4108 #define UNARY(o, name, m, t, p) \
4109 static bool name(Expression exp, Operand op1) \
4111 exp.type = constantExp; \
4112 exp.string = p((t)(o op1.m)); \
4114 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4118 #define OPERATOR_ALL(macro, o, name) \
4119 macro(o, Int##name, i, int, PrintInt) \
4120 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4121 macro(o, Int64##name, i64, int64, PrintInt64) \
4122 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4123 macro(o, Short##name, s, short, PrintShort) \
4124 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4125 macro(o, Char##name, c, char, PrintChar) \
4126 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4127 macro(o, Float##name, f, float, PrintFloat) \
4128 macro(o, Double##name, d, double, PrintDouble)
4130 #define OPERATOR_INTTYPES(macro, o, name) \
4131 macro(o, Int##name, i, int, PrintInt) \
4132 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4133 macro(o, Int64##name, i64, int64, PrintInt64) \
4134 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4135 macro(o, Short##name, s, short, PrintShort) \
4136 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4137 macro(o, Char##name, c, char, PrintChar) \
4138 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4140 #define OPERATOR_REALTYPES(macro, o, name) \
4141 macro(o, Float##name, f, float, PrintFloat) \
4142 macro(o, Double##name, d, double, PrintDouble)
4144 // binary arithmetic
4145 OPERATOR_ALL(BINARY, +, Add)
4146 OPERATOR_ALL(BINARY, -, Sub)
4147 OPERATOR_ALL(BINARY, *, Mul)
4148 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4149 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4150 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4153 OPERATOR_ALL(UNARY, -, Neg)
4155 // unary arithmetic increment and decrement
4156 OPERATOR_ALL(UNARY, ++, Inc)
4157 OPERATOR_ALL(UNARY, --, Dec)
4159 // binary arithmetic assignment
4160 OPERATOR_ALL(BINARY, =, Asign)
4161 OPERATOR_ALL(BINARY, +=, AddAsign)
4162 OPERATOR_ALL(BINARY, -=, SubAsign)
4163 OPERATOR_ALL(BINARY, *=, MulAsign)
4164 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4165 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4166 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4169 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4170 OPERATOR_INTTYPES(BINARY, |, BitOr)
4171 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4172 OPERATOR_INTTYPES(BINARY, <<, LShift)
4173 OPERATOR_INTTYPES(BINARY, >>, RShift)
4176 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4178 // binary bitwise assignment
4179 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4180 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4181 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4182 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4183 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4185 // unary logical negation
4186 OPERATOR_INTTYPES(UNARY, !, Not)
4188 // binary logical equality
4189 OPERATOR_ALL(BINARY, ==, Equ)
4190 OPERATOR_ALL(BINARY, !=, Nqu)
4193 OPERATOR_ALL(BINARY, &&, And)
4194 OPERATOR_ALL(BINARY, ||, Or)
4196 // binary logical relational
4197 OPERATOR_ALL(BINARY, >, Grt)
4198 OPERATOR_ALL(BINARY, <, Sma)
4199 OPERATOR_ALL(BINARY, >=, GrtEqu)
4200 OPERATOR_ALL(BINARY, <=, SmaEqu)
4202 // tertiary condition operator
4203 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4205 //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
4206 #define OPERATOR_TABLE_ALL(name, type) \
4207 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4209 type##Inc, type##Dec, \
4210 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4211 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4213 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4215 type##Equ, type##Nqu, \
4216 type##And, type##Or, \
4217 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4220 #define OPERATOR_TABLE_INTTYPES(name, type) \
4221 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4223 type##Inc, type##Dec, \
4224 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4225 null, null, null, null, null, \
4227 null, null, null, null, null, \
4229 type##Equ, type##Nqu, \
4230 type##And, type##Or, \
4231 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4234 OPERATOR_TABLE_ALL(int, Int)
4235 OPERATOR_TABLE_ALL(uint, UInt)
4236 OPERATOR_TABLE_ALL(int64, Int64)
4237 OPERATOR_TABLE_ALL(uint64, UInt64)
4238 OPERATOR_TABLE_ALL(short, Short)
4239 OPERATOR_TABLE_ALL(ushort, UShort)
4240 OPERATOR_TABLE_INTTYPES(float, Float)
4241 OPERATOR_TABLE_INTTYPES(double, Double)
4242 OPERATOR_TABLE_ALL(char, Char)
4243 OPERATOR_TABLE_ALL(uchar, UChar)
4245 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4246 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4247 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4248 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4249 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4250 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4251 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4252 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4254 public void ReadString(char * output, char * string)
4256 int len = strlen(string);
4258 bool quoted = false, escaped = false;
4259 for(c = 0; c<len; c++)
4261 char ch = string[c];
4266 case 'n': output[d] = '\n'; break;
4267 case 't': output[d] = '\t'; break;
4268 case 'a': output[d] = '\a'; break;
4269 case 'b': output[d] = '\b'; break;
4270 case 'f': output[d] = '\f'; break;
4271 case 'r': output[d] = '\r'; break;
4272 case 'v': output[d] = '\v'; break;
4273 case '\\': output[d] = '\\'; break;
4274 case '\"': output[d] = '\"'; break;
4275 case '\'': output[d] = '\''; break;
4276 default: output[d] = ch;
4297 // String Unescape Copy
4299 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4300 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4301 public int UnescapeString(char * d, char * s, int len)
4305 while(j < len && (ch = s[j]))
4310 switch((ch = s[++j]))
4312 case 'n': d[k] = '\n'; break;
4313 case 't': d[k] = '\t'; break;
4314 case 'a': d[k] = '\a'; break;
4315 case 'b': d[k] = '\b'; break;
4316 case 'f': d[k] = '\f'; break;
4317 case 'r': d[k] = '\r'; break;
4318 case 'v': d[k] = '\v'; break;
4319 case '\\': d[k] = '\\'; break;
4320 case '\"': d[k] = '\"'; break;
4321 case '\'': d[k] = '\''; break;
4322 default: d[k] = '\\'; d[k] = ch;
4334 public char * OffsetEscapedString(char * s, int len, int offset)
4338 while(j < len && k < offset && (ch = s[j]))
4343 return (k == offset) ? s + j : null;
4346 public Operand GetOperand(Expression exp)
4349 Type type = exp.expType;
4352 while(type.kind == classType &&
4353 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4355 if(!type._class.registered.dataType)
4356 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4357 type = type._class.registered.dataType;
4360 if(exp.type == stringExp && op.kind == pointerType)
4362 op.ui64 = (uint64)(uintptr)exp.string;
4363 op.kind = pointerType;
4366 else if(exp.isConstant && exp.type == constantExp)
4368 op.kind = type.kind;
4376 if(exp.constant[0] == '\'')
4378 op.c = exp.constant[1];
4381 else if(type.isSigned)
4383 op.c = (char)strtol(exp.constant, null, 0);
4388 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4396 op.s = (short)strtol(exp.constant, null, 0);
4401 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4409 op.i = (int)strtol(exp.constant, null, 0);
4414 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4422 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4427 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4430 op.kind = int64Type;
4435 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4440 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4443 op.kind = int64Type;
4448 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4453 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4456 op.kind = int64Type;
4459 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4460 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4461 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4462 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4464 op.f = (float)strtod(exp.constant, null);
4468 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4469 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4470 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4471 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4473 op.d = (double)strtod(exp.constant, null);
4476 //case classType: For when we have operator overloading...
4477 // Pointer additions
4478 //case functionType:
4482 op.ui64 = _strtoui64(exp.constant, null, 0);
4483 op.kind = pointerType;
4493 static int64 GetEnumValue(Class _class, void * ptr)
4496 switch(_class.typeSize)
4499 if(!strcmp(_class.dataTypeString, "uint64"))
4500 v = (int64)*(uint64 *)ptr;
4502 v = (int64)*(int64 *)ptr;
4505 if(!strcmp(_class.dataTypeString, "uint"))
4506 v = (int64)*(uint *)ptr;
4508 v = (int64)*(int *)ptr;
4511 if(!strcmp(_class.dataTypeString, "uint16"))
4512 v = (int64)*(uint16 *)ptr;
4514 v = (int64)*(short *)ptr;
4517 if(!strcmp(_class.dataTypeString, "byte"))
4518 v = (int64)*(byte *)ptr;
4520 v = (int64)*(char *)ptr;
4526 static __attribute__((unused)) void UnusedFunction()
4529 a.OnGetString(0,0,0);
4532 extern int __ecereVMethodID_class_OnGetString;
4535 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4537 DataMember dataMember;
4538 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4540 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4541 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4545 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4547 void * ptr = inst.data + dataMember.offset + offset;
4548 char * result = null;
4549 exp.loc = member.loc = inst.loc;
4550 ((Identifier)member.identifiers->first).loc = inst.loc;
4552 if(!dataMember.dataType)
4553 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4554 type = dataMember.dataType;
4555 if(type.kind == classType)
4557 Class _class = type._class.registered;
4558 if(_class.type == enumClass)
4560 Class enumClass = eSystem_FindClass(privateModule, "enum");
4563 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4565 for(item = e.values.first; item; item = item.next)
4567 if(item.data == GetEnumValue(_class, ptr))
4575 exp.identifier = MkIdentifier(result);
4576 exp.type = identifierExp;
4577 exp.destType = MkClassType(_class.fullName);
4578 ProcessExpressionType(exp);
4582 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4584 if(!_class.dataType)
4585 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4586 type = _class.dataType;
4595 FreeExpContents(exp);
4597 exp.constant = PrintFloat(*(float*)ptr);
4598 exp.type = constantExp;
4603 FreeExpContents(exp);
4605 exp.constant = PrintDouble(*(double*)ptr);
4606 exp.type = constantExp;
4611 FreeExpContents(exp);
4613 exp.constant = PrintInt(*(int*)ptr);
4614 exp.type = constantExp;
4619 FreeExpContents(exp);
4621 exp.constant = PrintInt64(*(int64*)ptr);
4622 exp.type = constantExp;
4627 FreeExpContents(exp);
4628 // TODO: This should probably use proper type
4629 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4630 exp.type = constantExp;
4635 FreeExpContents(exp);
4636 // TODO: This should probably use proper type
4637 exp.constant = PrintInt64((int64)*(intsize*)ptr);
4638 exp.type = constantExp;
4642 Compiler_Error($"Unhandled type populating instance\n");
4645 ListAdd(memberList, member);
4648 if(parentDataMember.type == unionMember)
4653 void PopulateInstance(Instantiation inst)
4655 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4656 Class _class = classSym.registered;
4657 DataMember dataMember;
4658 OldList * memberList = MkList();
4659 // Added this check and ->Add to prevent memory leaks on bad code
4661 inst.members = MkListOne(MkMembersInitList(memberList));
4663 inst.members->Add(MkMembersInitList(memberList));
4664 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4666 if(!dataMember.isProperty)
4668 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4669 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4673 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4675 void * ptr = inst.data + dataMember.offset;
4676 char * result = null;
4678 exp.loc = member.loc = inst.loc;
4679 ((Identifier)member.identifiers->first).loc = inst.loc;
4681 if(!dataMember.dataType)
4682 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4683 type = dataMember.dataType;
4684 if(type.kind == classType)
4686 Class _class = type._class.registered;
4687 if(_class.type == enumClass)
4689 Class enumClass = eSystem_FindClass(privateModule, "enum");
4692 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4694 for(item = e.values.first; item; item = item.next)
4696 if(item.data == GetEnumValue(_class, ptr))
4705 exp.identifier = MkIdentifier(result);
4706 exp.type = identifierExp;
4707 exp.destType = MkClassType(_class.fullName);
4708 ProcessExpressionType(exp);
4711 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4713 if(!_class.dataType)
4714 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4715 type = _class.dataType;
4724 exp.constant = PrintFloat(*(float*)ptr);
4725 exp.type = constantExp;
4730 exp.constant = PrintDouble(*(double*)ptr);
4731 exp.type = constantExp;
4736 exp.constant = PrintInt(*(int*)ptr);
4737 exp.type = constantExp;
4742 exp.constant = PrintInt64(*(int64*)ptr);
4743 exp.type = constantExp;
4748 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4749 exp.type = constantExp;
4753 Compiler_Error($"Unhandled type populating instance\n");
4756 ListAdd(memberList, member);
4762 void ComputeInstantiation(Expression exp)
4764 Instantiation inst = exp.instance;
4765 MembersInit members;
4766 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4767 Class _class = classSym ? classSym.registered : null;
4768 DataMember curMember = null;
4769 Class curClass = null;
4770 DataMember subMemberStack[256];
4771 int subMemberStackPos = 0;
4774 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4776 // Don't recompute the instantiation...
4777 // Non Simple classes will have become constants by now
4781 if(_class.type == normalClass || _class.type == noHeadClass)
4783 inst.data = (byte *)eInstance_New(_class);
4784 if(_class.type == normalClass)
4785 ((Instance)inst.data)._refCount++;
4788 inst.data = new0 byte[_class.structSize];
4793 for(members = inst.members->first; members; members = members.next)
4795 switch(members.type)
4797 case dataMembersInit:
4799 if(members.dataMembers)
4802 for(member = members.dataMembers->first; member; member = member.next)
4804 Identifier ident = member.identifiers ? member.identifiers->first : null;
4807 Property prop = null;
4808 DataMember dataMember = null;
4809 uint dataMemberOffset;
4813 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4816 if(curMember.isProperty)
4817 prop = (Property)curMember;
4820 dataMember = curMember;
4822 // CHANGED THIS HERE
4823 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4825 // 2013/17/29 -- It seems that this was missing here!
4826 if(_class.type == normalClass)
4827 dataMemberOffset += _class.base.structSize;
4828 // dataMemberOffset = dataMember.offset;
4835 prop = eClass_FindProperty(_class, ident.string, privateModule);
4839 if(prop.memberAccess == publicAccess)
4841 curMember = (DataMember)prop;
4842 curClass = prop._class;
4847 DataMember _subMemberStack[256];
4848 int _subMemberStackPos = 0;
4850 // FILL MEMBER STACK
4851 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
4856 if(dataMember.memberAccess == publicAccess)
4858 curMember = dataMember;
4859 curClass = dataMember._class;
4860 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
4861 subMemberStackPos = _subMemberStackPos;
4867 if(found && member.initializer && member.initializer.type == expInitializer)
4869 Expression value = member.initializer.exp;
4871 bool deepMember = false;
4874 type = prop.dataType;
4878 if(!dataMember.dataType)
4879 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4881 type = dataMember.dataType;
4884 if(ident && ident.next)
4888 // for(; ident && type; ident = ident.next)
4889 for(ident = ident.next; ident && type; ident = ident.next)
4891 if(type.kind == classType)
4893 prop = eClass_FindProperty(type._class.registered,
4894 ident.string, privateModule);
4896 type = prop.dataType;
4899 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
4900 ident.string, &dataMemberOffset, privateModule, null, null);
4902 type = dataMember.dataType;
4905 else if(type.kind == structType || type.kind == unionType)
4908 for(memberType = type.members.first; memberType; memberType = memberType.next)
4910 if(!strcmp(memberType.name, ident.string))
4921 FreeType(value.destType);
4922 value.destType = type;
4923 if(type) type.refCount++;
4924 ComputeExpression(value);
4926 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
4928 if(type.kind == classType)
4930 Class _class = type._class.registered;
4931 if(_class && (_class.type == bitClass || _class.type == unitClass || _class.type == enumClass))
4933 if(!_class.dataType)
4934 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4935 type = _class.dataType;
4941 void * ptr = inst.data + dataMemberOffset;
4943 if(value.type == constantExp)
4949 GetInt(value, (int*)ptr);
4954 GetInt64(value, (int64*)ptr);
4959 GetIntPtr(value, (intptr*)ptr);
4964 GetIntSize(value, (intsize*)ptr);
4969 GetFloat(value, (float*)ptr);
4974 GetDouble(value, (double *)ptr);
4979 else if(value.type == instanceExp)
4981 if(type.kind == classType)
4983 Class _class = type._class.registered;
4984 if(_class.type == structClass)
4986 ComputeTypeSize(type);
4987 if(value.instance.data)
4988 memcpy(ptr, value.instance.data, type.size);
4993 else if(prop && prop.Set != (void *)(intptr)1)
4995 if(value.type == instanceExp && value.instance.data)
4997 if(type.kind == classType)
4999 Class _class = type._class.registered;
5000 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5002 void (*Set)(void *, void *) = (void *)prop.Set;
5003 Set(inst.data, value.instance.data);
5004 PopulateInstance(inst);
5008 else if(value.type == constantExp)
5014 void (*Set)(void *, double) = (void *)prop.Set;
5015 Set(inst.data, strtod(value.constant, null) );
5020 void (*Set)(void *, float) = (void *)prop.Set;
5021 Set(inst.data, (float)(strtod(value.constant, null)));
5026 void (*Set)(void *, int) = (void *)prop.Set;
5027 Set(inst.data, (int)strtol(value.constant, null, 0));
5032 void (*Set)(void *, int64) = (void *)prop.Set;
5033 Set(inst.data, _strtoi64(value.constant, null, 0));
5038 void (*Set)(void *, intptr) = (void *)prop.Set;
5039 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5044 void (*Set)(void *, intsize) = (void *)prop.Set;
5045 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5050 else if(value.type == stringExp)
5053 ReadString(temp, value.string);
5054 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5058 else if(!deepMember && type && _class.type == unitClass)
5062 // Only support converting units to units for now...
5063 if(value.type == constantExp)
5065 if(type.kind == classType)
5067 Class _class = type._class.registered;
5068 if(_class.type == unitClass)
5070 if(!_class.dataType)
5071 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5072 type = _class.dataType;
5075 // TODO: Assuming same base type for units...
5081 float (*Set)(float) = (void *)prop.Set;
5082 GetFloat(member.initializer.exp, &fValue);
5083 exp.constant = PrintFloat(Set(fValue));
5084 exp.type = constantExp;
5090 double (*Set)(double) = (void *)prop.Set;
5091 GetDouble(member.initializer.exp, &dValue);
5092 exp.constant = PrintDouble(Set(dValue));
5093 exp.type = constantExp;
5100 else if(!deepMember && type && _class.type == bitClass)
5104 if(value.type == instanceExp && value.instance.data)
5106 unsigned int (*Set)(void *) = (void *)prop.Set;
5107 bits = Set(value.instance.data);
5109 else if(value.type == constantExp)
5115 BitMember bitMember = (BitMember) dataMember;
5118 bits = (bits & ~bitMember.mask);
5119 if(!bitMember.dataType)
5120 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5121 type = bitMember.dataType;
5122 if(type.kind == classType && type._class && type._class.registered)
5124 if(!type._class.registered.dataType)
5125 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5126 type = type._class.registered.dataType;
5131 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5132 case shortType: { uint16 v; type.isSigned ? GetShort(value, (short *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5134 case longType: { uint v; type.isSigned ? GetInt(value, (int *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5135 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (int64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5136 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (intptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5137 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (intsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5139 bits |= part << bitMember.pos;
5145 if(_class && _class.type == unitClass)
5147 ComputeExpression(member.initializer.exp);
5148 exp.constant = member.initializer.exp.constant;
5149 exp.type = constantExp;
5151 member.initializer.exp.constant = null;
5161 if(_class && _class.type == bitClass)
5163 exp.constant = PrintHexUInt(bits);
5164 exp.type = constantExp;
5166 if(exp.type != instanceExp)
5172 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5174 bool result = false;
5178 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5179 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5183 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5184 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5187 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5188 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5189 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5192 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5193 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5194 result = GetOpFloat(op, &op.f);
5197 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5198 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5199 result = GetOpDouble(op, &op.d);
5202 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5203 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5204 result = GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5207 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5208 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5209 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5212 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5213 result = isSigned ? GetOpInt64 /*GetOpIntPtr*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5216 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5217 result = isSigned ? GetOpInt64 /*GetOpIntSize*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntSize*/(op, &op.ui64);
5223 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5225 if(exp.op.op == SIZEOF)
5227 FreeExpContents(exp);
5228 exp.type = constantExp;
5229 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5240 // Provide default unary +
5241 Expression exp2 = exp.op.exp2;
5243 FreeExpContents(exp);
5244 FreeType(exp.expType);
5245 FreeType(exp.destType);
5251 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5253 // unary arithmetic increment and decrement
5254 //OPERATOR_ALL(UNARY, ++, Inc)
5255 //OPERATOR_ALL(UNARY, --, Dec)
5258 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5260 // unary logical negation
5262 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5268 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5270 if(Promote(op2, op1.kind, op1.type.isSigned))
5271 op2.kind = op1.kind, op2.ops = op1.ops;
5272 else if(Promote(op1, op2.kind, op2.type.isSigned))
5273 op1.kind = op2.kind, op1.ops = op2.ops;
5277 // binary arithmetic
5279 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5282 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5285 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5288 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5291 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5293 // binary arithmetic assignment
5294 //OPERATOR_ALL(BINARY, =, Asign)
5295 //OPERATOR_ALL(BINARY, +=, AddAsign)
5296 //OPERATOR_ALL(BINARY, -=, SubAsign)
5297 //OPERATOR_ALL(BINARY, *=, MulAsign)
5298 //OPERATOR_ALL(BINARY, /=, DivAsign)
5299 //OPERATOR_ALL(BINARY, %=, ModAsign)
5304 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5308 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5311 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5314 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5317 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5319 // binary bitwise assignment
5320 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5321 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5322 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5323 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5324 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5325 // binary logical equality
5327 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5330 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5334 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5337 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5339 // binary logical relational
5341 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5344 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5347 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5350 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5357 void ComputeExpression(Expression exp)
5360 char expString[10240];
5361 expString[0] = '\0';
5362 PrintExpression(exp, expString);
5369 Identifier id = exp.identifier;
5370 if(id && exp.isConstant && !inCompiler && !inPreCompiler && !inDebugger)
5372 Class c = (exp.expType && exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
5373 if(c && c.type == enumClass)
5375 Class enumClass = eSystem_FindClass(privateModule, "enum");
5379 EnumClassData e = ACCESS_CLASSDATA(c, enumClass);
5380 for(value = e.values.first; value; value = value.next)
5382 if(!strcmp(value.name, id.string))
5387 const String dts = c.dataTypeString;
5388 FreeExpContents(exp);
5389 exp.type = constantExp;
5390 exp.constant = (dts && (!strcmp(dts, "int") || !strcmp(dts, "int64") || !strcmp(dts, "short") || !strcmp(dts, "char"))) ? PrintInt64(value.data) : PrintUInt64(value.data);
5399 ComputeInstantiation(exp);
5408 Expression exp1, exp2 = null;
5412 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5415 Expression e = exp.op.exp2;
5417 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5419 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5421 if(e.type == extensionCompoundExp)
5422 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5427 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5429 if(e.type == stringExp && e.string)
5431 char * string = e.string;
5432 int len = strlen(string);
5433 char * tmp = new char[len-2+1];
5434 len = UnescapeString(tmp, string + 1, len - 2);
5436 FreeExpContents(exp);
5437 exp.type = constantExp;
5438 exp.constant = PrintUInt(len + 1);
5442 Type type = e.expType;
5444 FreeExpContents(exp);
5445 exp.type = constantExp;
5446 exp.constant = PrintUInt(ComputeTypeSize(type));
5452 ComputeExpression(exp.op.exp2);
5456 ComputeExpression(exp.op.exp1);
5459 op1 = GetOperand(exp1);
5460 if(op1.type) op1.type.refCount++;
5463 op2 = GetOperand(exp2);
5464 if(op2.type) op2.type.refCount++;
5470 op1 = GetOperand(exp1);
5471 if(op1.type) op1.type.refCount++;
5474 CallOperator(exp, exp1, exp2, op1, op2);
5481 if(exp.op.exp1 && exp.op.exp2)
5486 FreeExpContents(exp);
5487 op1.ops.BitAnd(exp, op1, op2);
5496 FreeExpContents(exp);
5497 op1.ops.Mul(exp, op1, op2);
5506 FreeExpContents(exp);
5507 op1.ops.Add(exp, op1, op2);
5512 // Provide default unary +
5513 Expression exp2 = exp.op.exp2;
5515 FreeExpContents(exp);
5516 FreeType(exp.expType);
5517 FreeType(exp.destType);
5528 FreeExpContents(exp);
5529 op1.ops.Sub(exp, op1, op2);
5536 FreeExpContents(exp);
5537 op1.ops.Neg(exp, op1);
5544 FreeExpContents(exp);
5545 op1.ops.BitNot(exp, op1);
5551 FreeExpContents(exp);
5552 op1.ops.Not(exp, op1);
5555 // Binary only operators
5559 FreeExpContents(exp);
5560 op1.ops.Div(exp, op1, op2);
5566 FreeExpContents(exp);
5567 op1.ops.Mod(exp, op1, op2);
5579 FreeExpContents(exp);
5580 op1.ops.Sma(exp, op1, op2);
5589 FreeExpContents(exp);
5590 op1.ops.Grt(exp, op1, op2);
5599 FreeExpContents(exp);
5600 op1.ops.SmaEqu(exp, op1, op2);
5609 FreeExpContents(exp);
5610 op1.ops.GrtEqu(exp, op1, op2);
5619 FreeExpContents(exp);
5620 op1.ops.Equ(exp, op1, op2);
5629 FreeExpContents(exp);
5630 op1.ops.Nqu(exp, op1, op2);
5637 FreeExpContents(exp);
5638 op1.ops.BitOr(exp, op1, op2);
5644 FreeExpContents(exp);
5645 op1.ops.BitXor(exp, op1, op2);
5653 FreeExpContents(exp);
5654 exp.type = constantExp;
5655 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5659 if(op1.type) FreeType(op1.type);
5660 if(op2.type) FreeType(op2.type);
5664 case extensionExpressionExp:
5667 for(e = exp.list->first; e; e = n)
5672 OldList * list = exp.list;
5673 Expression prev = exp.prev;
5674 Expression next = exp.next;
5675 ComputeExpression(e);
5676 //FreeExpContents(exp);
5677 FreeType(exp.expType);
5678 FreeType(exp.destType);
5697 exp.isConstant = true;
5699 ComputeExpression(exp.index.exp);
5700 if(!exp.index.exp.isConstant)
5701 exp.isConstant = false;
5703 for(e = exp.index.index->first; e; e = e.next)
5705 ComputeExpression(e);
5708 // Check if this type is int
5711 exp.isConstant = false;
5713 exp.expType = Dereference(exp.index.exp.expType);
5719 Expression memberExp = exp.member.exp;
5720 Identifier memberID = exp.member.member;
5723 ComputeExpression(exp.member.exp);
5724 type = exp.member.exp.expType;
5727 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);
5728 Property prop = null;
5729 DataMember member = null;
5730 Class convertTo = null;
5731 if(type.kind == subClassType && exp.member.exp.type == classExp)
5732 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5739 PrintTypeNoConst(type, string, false, true);
5740 classSym = FindClass(string);
5741 _class = classSym ? classSym.registered : null;
5744 if(exp.member.member)
5746 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5748 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5750 if(!prop && !member && _class && exp.member.member)
5752 Symbol classSym = FindClass(exp.member.member.string);
5754 _class = classSym ? classSym.registered : null;
5755 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5762 Type type = prop.dataType;
5763 // TODO: Assuming same base type for units...
5764 if(_class.type == unitClass)
5766 if(type.kind == classType)
5768 Class _class = type._class.registered;
5769 if(_class.type == unitClass)
5771 if(!_class.dataType)
5772 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5773 type = _class.dataType;
5781 float (*Get)(float) = (void *)prop.Get;
5782 GetFloat(exp.member.exp, &value);
5783 exp.constant = PrintFloat(Get ? Get(value) : value);
5784 exp.type = constantExp;
5790 double (*Get)(double);
5791 GetDouble(exp.member.exp, &value);
5794 Get = (void *)prop.Set;
5796 Get = (void *)prop.Get;
5797 exp.constant = PrintDouble(Get ? Get(value) : value);
5798 exp.type = constantExp;
5807 Expression value = exp.member.exp;
5810 ProcessPropertyType(prop);
5812 type = prop.dataType;
5815 // printf("Investigate this\n");
5817 else if(_class.type == structClass)
5823 Class propertyClass = type._class.registered;
5824 if(propertyClass.type == structClass && value.type == instanceExp)
5826 void (*Set)(void *, void *) = (void *)prop.Set;
5827 exp.instance = Instantiation { };
5828 exp.instance.data = new0 byte[_class.structSize];
5829 exp.instance._class = MkSpecifierName(_class.fullName);
5830 exp.instance.loc = exp.loc;
5831 exp.type = instanceExp;
5832 Set(exp.instance.data, value.instance.data);
5833 PopulateInstance(exp.instance);
5840 void (*Set)(void *, int) = (void *)prop.Set;
5842 exp.instance = Instantiation { };
5843 exp.instance.data = new0 byte[_class.structSize];
5844 exp.instance._class = MkSpecifierName(_class.fullName);
5845 exp.instance.loc = exp.loc;
5846 exp.type = instanceExp;
5848 GetInt(value, &intValue);
5850 Set(exp.instance.data, intValue);
5851 PopulateInstance(exp.instance);
5857 void (*Set)(void *, int64) = (void *)prop.Set;
5859 exp.instance = Instantiation { };
5860 exp.instance.data = new0 byte[_class.structSize];
5861 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
5862 exp.instance.loc = exp.loc;
5863 exp.type = instanceExp;
5865 GetInt64(value, &intValue);
5867 Set(exp.instance.data, intValue);
5868 PopulateInstance(exp.instance);
5875 void (*Set)(void *, intptr) = (void *)prop.Set;
5877 exp.instance = Instantiation { };
5878 exp.instance.data = new0 byte[_class.structSize];
5879 exp.instance._class = MkSpecifierName(_class.fullName);
5880 exp.instance.loc = exp.loc;
5881 exp.type = instanceExp;
5883 GetIntPtr(value, &intValue);
5885 Set(exp.instance.data, intValue);
5886 PopulateInstance(exp.instance);
5893 void (*Set)(void *, intsize) = (void *)prop.Set;
5895 exp.instance = Instantiation { };
5896 exp.instance.data = new0 byte[_class.structSize];
5897 exp.instance._class = MkSpecifierName(_class.fullName);
5898 exp.instance.loc = exp.loc;
5899 exp.type = instanceExp;
5901 GetIntSize(value, &intValue);
5903 Set(exp.instance.data, intValue);
5904 PopulateInstance(exp.instance);
5910 void (*Set)(void *, float) = (void *)prop.Set;
5912 exp.instance = Instantiation { };
5913 exp.instance.data = new0 byte[_class.structSize];
5914 exp.instance._class = MkSpecifierName(_class.fullName);
5915 exp.instance.loc = exp.loc;
5916 exp.type = instanceExp;
5918 GetFloat(value, &floatValue);
5920 Set(exp.instance.data, floatValue);
5921 PopulateInstance(exp.instance);
5927 void (*Set)(void *, double) = (void *)prop.Set;
5929 exp.instance = Instantiation { };
5930 exp.instance.data = new0 byte[_class.structSize];
5931 exp.instance._class = MkSpecifierName(_class.fullName);
5932 exp.instance.loc = exp.loc;
5933 exp.type = instanceExp;
5935 GetDouble(value, &doubleValue);
5937 Set(exp.instance.data, doubleValue);
5938 PopulateInstance(exp.instance);
5943 else if(_class.type == bitClass)
5949 Class propertyClass = type._class.registered;
5950 if(propertyClass.type == structClass && value.instance.data)
5952 unsigned int (*Set)(void *) = (void *)prop.Set;
5953 unsigned int bits = Set(value.instance.data);
5954 exp.constant = PrintHexUInt(bits);
5955 exp.type = constantExp;
5958 else if(_class.type == bitClass)
5961 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
5964 GetUInt(exp.member.exp, &value);
5966 exp.constant = PrintHexUInt(bits);
5967 exp.type = constantExp;
5975 if(_class.type == bitClass)
5978 GetUInt(exp.member.exp, &value);
5984 Class _class = type._class.registered;
5985 if(_class.type == structClass)
5987 void (*Get)(unsigned int, void *) = (void *)prop.Get;
5989 exp.instance = Instantiation { };
5990 exp.instance.data = new0 byte[_class.structSize];
5991 exp.instance._class = MkSpecifierName(_class.fullName);
5992 exp.instance.loc = exp.loc;
5993 //exp.instance.fullSet = true;
5994 exp.type = instanceExp;
5995 Get(value, exp.instance.data);
5996 PopulateInstance(exp.instance);
5998 else if(_class.type == bitClass)
6000 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6001 uint64 bits = Get(value);
6002 exp.constant = PrintHexUInt64(bits);
6003 exp.type = constantExp;
6009 else if(_class.type == structClass)
6011 byte * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6016 Class _class = type._class.registered;
6017 if(_class.type == structClass && value)
6019 void (*Get)(void *, void *) = (void *)prop.Get;
6021 exp.instance = Instantiation { };
6022 exp.instance.data = new0 byte[_class.structSize];
6023 exp.instance._class = MkSpecifierName(_class.fullName);
6024 exp.instance.loc = exp.loc;
6025 //exp.instance.fullSet = true;
6026 exp.type = instanceExp;
6027 Get(value, exp.instance.data);
6028 PopulateInstance(exp.instance);
6036 char * value = exp.member.exp.instance.data;
6041 Class _class = type._class.registered;
6042 if(_class.type == normalClass)
6044 void *(*Get)(void *) = (void *)prop.Get;
6046 exp.instance = Instantiation { };
6047 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6048 exp.type = instanceExp;
6049 exp.instance.data = Get(value, exp.instance.data);
6061 exp.isConstant = false;
6069 if(exp.type != ExpressionType::memberExp)
6071 FreeExpression(memberExp);
6072 FreeIdentifier(memberID);
6078 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6079 FreeExpContents(exp);
6080 exp.constant = PrintUInt(ComputeTypeSize(type));
6081 exp.type = constantExp;
6087 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6088 if(classSym && classSym.registered)
6090 if(classSym.registered.fixed)
6092 FreeSpecifier(exp._class);
6093 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6094 exp.type = constantExp;
6098 char className[1024];
6099 strcpy(className, "__ecereClass_");
6100 FullClassNameCat(className, classSym.string, true);
6102 DeclareClass(curExternal, classSym, className);
6104 FreeExpContents(exp);
6105 exp.type = pointerExp;
6106 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6107 exp.member.member = MkIdentifier("structSize");
6117 if(exp.type == castExp)
6120 ComputeExpression(exp.cast.exp);
6123 if(e && exp.expType)
6126 type = exp.destType;
6129 if(type.kind == classType)
6131 Class _class = type._class.registered;
6132 if(_class && (_class.type == unitClass || _class.type == bitClass))
6134 if(!_class.dataType)
6135 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6136 type = _class.dataType;
6147 if(GetChar(e, &value))
6149 FreeExpContents(exp);
6150 exp.constant = PrintChar(value);
6151 exp.type = constantExp;
6156 unsigned char value = 0;
6157 if(GetUChar(e, &value))
6159 FreeExpContents(exp);
6160 exp.constant = PrintUChar(value);
6161 exp.type = constantExp;
6169 if(GetShort(e, &value))
6171 FreeExpContents(exp);
6172 exp.constant = PrintShort(value);
6173 exp.type = constantExp;
6178 unsigned short value = 0;
6179 if(GetUShort(e, &value))
6181 FreeExpContents(exp);
6182 exp.constant = PrintUShort(value);
6183 exp.type = constantExp;
6191 if(GetInt(e, &value))
6193 FreeExpContents(exp);
6194 exp.constant = PrintInt(value);
6195 exp.type = constantExp;
6200 unsigned int value = 0;
6201 if(GetUInt(e, &value))
6203 FreeExpContents(exp);
6204 exp.constant = PrintUInt(value);
6205 exp.type = constantExp;
6213 if(GetInt64(e, &value))
6215 FreeExpContents(exp);
6216 exp.constant = PrintInt64(value);
6217 exp.type = constantExp;
6223 if(GetUInt64(e, &value))
6225 FreeExpContents(exp);
6226 exp.constant = PrintUInt64(value);
6227 exp.type = constantExp;
6235 if(GetIntPtr(e, &value))
6237 FreeExpContents(exp);
6238 exp.constant = PrintInt64((int64)value);
6239 exp.type = constantExp;
6245 if(GetUIntPtr(e, &value))
6247 FreeExpContents(exp);
6248 exp.constant = PrintUInt64((uint64)value);
6249 exp.type = constantExp;
6257 if(GetIntSize(e, &value))
6259 FreeExpContents(exp);
6260 exp.constant = PrintInt64((int64)value);
6261 exp.type = constantExp;
6267 if(GetUIntSize(e, &value))
6269 FreeExpContents(exp);
6270 exp.constant = PrintUInt64((uint64)value);
6271 exp.type = constantExp;
6278 if(GetFloat(e, &value))
6280 FreeExpContents(exp);
6281 exp.constant = PrintFloat(value);
6282 exp.type = constantExp;
6289 if(GetDouble(e, &value))
6291 FreeExpContents(exp);
6292 exp.constant = PrintDouble(value);
6293 exp.type = constantExp;
6308 // Caring only about last expression for now...
6309 ComputeExpression(exp.cond.exp->last);
6310 if(exp.cond.elseExp)
6311 ComputeExpression(exp.cond.elseExp);
6313 ComputeExpression(exp.cond.cond);
6315 op1 = GetOperand(exp.cond.cond);
6316 if(op1.type) op1.type.refCount++;
6317 op2 = GetOperand(exp.cond.exp->last);
6318 if(op2.type) op2.type.refCount++;
6319 op3 = GetOperand(exp.cond.elseExp);
6320 if(op3.type) op3.type.refCount++;
6322 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6323 if(op1.type) FreeType(op1.type);
6324 if(op2.type) FreeType(op2.type);
6325 if(op3.type) FreeType(op3.type);
6331 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6336 OldList converts { };
6339 if(destType.kind == voidType)
6342 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6346 // for(convert = converts.last; convert; convert = convert.prev)
6347 for(convert = converts.first; convert; convert = convert.next)
6349 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6352 Expression newExp { };
6353 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6355 // TODO: Check this...
6359 newExp.destType = null;
6364 exp.type = memberExp;
6365 exp.addedThis = true;
6366 exp.member.exp = newExp;
6367 FreeType(exp.member.exp.expType);
6369 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6370 exp.member.exp.expType.classObjectType = objectType;
6371 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6372 exp.member.memberType = propertyMember;
6373 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6374 // TESTING THIS... for (int)degrees
6375 exp.needCast = true;
6376 if(exp.expType) exp.expType.refCount++;
6377 ApplyAnyObjectLogic(exp.member.exp);
6382 /*if(exp.isConstant)
6384 // Color { ColorRGB = [exp] };
6385 exp.type = instanceExp;
6386 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6387 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6388 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6392 // If not constant, don't turn it yet into an instantiation
6393 // (Go through the deep members system first)
6394 exp.type = memberExp;
6395 exp.addedThis = true;
6396 exp.member.exp = newExp;
6398 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6399 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6400 newExp.expType._class.registered.type == noHeadClass)
6402 newExp.byReference = true;
6405 FreeType(exp.member.exp.expType);
6406 /*exp.member.exp.expType = convert.convert.dataType;
6407 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6408 exp.member.exp.expType = null;
6409 if(convert.convert.dataType)
6411 exp.member.exp.expType = { };
6412 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6413 exp.member.exp.expType.refCount = 1;
6414 exp.member.exp.expType.classObjectType = objectType;
6415 ApplyAnyObjectLogic(exp.member.exp);
6418 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6419 exp.member.memberType = reverseConversionMember;
6420 exp.expType = convert.resultType ? convert.resultType :
6421 MkClassType(convert.convert._class.fullName);
6422 exp.needCast = true;
6423 if(convert.resultType) convert.resultType.refCount++;
6429 FreeType(exp.expType);
6432 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6433 if(exp.destType.casted)
6434 exp.needCast = true;
6435 if(exp.expType) exp.expType.refCount++;
6439 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6440 if(exp.destType.casted)
6441 exp.needCast = true;
6442 if(convert.resultType)
6443 convert.resultType.refCount++;
6447 if(exp.isConstant && inCompiler)
6448 ComputeExpression(exp);
6450 converts.Free(FreeConvert);
6453 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6455 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6457 if(!result && exp.expType && exp.destType)
6459 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6460 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6461 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6462 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6466 // if(result) CheckTemplateTypes(exp);
6470 void CheckTemplateTypes(Expression exp)
6473 bool et = exp.expType ? exp.expType.passAsTemplate : false;
6474 bool dt = exp.destType ? exp.destType.passAsTemplate : false;
6476 Expression nbExp = GetNonBracketsExp(exp);
6477 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6478 (nbExp == exp || nbExp.type != castExp))
6480 Expression newExp { };
6482 TypeKind kind = exp.expType.kind;
6484 if(exp.destType) exp.destType.refCount++;
6485 if(exp.expType) exp.expType.refCount++;
6489 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6491 Class c = exp.expType._class.registered;
6492 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6495 c.dataType = ProcessTypeString(c.dataTypeString, false);
6496 kind = c.dataType.kind;
6503 if(exp.destType.classObjectType)
6505 // We need to pass the address, just pass it along (Undo what was done above)
6506 if(exp.destType) exp.destType.refCount--;
6507 if(exp.expType) exp.expType.refCount--;
6512 // If we're looking for value:
6513 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6515 OldList * unionDefs = MkList();
6516 OldList * statements = MkList();
6517 context = PushContext();
6518 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6519 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6520 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6521 exp.type = extensionCompoundExp;
6522 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6523 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6524 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6525 exp.compound.compound.context = context;
6526 PopContext(context);
6531 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6532 if((exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass) || exp.expType.isPointerType)
6533 exp.cast.exp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), MkExpBrackets(MkListOne(newExp)));
6535 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6536 exp.needCast = true;
6540 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6542 Expression newExp { };
6544 TypeKind kind = exp.expType.kind;
6546 if(exp.destType) exp.destType.refCount++;
6547 if(exp.expType) exp.expType.refCount++;
6551 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered)
6553 Class c = exp.expType._class.registered;
6554 if(c.type == bitClass || c.type == enumClass || c.type == unitClass)
6557 c.dataType = ProcessTypeString(c.dataTypeString, false);
6558 kind = c.dataType.kind;
6565 if(exp.destType.classObjectType)
6567 // We need to pass the address, just pass it along (Undo what was done above)
6568 if(exp.destType) exp.destType.refCount--;
6569 if(exp.expType) exp.expType.refCount--;
6574 // If we're looking for value:
6575 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6577 OldList * unionDefs = MkList();
6578 OldList * statements = MkList();
6579 context = PushContext();
6580 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6581 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6582 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6583 exp.type = extensionCompoundExp;
6584 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6585 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6586 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6587 exp.compound.compound.context = context;
6588 PopContext(context);
6593 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6595 exp.type = bracketsExp;
6597 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6598 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6599 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6600 ProcessExpressionType(exp.list->first);
6605 exp.type = bracketsExp;
6606 if(exp.expType.isPointerType)
6608 exp.needTemplateCast = 2;
6609 newExp.needCast = true;
6610 newExp.needTemplateCast = 2;
6611 newExp = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), newExp);
6614 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6615 exp.needTemplateCast = 2;
6616 newExp.needCast = true;
6617 newExp.needTemplateCast = 2;
6618 ProcessExpressionType(exp.list->first);
6624 if(exp.expType.kind == templateType)
6626 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6629 FreeType(exp.destType);
6630 FreeType(exp.expType);
6635 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6640 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6641 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6645 char typeString[1024];
6647 OldList * specs = MkList();
6648 typeString[0] = '\0';
6649 PrintType(exp.expType, typeString, false, false);
6650 decl = SpecDeclFromString(typeString, specs, null);
6653 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6654 exp.cast.typeName = MkTypeName(specs, decl);
6655 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6656 exp.cast.exp.needCast = true;
6663 // TODO: The Symbol tree should be reorganized by namespaces
6665 // - Tree of all symbols within (stored without namespace)
6666 // - Tree of sub-namespaces
6668 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6670 int nsLen = strlen(nameSpace);
6672 // Start at the name space prefix
6673 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6675 char * s = symbol.string;
6676 if(!strncmp(s, nameSpace, nsLen))
6678 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6681 for(c = strlen(s)-1; c >= 0; c--)
6686 if(!strcmp(namePart, name))
6688 // TODO: Error on ambiguity
6698 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6701 char nameSpace[1024];
6702 const char * namePart;
6703 bool gotColon = false;
6705 nameSpace[0] = '\0';
6706 for(c = strlen(name)-1; c >= 0; c--)
6713 namePart = name+c+1;
6714 while(c >= 0 && name[c] == ':') c--;
6717 // Try an exact match first
6718 Symbol symbol = (Symbol)tree.FindString(name);
6722 // Namespace specified
6723 memcpy(nameSpace, name, c + 1);
6726 return ScanWithNameSpace(tree, nameSpace, namePart);
6730 // Looking for a global symbol, e.g. ::Sleep()
6731 Symbol symbol = (Symbol)tree.FindString(namePart);
6736 // Name only (no namespace specified)
6737 Symbol symbol = (Symbol)tree.FindString(namePart);
6740 return ScanWithNameSpace(tree, "", namePart);
6745 static void ProcessDeclaration(Declaration decl);
6747 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6750 //Time startTime = GetTime();
6752 // Optimize this later? Do this before/less?
6754 Symbol symbol = null;
6756 // First, check if the identifier is declared inside the function
6757 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6759 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6761 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6767 strcpy(curName, thisNameSpace);
6768 strcat(curName, "::");
6769 strcat(curName, name);
6770 // Try to resolve in current namespace first
6771 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6774 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6777 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6779 if(symbol || ctx == endContext) break;
6781 if(inCompiler && symbol && ctx == globalContext && symbol.pointerExternal && curExternal && symbol.pointerExternal != curExternal)
6782 curExternal.CreateUniqueEdge(symbol.pointerExternal, symbol.pointerExternal.type == functionExternal);
6784 //findSymbolTotalTime += GetTime() - startTime;
6789 static void GetTypeSpecs(Type type, OldList * specs)
6791 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6796 if(type._class.registered)
6798 if(!type._class.registered.dataType)
6799 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6800 GetTypeSpecs(type._class.registered.dataType, specs);
6804 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6805 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6806 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6807 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6808 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6809 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6810 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6811 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6814 ListAdd(specs, MkSpecifier(INT)); break;
6818 static void PrintArraySize(Type arrayType, char * string)
6823 if(arrayType.enumClass)
6824 strcat(size, arrayType.enumClass.string);
6825 else if(arrayType.arraySizeExp)
6826 PrintExpression(arrayType.arraySizeExp, size);
6828 strcat(string, size);
6831 // WARNING : This function expects a null terminated string since it recursively concatenate...
6832 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6836 if(printConst && type.constant)
6837 strcat(string, "const ");
6842 Symbol c = type._class;
6843 bool isObjectBaseClass = !c || !c.string || !strcmp(c.string, "class");
6844 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6845 // look into merging with thisclass ?
6846 if(type.classObjectType == typedObject && isObjectBaseClass)
6847 strcat(string, "typed_object");
6848 else if(type.classObjectType == anyObject && isObjectBaseClass)
6849 strcat(string, "any_object");
6853 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6855 if(type.byReference)
6856 strcat(string, " &");
6859 case voidType: strcat(string, "void"); break;
6860 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6861 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6862 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6863 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6864 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6865 case _BoolType: strcat(string, "_Bool"); break;
6866 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6867 case floatType: strcat(string, "float"); break;
6868 case doubleType: strcat(string, "double"); break;
6872 strcat(string, "struct ");
6873 strcat(string, type.enumName);
6875 else if(type.typeName)
6876 strcat(string, type.typeName);
6880 strcat(string, "struct { ");
6881 for(member = type.members.first; member; member = member.next)
6883 PrintType(member, string, true, fullName);
6884 strcat(string,"; ");
6892 strcat(string, "union ");
6893 strcat(string, type.enumName);
6895 else if(type.typeName)
6896 strcat(string, type.typeName);
6899 strcat(string, "union ");
6900 strcat(string,"(unnamed)");
6906 strcat(string, "enum ");
6907 strcat(string, type.enumName);
6909 else if(type.typeName)
6910 strcat(string, type.typeName);
6912 strcat(string, "int"); // "enum");
6915 strcat(string, "...");
6918 strcat(string, "subclass(");
6919 strcat(string, type._class ? type._class.string : "int");
6920 strcat(string, ")");
6923 strcat(string, type.templateParameter.identifier.string);
6926 strcat(string, "thisclass");
6929 strcat(string, "__builtin_va_list");
6935 static void PrintName(Type type, char * string, bool fullName)
6937 if(type.name && type.name[0])
6940 strcat(string, type.name);
6943 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
6944 if(name) name += 2; else name = type.name;
6945 strcat(string, name);
6950 static void PrintAttribs(Type type, char * string)
6954 if(type.dllExport) strcat(string, "dllexport ");
6955 if(type.attrStdcall) strcat(string, "stdcall ");
6959 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
6961 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
6963 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
6964 PrintAttribs(type, string);
6965 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
6966 strcat(string, " const");
6967 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
6968 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6969 strcat(string, " (");
6970 if(type.kind == pointerType)
6972 if(type.type.kind == functionType || type.type.kind == methodType)
6973 PrintAttribs(type.type, string);
6975 if(type.kind == pointerType)
6977 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
6978 strcat(string, "*");
6980 strcat(string, " *");
6982 if(printConst && type.constant && type.kind == pointerType)
6983 strcat(string, " const");
6986 PrintTypeSpecs(type, string, fullName, printConst);
6989 static void PostPrintType(Type type, char * string, bool fullName)
6991 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
6992 strcat(string, ")");
6993 if(type.kind == arrayType)
6994 PrintArraySize(type, string);
6995 else if(type.kind == functionType)
6998 strcat(string, "(");
6999 for(param = type.params.first; param; param = param.next)
7001 PrintType(param, string, true, fullName);
7002 if(param.next) strcat(string, ", ");
7004 strcat(string, ")");
7006 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7007 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7011 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7013 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7015 PrePrintType(type, string, fullName, null, printConst);
7017 if(type.thisClass || (printName && type.name && type.name[0]))
7018 strcat(string, " ");
7019 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7021 Symbol _class = type.thisClass;
7022 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7024 if(type.classObjectType == classPointer)
7025 strcat(string, "class");
7027 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7029 else if(_class && _class.string)
7031 String s = _class.string;
7036 char * name = RSearchString(s, "::", strlen(s), true, false);
7037 if(name) name += 2; else name = s;
7038 strcat(string, name);
7041 strcat(string, "::");
7044 if(printName && type.name)
7045 PrintName(type, string, fullName);
7046 PostPrintType(type, string, fullName);
7047 if(type.bitFieldCount)
7050 sprintf(count, ":%d", type.bitFieldCount);
7051 strcat(string, count);
7055 void PrintType(Type type, char * string, bool printName, bool fullName)
7057 _PrintType(type, string, printName, fullName, true);
7060 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7062 _PrintType(type, string, printName, fullName, false);
7065 static Type FindMember(Type type, char * string)
7068 for(memberType = type.members.first; memberType; memberType = memberType.next)
7070 if(!memberType.name)
7072 Type subType = FindMember(memberType, string);
7076 else if(!strcmp(memberType.name, string))
7082 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7085 for(memberType = type.members.first; memberType; memberType = memberType.next)
7087 if(!memberType.name)
7089 Type subType = FindMember(memberType, string);
7092 *offset += memberType.offset;
7096 else if(!strcmp(memberType.name, string))
7098 *offset += memberType.offset;
7105 public bool GetParseError() { return parseError; }
7107 Expression ParseExpressionString(char * expression)
7111 fileInput = TempFile { };
7112 fileInput.Write(expression, 1, strlen(expression));
7113 fileInput.Seek(0, start);
7116 parsedExpression = null;
7118 expression_yyparse();
7121 return parsedExpression;
7124 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7126 Identifier id = exp.identifier;
7127 Method method = null;
7128 Property prop = null;
7129 DataMember member = null;
7130 ClassProperty classProp = null;
7132 if(_class && _class.type == enumClass)
7134 NamedLink64 value = null;
7135 Class enumClass = eSystem_FindClass(privateModule, "enum");
7139 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7141 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7142 for(value = e.values.first; value; value = value.next)
7144 if(!strcmp(value.name, id.string))
7149 exp.isConstant = true;
7150 if(inCompiler || inPreCompiler || inDebugger)
7153 FreeExpContents(exp);
7155 exp.type = constantExp;
7156 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "char") || !strcmp(baseClass.dataTypeString, "short"))
7157 sprintf(constant, FORMAT64D, value.data);
7159 sprintf(constant, FORMAT64HEX, value.data);
7160 exp.constant = CopyString(constant);
7162 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7163 exp.expType = MkClassType(baseClass.fullName);
7171 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7173 ProcessMethodType(method);
7180 // TOCHECK: Put it back to what it was...
7181 // methodClass = _class;
7182 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7187 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7190 ProcessPropertyType(prop);
7191 exp.expType = prop.dataType;
7192 if(prop.dataType) prop.dataType.refCount++;
7195 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7197 if(!member.dataType)
7198 member.dataType = ProcessTypeString(member.dataTypeString, false);
7199 exp.expType = member.dataType;
7200 if(member.dataType) member.dataType.refCount++;
7203 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7205 if(!classProp.dataType)
7206 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7208 if(classProp.constant)
7210 FreeExpContents(exp);
7212 exp.isConstant = true;
7213 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7215 //char constant[256];
7216 exp.type = stringExp;
7217 exp.constant = QMkString((char *)(uintptr)classProp.Get(_class));
7222 exp.type = constantExp;
7223 sprintf(constant, "%d", (int)classProp.Get(_class));
7224 exp.constant = CopyString(constant);
7232 exp.expType = classProp.dataType;
7233 if(classProp.dataType) classProp.dataType.refCount++;
7239 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7241 BinaryTree * tree = &nameSpace.functions;
7242 GlobalData data = (GlobalData)tree->FindString(name);
7246 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7248 data = ScanGlobalData(child, name);
7256 static GlobalData FindGlobalData(char * name)
7259 NameSpace * nameSpace;
7260 nameSpace = globalData;
7261 for(c = 0; name[c]; c++)
7263 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7265 NameSpace * newSpace;
7266 char * spaceName = new char[c - start + 1];
7267 strncpy(spaceName, name + start, c - start);
7268 spaceName[c-start] = '\0';
7269 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7273 nameSpace = newSpace;
7274 if(name[c] == ':') c++;
7280 return ScanGlobalData(nameSpace, name + start);
7285 static int definedExpStackPos;
7286 static void * definedExpStack[512];
7288 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7289 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7291 Expression prev = checkedExp.prev, next = checkedExp.next;
7293 FreeExpContents(checkedExp);
7294 FreeType(checkedExp.expType);
7295 FreeType(checkedExp.destType);
7297 *checkedExp = *newExp;
7301 checkedExp.prev = prev;
7302 checkedExp.next = next;
7305 void ApplyAnyObjectLogic(Expression e)
7307 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7309 char debugExpString[4096];
7310 debugExpString[0] = '\0';
7311 PrintExpression(e, debugExpString);
7314 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7316 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7317 //ellipsisDestType = destType;
7320 Type type = e.expType;
7321 Class _class = null;
7322 //Type destType = e.destType;
7324 if(type.kind == classType && type._class && type._class.registered)
7326 _class = type._class.registered;
7328 else if(type.kind == subClassType)
7330 _class = FindClass("ecere::com::Class").registered;
7334 char string[1024] = "";
7337 PrintTypeNoConst(type, string, false, true);
7338 classSym = FindClass(string);
7339 if(classSym) _class = classSym.registered;
7342 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...
7343 (!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))) ||
7344 destType.byReference)))
7346 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7348 Expression checkedExp = e, newExp;
7350 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7352 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7354 if(checkedExp.type == extensionCompoundExp)
7356 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7359 checkedExp = checkedExp.list->last;
7361 else if(checkedExp.type == castExp)
7362 checkedExp = checkedExp.cast.exp;
7365 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7367 newExp = checkedExp.op.exp2;
7368 checkedExp.op.exp2 = null;
7369 FreeExpContents(checkedExp);
7371 if(e.expType && e.expType.passAsTemplate)
7374 ComputeTypeSize(e.expType);
7375 sprintf(size, "%d", e.expType.size); // Potential 32/64 Bootstrap issue
7376 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7377 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7378 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7381 ReplaceExpContents(checkedExp, newExp);
7382 e.byReference = true;
7384 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7386 Expression checkedExp; //, newExp;
7389 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7391 e.type == identifierExp ||
7392 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7393 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7394 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7397 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7399 Context context = PushContext();
7401 OldList * specs = MkList();
7402 char typeString[1024];
7403 Expression newExp { };
7405 typeString[0] = '\0';
7408 //if(e.destType) e.destType.refCount++;
7409 // if(exp.expType) exp.expType.refCount++;
7412 newExp.expType = null;
7414 PrintTypeNoConst(e.expType, typeString, false, true);
7415 decl = SpecDeclFromString(typeString, specs, null);
7416 newExp.destType = ProcessType(specs, decl);
7418 curContext = context;
7420 // We need a current compound for this
7424 OldList * stmts = MkList();
7425 e.type = extensionCompoundExp;
7426 sprintf(name, "__internalValue%03X", internalValueCounter++);
7427 if(!curCompound.compound.declarations)
7428 curCompound.compound.declarations = MkList();
7429 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7430 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7431 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7432 e.compound = MkCompoundStmt(null, stmts);
7435 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7438 e.compound = MkCompoundStmt(
7439 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7440 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7442 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7446 Type type = e.destType;
7448 CopyTypeInto(e.destType, type);
7449 e.destType.refCount = 1;
7450 e.destType.classObjectType = none;
7454 e.compound.compound.context = context;
7455 PopContext(context);
7456 curContext = context.parent;
7460 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7462 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7464 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7466 if(checkedExp.type == extensionCompoundExp)
7468 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7471 checkedExp = checkedExp.list->last;
7473 else if(checkedExp.type == castExp)
7474 checkedExp = checkedExp.cast.exp;
7477 Expression operand { };
7478 operand = *checkedExp;
7480 checkedExp.destType = ProcessTypeString("void *", false);
7481 checkedExp.expType = checkedExp.destType;
7482 checkedExp.destType.refCount++;
7484 checkedExp.type = opExp;
7485 checkedExp.op.op = '&';
7486 checkedExp.op.exp1 = null;
7487 checkedExp.op.exp2 = operand;
7489 //newExp = MkExpOp(null, '&', checkedExp);
7491 //ReplaceExpContents(checkedExp, newExp);
7498 // If expression type is a simple class, make it an address
7499 // FixReference(e, true);
7502 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7503 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7504 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7506 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"))
7508 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7512 Expression thisExp { };
7515 thisExp.prev = null;
7516 thisExp.next = null;
7519 e.type = bracketsExp;
7520 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7521 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7522 ((Expression)e.list->first).byReference = true;
7524 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7526 e.expType = thisExp.expType;
7527 e.expType.refCount++;
7532 CopyTypeInto(e.expType, thisExp.expType);
7533 e.expType.byReference = false;
7534 e.expType.refCount = 1;
7536 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7537 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7539 e.expType.classObjectType = none;
7544 // TOFIX: Try this for a nice IDE crash!
7546 // The other way around
7549 if(destType && e.expType &&
7550 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7551 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7552 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7554 if(destType.kind == ellipsisType)
7556 Compiler_Error($"Unspecified type\n");
7558 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7560 bool byReference = e.expType.byReference;
7561 Expression thisExp { };
7563 OldList * specs = MkList();
7564 char typeString[1024]; // Watch buffer overruns
7566 ClassObjectType backupClassObjectType;
7567 bool backupByReference;
7569 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7574 backupClassObjectType = type.classObjectType;
7575 backupByReference = type.byReference;
7577 type.classObjectType = none;
7578 type.byReference = false;
7580 typeString[0] = '\0';
7581 PrintType(type, typeString, false, true);
7582 decl = SpecDeclFromString(typeString, specs, null);
7584 type.classObjectType = backupClassObjectType;
7585 type.byReference = backupByReference;
7588 thisExp.prev = null;
7589 thisExp.next = null;
7592 if( ( type.kind == classType && type._class && type._class.registered &&
7593 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7594 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7595 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7596 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7598 bool passAsTemplate = thisExp.destType.passAsTemplate;
7601 destType.refCount++;
7606 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7609 CopyTypeInto(t, thisExp.destType);
7610 t.passAsTemplate = false;
7611 FreeType(thisExp.destType);
7612 thisExp.destType = t;
7615 CopyTypeInto(t, destType);
7616 t.passAsTemplate = passAsTemplate;
7619 destType.refCount = 0;
7622 CopyTypeInto(e.expType, type);
7623 if(type.passAsTemplate)
7625 e.expType.classObjectType = none;
7626 e.expType.passAsTemplate = false;
7628 e.expType.byReference = false;
7629 e.expType.refCount = 1;
7634 e.cast.typeName = MkTypeName(specs, decl);
7635 e.cast.exp = thisExp;
7636 e.byReference = true;
7642 FreeType(e.destType);
7644 e.destType = destType;
7645 destType.refCount++;
7650 void ApplyLocation(Expression exp, Location loc)
7656 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7657 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7663 for(e = exp.list->first; e; e = e.next)
7664 ApplyLocation(e, loc);
7671 for(e = exp.index.index->first; e; e = e.next)
7672 ApplyLocation(e, loc);
7675 ApplyLocation(exp.index.exp, loc);
7678 if(exp.call.arguments)
7681 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7682 ApplyLocation(arg, loc);
7685 ApplyLocation(exp.call.exp, loc);
7690 ApplyLocation(exp.member.exp, loc);
7694 ApplyLocation(exp.cast.exp, loc);
7700 for(e = exp.cond.exp->first; e; e = e.next)
7701 ApplyLocation(e, loc);
7704 ApplyLocation(exp.cond.cond, loc);
7705 if(exp.cond.elseExp)
7706 ApplyLocation(exp.cond.elseExp, loc);
7710 ApplyLocation(exp.vaArg.exp, loc);
7717 void ProcessExpressionType(Expression exp)
7719 bool unresolved = false;
7720 Location oldyylloc = yylloc;
7721 bool notByReference = false;
7723 char debugExpString[4096];
7724 debugExpString[0] = '\0';
7725 PrintExpression(exp, debugExpString);
7727 if(!exp || exp.expType)
7730 //eSystem_Logf("%s\n", expString);
7732 // Testing this here
7738 Identifier id = exp.identifier;
7739 if(!id || !topContext) return;
7741 // DOING THIS LATER NOW...
7742 if(id._class && id._class.name)
7744 id.classSym = id._class.symbol; // FindClass(id._class.name);
7745 /* TODO: Name Space Fix ups
7747 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7751 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7753 exp.expType = ProcessTypeString("Module", true);
7757 if(!strcmp(id.string, "__runtimePlatform"))
7759 exp.expType = ProcessTypeString("ecere::com::Platform", true);
7762 else if(strstr(id.string, "__ecereClass") == id.string)
7764 exp.expType = ProcessTypeString("ecere::com::Class", true);
7767 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7769 // Added this here as well
7770 ReplaceClassMembers(exp, thisClass);
7771 if(exp.type != identifierExp)
7773 ProcessExpressionType(exp);
7777 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7782 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7783 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7784 if(!symbol/* && exp.destType*/)
7786 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7792 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7793 if(exp.type != identifierExp)
7795 ProcessExpressionType(exp);
7799 // Static methods called from inside the _class
7800 else if(currentClass && !id._class)
7802 if(ResolveIdWithClass(exp, currentClass, true))
7805 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7809 // If we manage to resolve this symbol
7812 Type type = symbol.type;
7813 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7815 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7817 Context context = SetupTemplatesContext(_class);
7818 type = ReplaceThisClassType(_class);
7819 FinishTemplatesContext(context);
7820 if(type) type.refCount = 0; // We'll be incrementing it right below...
7823 FreeSpecifier(id._class);
7826 id.string = CopyString(symbol.string);
7833 // Commented this out, it was making non-constant enum parameters seen as constant
7834 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7835 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7836 // Add missing cases here... enum Classes...
7837 exp.isConstant = true;
7839 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7840 if(symbol.isParam || !strcmp(id.string, "this"))
7842 if(_class && _class.type == structClass && !type.declaredWithStruct)
7843 exp.byReference = true;
7845 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7846 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7847 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7848 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7850 Identifier id = exp.identifier;
7851 exp.type = bracketsExp;
7852 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7856 if(symbol.isIterator)
7858 if(symbol.isIterator == 3)
7860 exp.type = bracketsExp;
7861 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7862 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7864 ProcessExpressionType(exp);
7866 else if(symbol.isIterator != 4)
7868 exp.type = memberExp;
7869 exp.member.exp = MkExpIdentifier(exp.identifier);
7870 exp.member.exp.expType = exp.expType;
7871 /*if(symbol.isIterator == 6)
7872 exp.member.member = MkIdentifier("key");
7874 exp.member.member = MkIdentifier("data");
7876 ProcessExpressionType(exp);
7883 DefinedExpression definedExp = null;
7884 if(thisNameSpace && !(id._class && !id._class.name))
7887 strcpy(name, thisNameSpace);
7889 strcat(name, id.string);
7890 definedExp = eSystem_FindDefine(privateModule, name);
7893 definedExp = eSystem_FindDefine(privateModule, id.string);
7897 for(c = 0; c<definedExpStackPos; c++)
7898 if(definedExpStack[c] == definedExp)
7900 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
7902 Location backupYylloc = yylloc;
7903 File backInput = fileInput;
7904 definedExpStack[definedExpStackPos++] = definedExp;
7906 fileInput = TempFile { };
7907 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
7908 fileInput.Seek(0, start);
7911 parsedExpression = null;
7913 expression_yyparse();
7916 fileInput = backInput;
7918 yylloc = backupYylloc;
7920 if(parsedExpression)
7923 exp.type = bracketsExp;
7924 exp.list = MkListOne(parsedExpression);
7925 ApplyLocation(parsedExpression, yylloc);
7926 ProcessExpressionType(exp);
7927 definedExpStackPos--;
7930 definedExpStackPos--;
7936 Compiler_Error($"Recursion in defined expression %s\n", id.string);
7942 GlobalData data = null;
7943 if(thisNameSpace && !(id._class && !id._class.name))
7946 strcpy(name, thisNameSpace);
7948 strcat(name, id.string);
7949 data = FindGlobalData(name);
7952 data = FindGlobalData(id.string);
7955 DeclareGlobalData(curExternal, data);
7956 exp.expType = data.dataType;
7957 if(data.dataType) data.dataType.refCount++;
7960 id.string = CopyString(data.fullName);
7961 FreeSpecifier(id._class);
7968 GlobalFunction function = null;
7969 if(thisNameSpace && !(id._class && !id._class.name))
7972 strcpy(name, thisNameSpace);
7974 strcat(name, id.string);
7975 function = eSystem_FindFunction(privateModule, name);
7978 function = eSystem_FindFunction(privateModule, id.string);
7983 id.string = CopyString(function.name);
7986 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
7987 strcpy(name, "__ecereFunction_");
7988 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
7989 if(DeclareFunction(curExternal, function, name))
7992 id.string = CopyString(name);
7994 exp.expType = function.dataType;
7995 if(function.dataType) function.dataType.refCount++;
7997 FreeSpecifier(id._class);
8014 if(!exp.instance._class)
8016 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8018 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8022 //classSym = FindClass(exp.instance._class.fullName);
8023 //_class = classSym ? classSym.registered : null;
8025 ProcessInstantiationType(exp.instance);
8027 exp.isConstant = exp.instance.isConstant;
8030 if(_class.type == unitClass && _class.base.type != systemClass)
8033 Type destType = exp.destType;
8035 exp.destType = MkClassType(_class.base.fullName);
8036 exp.expType = MkClassType(_class.fullName);
8037 CheckExpressionType(exp, exp.destType, true);
8039 exp.destType = destType;
8041 exp.expType = MkClassType(_class.fullName);
8044 if(exp.instance._class)
8046 exp.expType = MkClassType(exp.instance._class.name);
8047 /*if(exp.expType._class && exp.expType._class.registered &&
8048 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8049 exp.expType.byReference = true;*/
8057 char * constant = exp.constant;
8065 if(constant[0] == '\'')
8067 if((int)((byte *)constant)[1] > 127)
8070 unichar ch = UTF8GetChar(constant + 1, &nb);
8071 if(nb < 2) ch = constant[1];
8073 exp.constant = PrintUInt(ch);
8074 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8075 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8076 type._class = FindClass("unichar");
8078 type.isSigned = false;
8082 type.kind = charType;
8083 type.isSigned = true;
8088 char * dot = strchr(constant, '.');
8089 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8093 exponent = strchr(constant, 'p');
8094 if(!exponent) exponent = strchr(constant, 'P');
8098 exponent = strchr(constant, 'e');
8099 if(!exponent) exponent = strchr(constant, 'E');
8104 if(strchr(constant, 'f') || strchr(constant, 'F'))
8105 type.kind = floatType;
8107 type.kind = doubleType;
8108 type.isSigned = true;
8112 bool isSigned = constant[0] == '-';
8114 int64 i64 = strtoll(constant, &endP, 0);
8115 uint64 ui64 = strtoull(constant, &endP, 0);
8116 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
8129 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8133 else if(constant[0] != '0' || !constant[1])
8136 type.kind = is64Bit ? int64Type : intType;
8137 type.isSigned = isSigned;
8140 exp.isConstant = true;
8141 if(exp.destType && exp.destType.kind == doubleType)
8142 type.kind = doubleType;
8143 else if(exp.destType && exp.destType.kind == floatType)
8144 type.kind = floatType;
8145 else if(exp.destType && exp.destType.kind == int64Type)
8146 type.kind = int64Type;
8152 exp.isConstant = true; // Why wasn't this constant?
8160 kind = exp.wideString ? shortType : charType;
8162 isSigned = exp.wideString ? false : true;
8169 ProcessExpressionType(exp._new.size);
8174 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8176 DeclareType(curExternal, exp.expType.type, true, false);
8180 ProcessExpressionType(exp._renew.size);
8181 ProcessExpressionType(exp._renew.exp);
8186 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8188 DeclareType(curExternal, exp.expType.type, true, false);
8192 bool assign = false, boolResult = false, boolOps = false;
8193 Type type1 = null, type2 = null;
8194 bool useDestType = false, useSideType = false;
8195 Location oldyylloc = yylloc;
8196 bool useSideUnit = false;
8197 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8199 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8208 // Assignment Operators
8222 // boolean Operators
8224 // Expect boolean operators
8226 //boolResult = true;
8230 // Expect boolean operands
8241 // Gives boolean result
8273 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8279 /*// Implement speed etc.
8285 if(exp.op.op == '&')
8287 // Added this here earlier for Iterator address as key
8288 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8290 Identifier id = exp.op.exp2.identifier;
8291 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8292 if(symbol && symbol.isIterator == 2)
8294 exp.type = memberExp;
8295 exp.member.exp = exp.op.exp2;
8296 exp.member.member = MkIdentifier("key");
8298 exp.op.exp2.expType = symbol.type;
8299 symbol.type.refCount++;
8300 ProcessExpressionType(exp);
8304 // exp.op.exp2.usage.usageRef = true;
8308 //dummy.kind = TypeDummy;
8311 // Added this check here to use the dest type only for units derived from the base unit
8312 // So that untyped units will use the side unit as opposed to the untyped destination unit
8313 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8314 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8315 useDestType = false;
8317 if(destClass && useDestType &&
8318 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8320 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8322 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8323 exp.op.exp1.destType = exp.destType;
8324 exp.op.exp1.opDestType = true;
8326 exp.destType.refCount++;
8330 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8331 exp.op.exp1.destType = dummy;
8335 // TESTING THIS HERE...
8336 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8337 ProcessExpressionType(exp.op.exp1);
8338 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8340 exp.op.exp1.opDestType = false;
8342 // Fix for unit and ++ / --
8343 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8344 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8346 exp.op.exp2 = MkExpConstant("1");
8347 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8351 if(exp.op.exp1.destType == dummy)
8354 exp.op.exp1.destType = null;
8356 type1 = exp.op.exp1.expType;
8361 char expString[10240];
8362 expString[0] = '\0';
8363 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8367 exp.op.exp2.destType = exp.op.exp1.expType;
8368 if(exp.op.exp1.expType)
8369 exp.op.exp1.expType.refCount++;
8373 exp.op.exp2.destType = exp.destType;
8374 if(!exp.op.exp1 || (exp.op.op != '&' && exp.op.op != '^'))
8375 exp.op.exp2.opDestType = true;
8377 exp.destType.refCount++;
8380 if(type1) type1.refCount++;
8381 exp.expType = type1;
8386 PrintExpression(exp.op.exp2, expString);
8388 if(type1 && type1.kind == pointerType)
8390 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 ||
8391 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8392 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8393 else if(exp.op.op == '=')
8395 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8396 exp.op.exp2.destType = type1;
8403 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8404 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/* ||
8405 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8408 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8409 exp.op.exp2.destType = type1;
8414 if(type1) type1.refCount++;
8415 exp.expType = type1;
8417 else if(destClass &&
8418 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8419 (destClass.type == enumClass && useDestType)))
8421 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8422 exp.op.exp2.destType = exp.destType;
8423 if(exp.op.op != '&' && exp.op.op != '^')
8424 exp.op.exp2.opDestType = true;
8426 exp.destType.refCount++;
8430 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8431 exp.op.exp2.destType = dummy;
8435 // TESTING THIS HERE... (DANGEROUS)
8436 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8437 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8439 FreeType(exp.op.exp2.destType);
8440 exp.op.exp2.destType = type1;
8443 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8444 // Cannot lose the cast on a sizeof
8445 if(exp.op.op == SIZEOF)
8447 Expression e = exp.op.exp2;
8448 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8450 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8452 if(e.type == extensionCompoundExp)
8453 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8458 if(e.type == castExp && e.cast.exp)
8459 e.cast.exp.needCast = true;
8461 ProcessExpressionType(exp.op.exp2);
8462 exp.op.exp2.opDestType = false;
8463 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8465 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8467 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)
8469 if(exp.op.op != '=' && type1.type.kind == voidType)
8470 Compiler_Error($"void *: unknown size\n");
8472 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||
8473 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8474 (exp.op.exp2.expType._class.registered.type == normalClass ||
8475 exp.op.exp2.expType._class.registered.type == structClass ||
8476 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8478 if(exp.op.op == ADD_ASSIGN)
8479 Compiler_Error($"cannot add two pointers\n");
8481 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8482 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8484 if(exp.op.op == ADD_ASSIGN)
8485 Compiler_Error($"cannot add two pointers\n");
8489 char type1String[1024];
8490 char type2String[1024];
8491 type1String[0] = '\0';
8492 type2String[0] = '\0';
8494 PrintType(exp.op.exp2.expType, type1String, false, true);
8495 PrintType(type1, type2String, false, true);
8496 ChangeCh(expString, '\n', ' ');
8497 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8501 if(exp.op.exp2.destType == dummy)
8504 exp.op.exp2.destType = null;
8507 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8511 CopyTypeInto(type2, exp.op.exp2.expType);
8512 type2.isSigned = true;
8514 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8516 type2 = { kind = intType };
8518 type2.isSigned = true;
8522 type2 = exp.op.exp2.expType;
8523 if(type2) type2.refCount++;
8527 dummy.kind = voidType;
8529 if(exp.op.op == SIZEOF)
8536 exp.isConstant = true;
8538 // Get type of dereferenced pointer
8539 else if(exp.op.op == '*' && !exp.op.exp1)
8541 exp.expType = Dereference(type2);
8542 if(type2 && type2.kind == classType)
8543 notByReference = true;
8545 else if(exp.op.op == '&' && !exp.op.exp1)
8546 exp.expType = Reference(type2);
8553 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8554 exp.op.exp1.destType = MkClassType("bool");
8555 exp.op.exp1.destType.truth = true;
8556 if(!exp.op.exp1.expType)
8557 ProcessExpressionType(exp.op.exp1);
8559 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8560 FreeType(exp.op.exp1.expType);
8561 exp.op.exp1.expType = MkClassType("bool");
8562 exp.op.exp1.expType.truth = true;
8566 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8567 exp.op.exp2.destType = MkClassType("bool");
8568 exp.op.exp2.destType.truth = true;
8569 if(!exp.op.exp2.expType)
8570 ProcessExpressionType(exp.op.exp2);
8572 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8573 FreeType(exp.op.exp2.expType);
8574 exp.op.exp2.expType = MkClassType("bool");
8575 exp.op.exp2.expType.truth = true;
8578 else if(exp.op.exp1 && exp.op.exp2 &&
8581 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8582 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8583 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8584 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8586 if(type1 && type2 &&
8587 // If either both are class or both are not class
8588 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8590 // Added this check for enum subtraction to result in an int type:
8591 if(exp.op.op == '-' &&
8592 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8593 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8596 if(!type1._class.registered.dataType)
8597 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8598 if(!type2._class.registered.dataType)
8599 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8601 intType = ProcessTypeString(
8602 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8604 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8605 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8606 exp.op.exp1.destType = intType;
8607 exp.op.exp2.destType = intType;
8612 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8613 exp.op.exp2.destType = type1;
8615 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8616 exp.op.exp1.destType = type2;
8620 // Warning here for adding Radians + Degrees with no destination type
8621 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8622 type1._class.registered && type1._class.registered.type == unitClass &&
8623 type2._class.registered && type2._class.registered.type == unitClass &&
8624 type1._class.registered != type2._class.registered)
8625 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8626 type1._class.string, type2._class.string, type1._class.string);
8628 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8630 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8633 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8635 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8636 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8639 ProcessExpressionType(exp.op.exp1);
8641 if(type2.kind != pointerType)
8643 ProcessExpressionType(classExp);
8645 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8647 if(!exp.op.exp2.expType)
8651 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8655 ProcessExpressionType(exp.op.exp2);
8660 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)))
8662 if(type1.kind != classType && type1.type.kind == voidType)
8663 Compiler_Error($"void *: unknown size\n");
8664 exp.expType = type1;
8665 if(type1) type1.refCount++;
8667 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)))
8669 if(type2.kind != classType && type2.type.kind == voidType)
8670 Compiler_Error($"void *: unknown size\n");
8671 exp.expType = type2;
8672 if(type2) type2.refCount++;
8674 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8675 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8677 Compiler_Warning($"different levels of indirection\n");
8681 bool success = false;
8682 if(type1.kind == pointerType && type2.kind == pointerType)
8684 if(exp.op.op == '+')
8685 Compiler_Error($"cannot add two pointers\n");
8686 else if(exp.op.op == '-')
8688 // Pointer Subtraction gives integer
8689 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8698 if(type1.type.kind == templateType)
8700 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8703 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8705 ProcessExpressionType(classExp);
8707 exp.type = bracketsExp;
8708 exp.list = MkListOne(MkExpOp(
8709 MkExpBrackets(MkListOne(MkExpOp(
8710 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8712 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8713 MkExpMember(classExp, MkIdentifier("typeSize"))));
8715 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8724 if(!success && exp.op.exp1.type == constantExp)
8726 // If first expression is constant, try to match that first
8727 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8729 if(exp.expType) FreeType(exp.expType);
8730 exp.expType = exp.op.exp1.destType;
8731 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8734 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8736 if(exp.expType) FreeType(exp.expType);
8737 exp.expType = exp.op.exp2.destType;
8738 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8744 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8746 if(exp.expType) FreeType(exp.expType);
8747 exp.expType = exp.op.exp2.destType;
8748 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8751 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8753 if(exp.expType) FreeType(exp.expType);
8754 exp.expType = exp.op.exp1.destType;
8755 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8761 char expString1[10240];
8762 char expString2[10240];
8765 expString1[0] = '\0';
8766 expString2[0] = '\0';
8771 PrintExpression(exp.op.exp1, expString1);
8772 ChangeCh(expString1, '\n', ' ');
8773 PrintExpression(exp.op.exp2, expString2);
8774 ChangeCh(expString2, '\n', ' ');
8775 PrintType(exp.op.exp1.expType, type1, false, true);
8776 PrintType(exp.op.exp2.expType, type2, false, true);
8779 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8783 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8784 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8786 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8787 // Convert e.g. / 4 into / 4.0
8788 exp.op.exp1.destType = type2._class.registered.dataType;
8789 if(type2._class.registered.dataType)
8790 type2._class.registered.dataType.refCount++;
8791 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8792 exp.expType = type2;
8793 if(type2) type2.refCount++;
8795 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8797 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8798 // Convert e.g. / 4 into / 4.0
8799 exp.op.exp2.destType = type1._class.registered.dataType;
8800 if(type1._class.registered.dataType)
8801 type1._class.registered.dataType.refCount++;
8802 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8803 exp.expType = type1;
8804 if(type1) type1.refCount++;
8810 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8812 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8814 if(!type1._class.registered.dataType)
8815 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8816 exp.op.exp2.destType = type1._class.registered.dataType;
8817 exp.op.exp2.destType.refCount++;
8819 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8822 type2 = exp.op.exp2.destType;
8823 if(type2) type2.refCount++;
8825 exp.expType = type2;
8829 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8831 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8833 if(!type2._class.registered.dataType)
8834 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8835 exp.op.exp1.destType = type2._class.registered.dataType;
8836 exp.op.exp1.destType.refCount++;
8838 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8839 type1 = exp.op.exp1.destType;
8840 exp.expType = type1;
8844 // TESTING THIS NEW CODE
8845 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8847 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8848 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8849 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8851 // Convert the enum to an int instead for these operators
8852 if(op1IsEnum && exp.op.exp2.expType)
8854 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8856 if(exp.expType) FreeType(exp.expType);
8857 exp.expType = exp.op.exp2.expType;
8858 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8862 else if(op2IsEnum && exp.op.exp1.expType)
8864 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8866 if(exp.expType) FreeType(exp.expType);
8867 exp.expType = exp.op.exp1.expType;
8868 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8875 if(op1IsEnum && exp.op.exp2.expType)
8877 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8879 if(exp.expType) FreeType(exp.expType);
8880 exp.expType = exp.op.exp1.expType;
8881 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8885 else if(op2IsEnum && exp.op.exp1.expType)
8887 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8889 if(exp.expType) FreeType(exp.expType);
8890 exp.expType = exp.op.exp2.expType;
8891 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8900 // 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
8901 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
8902 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
8904 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8905 exp.op.exp1.destType = type2;
8908 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8910 if(exp.expType) FreeType(exp.expType);
8911 exp.expType = exp.op.exp1.destType;
8912 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8917 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8918 exp.op.exp2.destType = type1;
8922 // Maybe this was meant to be an enum...
8923 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8925 Type oldType = exp.op.exp2.expType;
8926 exp.op.exp2.expType = null;
8927 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
8930 exp.op.exp2.expType = oldType;
8935 // TESTING THIS HERE... LATEST ADDITION
8936 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8938 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8939 exp.op.exp2.destType = type2._class.registered.dataType;
8940 if(type2._class.registered.dataType)
8941 type2._class.registered.dataType.refCount++;
8942 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
8944 //exp.expType = type2._class.registered.dataType; //type2;
8945 //if(type2) type2.refCount++;
8948 // TESTING THIS HERE... LATEST ADDITION
8949 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8951 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8952 exp.op.exp1.destType = type1._class.registered.dataType;
8953 if(type1._class.registered.dataType)
8954 type1._class.registered.dataType.refCount++;
8955 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
8956 exp.expType = type1._class.registered.dataType; //type1;
8957 if(type1) type1.refCount++;
8961 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8963 if(exp.expType) FreeType(exp.expType);
8964 exp.expType = exp.op.exp2.destType;
8965 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8967 else if(type1 && type2)
8969 char expString1[10240];
8970 char expString2[10240];
8971 char type1String[1024];
8972 char type2String[1024];
8973 expString1[0] = '\0';
8974 expString2[0] = '\0';
8975 type1String[0] = '\0';
8976 type2String[0] = '\0';
8979 PrintExpression(exp.op.exp1, expString1);
8980 ChangeCh(expString1, '\n', ' ');
8981 PrintExpression(exp.op.exp2, expString2);
8982 ChangeCh(expString2, '\n', ' ');
8983 PrintType(exp.op.exp1.expType, type1String, false, true);
8984 PrintType(exp.op.exp2.expType, type2String, false, true);
8987 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
8989 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
8991 exp.expType = exp.op.exp1.expType;
8992 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8994 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
8996 exp.expType = exp.op.exp2.expType;
8997 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9005 // Maybe this was meant to be an enum...
9006 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9008 Type oldType = exp.op.exp1.expType;
9009 exp.op.exp1.expType = null;
9010 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9013 exp.op.exp1.expType = oldType;
9016 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9017 exp.op.exp1.destType = type2;
9020 // TESTING THIS HERE... LATEST ADDITION
9021 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9023 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9024 exp.op.exp1.destType = type1._class.registered.dataType;
9025 if(type1._class.registered.dataType)
9026 type1._class.registered.dataType.refCount++;
9029 // TESTING THIS HERE... LATEST ADDITION
9030 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9032 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9033 exp.op.exp2.destType = type2._class.registered.dataType;
9034 if(type2._class.registered.dataType)
9035 type2._class.registered.dataType.refCount++;
9039 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9041 if(exp.expType) FreeType(exp.expType);
9042 exp.expType = exp.op.exp1.destType;
9043 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9047 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9049 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9051 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9052 // Convert e.g. / 4 into / 4.0
9053 exp.op.exp1.destType = type2._class.registered.dataType;
9054 if(type2._class.registered.dataType)
9055 type2._class.registered.dataType.refCount++;
9056 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9058 if(exp.op.op == '!')
9060 exp.expType = MkClassType("bool");
9061 exp.expType.truth = true;
9065 exp.expType = type2;
9066 if(type2) type2.refCount++;
9069 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9071 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9073 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9074 // Convert e.g. / 4 into / 4.0
9075 exp.op.exp2.destType = type1._class.registered.dataType;
9076 if(type1._class.registered.dataType)
9077 type1._class.registered.dataType.refCount++;
9078 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9080 exp.expType = type1;
9081 if(type1) type1.refCount++;
9086 if(exp.op.exp1 && !exp.op.exp1.expType)
9088 char expString[10000];
9089 expString[0] = '\0';
9092 PrintExpression(exp.op.exp1, expString);
9093 ChangeCh(expString, '\n', ' ');
9096 Compiler_Error($"couldn't determine type of %s\n", expString);
9098 if(exp.op.exp2 && !exp.op.exp2.expType)
9100 char expString[10240];
9101 expString[0] = '\0';
9104 PrintExpression(exp.op.exp2, expString);
9105 ChangeCh(expString, '\n', ' ');
9108 Compiler_Error($"couldn't determine type of %s\n", expString);
9113 FreeType(exp.expType);
9114 exp.expType = MkClassType("bool");
9115 exp.expType.truth = true;
9118 if(exp.op.op != SIZEOF)
9119 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9120 (!exp.op.exp2 || exp.op.exp2.isConstant);
9122 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9124 DeclareType(curExternal, exp.op.exp2.expType, true, false);
9127 if(exp.op.op == DELETE && exp.op.exp2 && exp.op.exp2.expType && exp.op.exp2.expType.specConst)
9128 Compiler_Warning($"deleting const qualified object\n");
9138 case extensionExpressionExp:
9141 exp.isConstant = true;
9142 for(e = exp.list->first; e; e = e.next)
9144 //bool inced = false;
9147 FreeType(e.destType);
9148 e.opDestType = exp.opDestType;
9149 e.destType = exp.destType;
9150 if(e.destType) { exp.destType.refCount++; /*e.destType.count++; inced = true;*/ }
9152 ProcessExpressionType(e);
9154 exp.destType.count--;*/
9155 if(!exp.expType && !e.next)
9157 exp.expType = e.expType;
9158 if(e.expType) e.expType.refCount++;
9161 exp.isConstant = false;
9164 // In case a cast became a member...
9165 e = exp.list->first;
9166 if(!e.next && e.type == memberExp)
9168 // Preserve prev, next
9169 Expression next = exp.next, prev = exp.prev;
9172 FreeType(exp.expType);
9173 FreeType(exp.destType);
9183 ProcessExpressionType(exp);
9190 exp.isConstant = true;
9192 ProcessExpressionType(exp.index.exp);
9193 if(!exp.index.exp.isConstant)
9194 exp.isConstant = false;
9196 if(exp.index.exp.expType)
9198 Type source = exp.index.exp.expType;
9199 if(source.kind == classType && source._class && source._class.registered)
9201 Class _class = source._class.registered;
9202 Class c = _class.templateClass ? _class.templateClass : _class;
9203 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9205 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9207 if(exp.index.index && exp.index.index->last)
9209 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9211 if(type.kind == classType) type.constant = true;
9212 else if(type.kind == pointerType)
9215 while(t.kind == pointerType) t = t.type;
9219 ((Expression)exp.index.index->last).destType = type;
9225 for(e = exp.index.index->first; e; e = e.next)
9227 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9229 if(e.destType) FreeType(e.destType);
9230 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9232 ProcessExpressionType(e);
9235 // Check if this type is int
9238 exp.isConstant = false;
9242 exp.expType = Dereference(exp.index.exp.expType);
9244 DeclareType(curExternal, exp.expType, true, false);
9251 Type methodType = null;
9257 PrintExpression(exp.call.exp, name);
9258 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9260 //exp.call.exp.expType = null;
9261 PrintExpression(exp.call.exp, name);
9264 if(exp.call.exp.type == identifierExp)
9266 Expression idExp = exp.call.exp;
9267 Identifier id = idExp.identifier;
9268 if(!strcmp(id.string, "__builtin_frame_address"))
9270 exp.expType = ProcessTypeString("void *", true);
9271 if(exp.call.arguments && exp.call.arguments->first)
9272 ProcessExpressionType(exp.call.arguments->first);
9275 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9277 exp.expType = ProcessTypeString("int", true);
9278 if(exp.call.arguments && exp.call.arguments->first)
9279 ProcessExpressionType(exp.call.arguments->first);
9282 else if(!strcmp(id.string, "Max") ||
9283 !strcmp(id.string, "Min") ||
9284 !strcmp(id.string, "Sgn") ||
9285 !strcmp(id.string, "Abs"))
9287 Expression a = null;
9288 Expression b = null;
9289 Expression tempExp1 = null, tempExp2 = null;
9290 if((!strcmp(id.string, "Max") ||
9291 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9293 a = exp.call.arguments->first;
9294 b = exp.call.arguments->last;
9298 else if(exp.call.arguments->count == 1)
9300 a = exp.call.arguments->first;
9306 exp.call.arguments->Clear();
9307 idExp.identifier = null;
9309 FreeExpContents(exp);
9311 ProcessExpressionType(a);
9313 ProcessExpressionType(b);
9315 exp.type = bracketsExp;
9316 exp.list = MkList();
9318 if(a.expType && (!b || b.expType))
9320 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9322 // Use the simpleStruct name/ids for now...
9325 OldList * specs = MkList();
9326 OldList * decls = MkList();
9328 char temp1[1024], temp2[1024];
9330 GetTypeSpecs(a.expType, specs);
9332 if(a && !a.isConstant && a.type != identifierExp)
9334 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9335 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9336 tempExp1 = QMkExpId(temp1);
9337 tempExp1.expType = a.expType;
9339 a.expType.refCount++;
9340 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9342 if(b && !b.isConstant && b.type != identifierExp)
9344 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9345 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9346 tempExp2 = QMkExpId(temp2);
9347 tempExp2.expType = b.expType;
9349 b.expType.refCount++;
9350 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9353 decl = MkDeclaration(specs, decls);
9354 if(!curCompound.compound.declarations)
9355 curCompound.compound.declarations = MkList();
9356 curCompound.compound.declarations->Insert(null, decl);
9361 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9363 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9365 MkExpCondition(MkExpBrackets(MkListOne(
9366 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9367 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9368 exp.expType = a.expType;
9370 a.expType.refCount++;
9372 else if(!strcmp(id.string, "Abs"))
9375 MkExpCondition(MkExpBrackets(MkListOne(
9376 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9377 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9378 exp.expType = a.expType;
9380 a.expType.refCount++;
9382 else if(!strcmp(id.string, "Sgn"))
9384 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9386 MkExpCondition(MkExpBrackets(MkListOne(
9387 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9388 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9389 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9390 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9391 exp.expType = ProcessTypeString("int", false);
9394 FreeExpression(tempExp1);
9395 if(tempExp2) FreeExpression(tempExp2);
9409 if(!exp.call.exp.destType)
9411 exp.call.exp.destType = dummy;
9414 ProcessExpressionType(exp.call.exp);
9415 if(exp.call.exp.destType == dummy)
9418 exp.call.exp.destType = null;
9423 // Check argument types against parameter types
9424 functionType = exp.call.exp.expType;
9426 if(functionType && functionType.kind == TypeKind::methodType)
9428 methodType = functionType;
9429 functionType = methodType.method.dataType;
9431 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9432 // TOCHECK: Instead of doing this here could this be done per param?
9433 if(exp.call.exp.expType.usedClass)
9435 char typeString[1024];
9436 typeString[0] = '\0';
9438 Symbol back = functionType.thisClass;
9439 // Do not output class specifier here (thisclass was added to this)
9440 functionType.thisClass = null;
9441 PrintType(functionType, typeString, true, true);
9442 functionType.thisClass = back;
9444 if(strstr(typeString, "thisclass"))
9446 OldList * specs = MkList();
9449 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9451 decl = SpecDeclFromString(typeString, specs, null);
9453 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9454 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9455 exp.call.exp.expType.usedClass))
9456 thisClassParams = false;
9458 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9460 Class backupThisClass = thisClass;
9461 thisClass = exp.call.exp.expType.usedClass;
9462 ProcessDeclarator(decl, true);
9463 thisClass = backupThisClass;
9466 thisClassParams = true;
9468 functionType = ProcessType(specs, decl);
9469 functionType.refCount = 0;
9470 FinishTemplatesContext(context);
9472 // Mark parameters that were 'thisclass'
9475 for(p = functionType.params.first, op = methodType.method.dataType.params.first; p && op; p = p.next, op = op.next)
9477 //p.wasThisClass = op.kind == thisClassType;
9478 if(op.kind == thisClassType)
9479 p.thisClassFrom = methodType.method._class;
9482 if(methodType.method.dataType.returnType.kind == thisClassType)
9484 // functionType.returnType.wasThisClass = true;
9485 functionType.returnType.thisClassFrom = methodType.method._class;
9489 FreeList(specs, FreeSpecifier);
9490 FreeDeclarator(decl);
9494 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9496 Type type = functionType.type;
9497 if(!functionType.refCount)
9499 functionType.type = null;
9500 FreeType(functionType);
9502 //methodType = functionType;
9503 functionType = type;
9505 if(functionType && functionType.kind != TypeKind::functionType)
9507 Compiler_Error($"called object %s is not a function\n", name);
9509 else if(functionType)
9511 bool emptyParams = false, noParams = false;
9512 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9513 Type type = functionType.params.first;
9514 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9516 Location oldyylloc = yylloc;
9518 if(!type) emptyParams = true;
9521 if(functionType.extraParam && e && functionType.thisClass)
9523 e.destType = MkClassType(functionType.thisClass.string);
9527 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9528 // Fixed #141 by adding '&& !functionType.extraParam'
9529 if(!functionType.staticMethod && !functionType.extraParam)
9531 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9532 memberExp.member.exp.expType._class)
9534 type = MkClassType(memberExp.member.exp.expType._class.string);
9539 type = functionType.params.first;
9544 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9546 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9547 type.byReference = functionType.byReference;
9548 type.typedByReference = functionType.typedByReference;
9551 // Allow manually passing a class for typed object
9552 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9556 type = functionType.params.first;
9564 if(type && type.kind == voidType)
9567 if(!type.refCount) FreeType(type);
9571 for( ; e; e = e.next)
9573 if(!type && !emptyParams)
9576 if(methodType && methodType.methodClass)
9577 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9578 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9579 noParams ? 0 : functionType.params.count);
9581 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9582 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9583 noParams ? 0 : functionType.params.count);
9587 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9589 Type templatedType = null;
9590 Class _class = methodType.usedClass;
9591 ClassTemplateParameter curParam = null;
9593 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9596 for(sClass = _class; sClass; sClass = sClass.base)
9598 if(sClass.templateClass) sClass = sClass.templateClass;
9600 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9602 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9605 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9607 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9608 id += nextClass.templateParams.count;
9617 if(curParam && _class.templateArgs[id].dataTypeString)
9619 bool constant = type.constant;
9620 ClassTemplateArgument arg = _class.templateArgs[id];
9622 Context context = SetupTemplatesContext(_class);
9625 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9626 templatedType = ProcessTypeString(arg.dataTypeString, false);
9627 FinishTemplatesContext(context);
9630 if(templatedType.kind == classType && constant) templatedType.constant = true;
9631 else if(templatedType.kind == pointerType)
9633 Type t = templatedType.type;
9634 while(t.kind == pointerType) t = t.type;
9635 if(constant) t.constant = constant;
9638 e.destType = templatedType;
9641 templatedType.passAsTemplate = true;
9642 // templatedType.refCount++;
9648 if(type) type.refCount++;
9653 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9655 e.destType = type.prev;
9656 e.destType.refCount++;
9661 if(type) type.refCount++;
9664 // Don't reach the end for the ellipsis
9665 if(type && type.kind != ellipsisType)
9667 Type next = type.next;
9668 if(!type.refCount) FreeType(type);
9673 if(type && type.kind != ellipsisType)
9675 if(methodType && methodType.methodClass)
9676 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9677 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9678 functionType.params.count + extra);
9680 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9681 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9682 functionType.params.count + extra);
9685 if(type && !type.refCount) FreeType(type);
9692 kind = TypeKind::functionType;
9695 if(exp.call.exp.type == identifierExp)
9697 char * string = exp.call.exp.identifier.string;
9701 Location oldyylloc = yylloc;
9703 yylloc = exp.call.exp.identifier.loc;
9704 if(strstr(string, "__builtin_") == string)
9708 functionType.returnType = exp.destType;
9709 exp.destType.refCount++;
9713 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9714 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9715 globalContext.symbols.Add((BTNode)symbol);
9716 if(strstr(symbol.string, "::"))
9717 globalContext.hasNameSpace = true;
9722 else if(exp.call.exp.type == memberExp)
9724 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9725 exp.call.exp.member.member.string);*/
9728 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9730 if(!functionType.returnType)
9732 functionType.returnType = Type
9739 if(functionType && functionType.kind == TypeKind::functionType)
9741 exp.expType = functionType.returnType;
9743 if(functionType.returnType)
9744 functionType.returnType.refCount++;
9746 if(!functionType.refCount)
9747 FreeType(functionType);
9750 if(exp.call.arguments)
9752 for(e = exp.call.arguments->first; e; e = e.next)
9753 ProcessExpressionType(e);
9760 Location oldyylloc = yylloc;
9762 Expression checkExp = exp.member.exp;
9765 if(checkExp.type == castExp)
9766 checkExp = checkExp.cast.exp;
9767 else if(checkExp.type == bracketsExp)
9768 checkExp = checkExp.list ? checkExp.list->first : null;
9773 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9774 exp.thisPtr = thisPtr;
9776 // DOING THIS LATER NOW...
9777 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9779 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9780 /* TODO: Name Space Fix ups
9781 if(!exp.member.member.classSym)
9782 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9786 ProcessExpressionType(exp.member.exp);
9787 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9788 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9790 exp.isConstant = false;
9793 exp.isConstant = exp.member.exp.isConstant;
9794 type = exp.member.exp.expType;
9798 if(type && (type.kind == templateType))
9800 Class _class = thisClass ? thisClass : currentClass;
9801 ClassTemplateParameter param = null;
9804 for(param = _class.templateParams.first; param; param = param.next)
9806 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9810 if(param && param.defaultArg.member)
9812 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9815 Expression expMember = exp.member.exp;
9817 OldList * specs = MkList();
9818 char thisClassTypeString[1024];
9820 FreeIdentifier(exp.member.member);
9822 ProcessExpressionType(argExp);
9825 char * colon = strstr(param.defaultArg.memberString, "::");
9828 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9829 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9832 strcpy(thisClassTypeString, _class.fullName);
9835 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9837 exp.expType = ProcessType(specs, decl);
9838 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9840 Class expClass = exp.expType._class.registered;
9841 Class cClass = null;
9845 char templateString[1024];
9846 ClassTemplateParameter param;
9847 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9848 for(cClass = expClass; cClass; cClass = cClass.base)
9851 for(param = cClass.templateParams.first; param; param = param.next)
9855 ClassTemplateArgument arg;
9856 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9857 arg = expClass.templateArgs[id];
9859 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9861 ClassTemplateParameter cParam;
9862 //int p = numParams - sClass.templateParams.count;
9865 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9867 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9869 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9871 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9873 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9874 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9886 strcat(argument, arg.name.string);
9887 strcat(argument, " = ");
9893 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9894 char expString[1024];
9895 OldList * specs = MkList();
9896 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9898 char * string = PrintHexUInt64(arg.expression.ui64);
9899 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9902 ProcessExpressionType(exp);
9903 ComputeExpression(exp);
9904 expString[0] = '\0';
9905 PrintExpression(exp, expString);
9906 strcat(argument, expString);
9908 FreeExpression(exp);
9913 strcat(argument, arg.member.name);
9916 case TemplateParameterType::type:
9918 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9920 if(!strcmp(arg.dataTypeString, "thisclass"))
9921 strcat(argument, thisClassTypeString);
9923 strcat(argument, arg.dataTypeString);
9930 if(paramCount) strcat(templateString, ", ");
9931 if(lastParam != p - 1)
9933 strcat(templateString, param.name);
9934 strcat(templateString, " = ");
9936 strcat(templateString, argument);
9945 int len = strlen(templateString);
9946 if(templateString[len-1] == '>') templateString[len++] = ' ';
9947 templateString[len++] = '>';
9948 templateString[len++] = '\0';
9951 Context context = SetupTemplatesContext(_class);
9952 FreeType(exp.expType);
9953 exp.expType = ProcessTypeString(templateString, false);
9954 FinishTemplatesContext(context);
9958 if(!expMember.expType.isPointerType)
9959 expMember = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uintptr")), null), expMember);
9960 // *([expType] *)(((byte *)(uintptr)[exp.member.exp]) + [argExp].member.offset)
9961 exp.type = bracketsExp;
9962 exp.list = MkListOne(MkExpOp(null, '*',
9967 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
9968 MkExpBrackets(MkListOne(
9969 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
9972 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
9974 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
9979 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
9980 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
9982 type = ProcessTemplateParameterType(type.templateParameter);
9985 // TODO: *** This seems to be where we should add method support for all basic types ***
9986 if(type && (type.kind == templateType));
9987 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
9988 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
9989 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
9990 (type.kind == pointerType && type.type.kind == charType)))
9992 Identifier id = exp.member.member;
9993 TypeKind typeKind = type.kind;
9994 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
9995 if(typeKind == subClassType && exp.member.exp.type == classExp)
9997 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
9998 typeKind = classType;
10003 if(typeKind == intType || typeKind == enumType)
10004 _class = eSystem_FindClass(privateModule, "int");
10007 if(type.kind == classType && type._class && type._class.registered)
10009 _class = type._class.registered;
10011 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10013 _class = FindClass("char *").registered;
10015 else if(type.kind == pointerType)
10017 _class = eSystem_FindClass(privateModule, "uintptr");
10018 FreeType(exp.expType);
10019 exp.expType = ProcessTypeString("uintptr", false);
10020 exp.byReference = true;
10024 char string[1024] = "";
10026 PrintTypeNoConst(type, string, false, true);
10027 classSym = FindClass(string);
10028 if(classSym) _class = classSym.registered;
10036 (exp.member.exp.type == identifierExp &&
10037 !strcmp(exp.member.exp.identifier.string, "this"));*/
10038 Property prop = null;
10039 Method method = null;
10040 DataMember member = null;
10041 Property revConvert = null;
10042 ClassProperty classProp = null;
10044 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10045 exp.member.memberType = propertyMember;
10047 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10048 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10050 if(typeKind != subClassType)
10052 // Prioritize data members over properties for "this"
10053 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10055 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10056 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10058 prop = eClass_FindProperty(_class, id.string, privateModule);
10062 if(!member && !prop)
10063 prop = eClass_FindProperty(_class, id.string, privateModule);
10064 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10065 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10066 exp.member.thisPtr = true;
10068 // Prioritize properties over data members otherwise
10071 bool useMemberForNonConst = false;
10072 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10075 prop = eClass_FindProperty(_class, id.string, null);
10077 useMemberForNonConst = prop && exp.destType &&
10078 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10079 !strncmp(prop.dataTypeString, "const ", 6);
10081 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10082 member = eClass_FindDataMember(_class, id.string, null, null, null);
10085 if((!prop || useMemberForNonConst) && !member)
10087 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10090 prop = eClass_FindProperty(_class, id.string, privateModule);
10092 useMemberForNonConst |= prop && exp.destType &&
10093 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10094 !strncmp(prop.dataTypeString, "const ", 6);
10096 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10097 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10103 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10110 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10111 method = eClass_FindMethod(_class, id.string, privateModule);
10112 if(!prop && !member && !method)
10114 if(typeKind == subClassType)
10116 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10119 exp.member.memberType = classPropertyMember;
10120 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10124 // Assume this is a class_data member
10125 char structName[1024];
10126 Identifier id = exp.member.member;
10127 Expression classExp = exp.member.exp;
10130 FreeType(classExp.expType);
10131 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10133 strcpy(structName, "__ecereClassData_");
10134 FullClassNameCat(structName, type._class.string, false);
10135 exp.type = pointerExp;
10136 exp.member.member = id;
10138 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10139 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10140 MkExpBrackets(MkListOne(MkExpOp(
10141 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10142 MkExpMember(classExp, MkIdentifier("data"))), '+',
10143 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10148 ProcessExpressionType(exp);
10154 // Check for reverse conversion
10155 // (Convert in an instantiation later, so that we can use
10156 // deep properties system)
10157 Symbol classSym = FindClass(id.string);
10160 Class convertClass = classSym.registered;
10162 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10167 //if(!exp.member.exp.destType)
10168 if(exp.member.exp.destType)
10169 FreeType(exp.member.exp.destType);
10171 if(method && !method._class.symbol)
10172 method._class.symbol = FindClass(method._class.fullName);
10173 if(prop && !prop._class.symbol)
10174 prop._class.symbol = FindClass(prop._class.fullName);
10176 exp.member.exp.destType = Type
10180 _class = prop ? prop._class.symbol : method ? method._class.symbol : _class.symbol;
10181 // wasThisClass = type ? type.wasThisClass : false;
10182 thisClassFrom = type ? type.thisClassFrom : null;
10188 exp.member.memberType = propertyMember;
10190 ProcessPropertyType(prop);
10191 exp.expType = prop.dataType;
10192 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10195 CopyTypeInto(type, exp.expType);
10197 type.constant = true;
10198 exp.expType = type;
10200 else if(prop.dataType)
10201 prop.dataType.refCount++;
10205 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10207 FreeExpContents(exp);
10208 exp.type = identifierExp;
10209 exp.identifier = MkIdentifier("class");
10210 ProcessExpressionType(exp);
10214 exp.member.memberType = dataMember;
10215 DeclareStruct(curExternal, _class.fullName, false, true);
10216 if(member._class != _class)
10217 DeclareStruct(curExternal, member._class.fullName, false, true);
10219 if(!member.dataType)
10221 Context context = SetupTemplatesContext(_class);
10222 member.dataType = ProcessTypeString(member.dataTypeString, false);
10223 FinishTemplatesContext(context);
10225 exp.expType = member.dataType;
10226 if(member.dataType) member.dataType.refCount++;
10228 else if(revConvert)
10230 exp.member.memberType = reverseConversionMember;
10231 exp.expType = MkClassType(revConvert._class.fullName);
10239 exp.type = identifierExp;
10240 exp.identifier = exp.member.member;
10243 exp.member.memberType = methodMember;
10245 if(!method.dataType)
10246 ProcessMethodType(method);
10254 // Tricky spot here... To use instance versus class virtual table
10255 // Put it back to what it was... What did we break?
10257 // Had to put it back for overriding Main of Thread global instance
10259 //exp.expType.methodClass = _class;
10260 exp.expType.methodClass = (id && id._class) ? _class : null;
10262 // Need the actual class used for templated classes
10263 exp.expType.usedClass = _class;
10265 else if(!classProp)
10267 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10269 FreeExpContents(exp);
10270 exp.type = identifierExp;
10271 exp.identifier = MkIdentifier("class");
10272 FreeType(exp.expType);
10273 exp.expType = MkClassType("ecere::com::Class");
10276 yylloc = exp.member.member.loc;
10277 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10279 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10282 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10286 tClass = type._class && type._class.registered ? type._class.registered : _class;
10287 while(tClass && !tClass.templateClass) tClass = tClass.base;
10289 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10292 ClassTemplateParameter curParam = null;
10295 for(sClass = tClass; sClass; sClass = sClass.base)
10298 if(sClass.templateClass) sClass = sClass.templateClass;
10299 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10301 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10303 for(sClass = sClass.base; sClass; sClass = sClass.base)
10304 id += sClass.templateParams.count;
10309 if(curParam) break;
10312 if(curParam && tClass.templateArgs[id].dataTypeString)
10314 ClassTemplateArgument arg = tClass.templateArgs[id];
10315 Context context = SetupTemplatesContext(tClass);
10316 bool constant = exp.expType.constant;
10317 bool passAsTemplate = false;
10318 Class thisClassFrom = null;
10319 Type t = ProcessTypeString(exp.expType.templateParameter.dataTypeString, false);
10320 if(t && t.kind == classType && t._class)
10321 thisClassFrom = t._class.registered;
10324 passAsTemplate = tClass.templateClass && (exp.expType.kind != templateType ||
10325 (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType)));
10327 /*if(!arg.dataType)
10328 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10329 FreeType(exp.expType);
10331 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10332 exp.expType.thisClassFrom = thisClassFrom;
10333 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10334 else if(exp.expType.kind == pointerType)
10336 Type t = exp.expType.type;
10337 while(t.kind == pointerType) t = t.type;
10338 if(constant) t.constant = constant;
10342 if(exp.expType.kind == thisClassType)
10344 FreeType(exp.expType);
10345 exp.expType = ReplaceThisClassType(_class);
10349 exp.expType.passAsTemplate = true;
10350 //exp.expType.refCount++;
10353 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10354 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10355 else if(exp.destType.kind == pointerType)
10357 Type t = exp.destType.type;
10358 while(t.kind == pointerType) t = t.type;
10359 if(constant) t.constant = constant;
10362 //exp.destType.refCount++;
10364 if(exp.destType.kind == thisClassType)
10366 FreeType(exp.destType);
10367 exp.destType = ReplaceThisClassType(_class);
10371 FinishTemplatesContext(context);
10374 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10375 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10378 ClassTemplateParameter curParam = null;
10381 for(sClass = tClass; sClass; sClass = sClass.base)
10384 if(sClass.templateClass) sClass = sClass.templateClass;
10385 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10387 if(curParam.type == TemplateParameterType::type &&
10388 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10390 for(sClass = sClass.base; sClass; sClass = sClass.base)
10391 id += sClass.templateParams.count;
10396 if(curParam) break;
10401 ClassTemplateArgument arg = tClass.templateArgs[id];
10402 Context context = SetupTemplatesContext(tClass);
10404 /*if(!arg.dataType)
10405 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10407 basicType = ProcessTypeString(arg.dataTypeString, false);
10410 if(basicType.kind == thisClassType)
10412 FreeType(basicType);
10413 basicType = ReplaceThisClassType(_class);
10416 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10417 if(tClass.templateClass)
10418 basicType.passAsTemplate = true;
10421 FreeType(exp.expType);
10423 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10424 //exp.expType.refCount++;
10427 exp.destType = exp.expType;
10428 exp.destType.refCount++;
10432 Expression newExp { };
10433 OldList * specs = MkList();
10435 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10437 if(exp.destType) exp.destType.refCount++;
10438 if(exp.expType) exp.expType.refCount++;
10439 exp.type = castExp;
10440 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10441 exp.cast.exp = newExp;
10442 //FreeType(exp.expType);
10443 //exp.expType = null;
10444 //ProcessExpressionType(sourceExp);
10447 FinishTemplatesContext(context);
10450 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10452 Class expClass = exp.expType._class.registered;
10455 Class cClass = null;
10457 int paramCount = 0;
10458 int lastParam = -1;
10459 char templateString[1024];
10460 ClassTemplateParameter param;
10461 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10462 while(cClass != expClass)
10465 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10468 for(param = cClass.templateParams.first; param; param = param.next)
10470 Class cClassCur = null;
10472 ClassTemplateParameter paramCur = null;
10473 ClassTemplateArgument arg;
10474 while(cClassCur != tClass && !paramCur)
10477 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10478 cClassCur = sClassCur;
10480 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10482 if(!strcmp(paramCur.name, param.name))
10490 if(paramCur && paramCur.type == TemplateParameterType::type)
10491 arg = tClass.templateArgs[cp];
10493 arg = expClass.templateArgs[p];
10496 char argument[256];
10497 argument[0] = '\0';
10500 strcat(argument, arg.name.string);
10501 strcat(argument, " = ");
10507 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10508 char expString[1024];
10509 OldList * specs = MkList();
10510 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10512 char * string = PrintHexUInt64(arg.expression.ui64);
10513 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10516 ProcessExpressionType(exp);
10517 ComputeExpression(exp);
10518 expString[0] = '\0';
10519 PrintExpression(exp, expString);
10520 strcat(argument, expString);
10522 FreeExpression(exp);
10527 strcat(argument, arg.member.name);
10530 case TemplateParameterType::type:
10532 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10533 strcat(argument, arg.dataTypeString);
10539 if(paramCount) strcat(templateString, ", ");
10540 if(lastParam != p - 1)
10542 strcat(templateString, param.name);
10543 strcat(templateString, " = ");
10545 strcat(templateString, argument);
10554 int len = strlen(templateString);
10555 if(templateString[len-1] == '>') templateString[len++] = ' ';
10556 templateString[len++] = '>';
10557 templateString[len++] = '\0';
10560 FreeType(exp.expType);
10562 Context context = SetupTemplatesContext(tClass);
10563 exp.expType = ProcessTypeString(templateString, false);
10564 FinishTemplatesContext(context);
10571 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10573 else if(type && (type.kind == structType || type.kind == unionType))
10575 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10578 exp.expType = memberType;
10580 memberType.refCount++;
10585 char expString[10240];
10586 expString[0] = '\0';
10587 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10588 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10591 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10593 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10595 Identifier id = exp.member.member;
10596 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10599 FreeType(exp.expType);
10600 exp.expType = ReplaceThisClassType(_class);
10604 yylloc = oldyylloc;
10607 // Convert x->y into (*x).y
10610 Type destType = exp.destType;
10612 // DOING THIS LATER NOW...
10613 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10615 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10616 /* TODO: Name Space Fix ups
10617 if(!exp.member.member.classSym)
10618 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10622 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10623 exp.type = memberExp;
10626 ProcessExpressionType(exp);
10633 //ComputeExpression(exp);
10635 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10636 if(classSym && classSym.registered)
10638 if(classSym.registered.type == noHeadClass || (classSym.registered.fixed && classSym.registered.structSize))
10641 Class b = classSym.registered;
10643 DeclareStruct(curExternal, classSym.string, false, true);
10644 FreeSpecifier(exp._class);
10645 FullClassNameCat(name, classSym.string, false);
10649 exp.type = typeSizeExp;
10650 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10656 if(b.structSize == b.offset)
10657 exp.op.exp1 = MkExpConstant("0");
10659 exp.op.exp1 = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10662 while(b.offset != 0)
10665 Expression typeSize;
10668 sym = FindClass(b.fullName);
10671 DeclareStruct(curExternal, sym.string, false, true);
10672 FullClassNameCat(name, sym.string, false);
10674 if(b.structSize == b.offset)
10675 typeSize = MkExpConstant("0");
10677 typeSize = MkExpTypeSize(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null));
10678 e.op.exp2 = b.offset ? MkExpOp(typeSize, '+', null) : typeSize;
10685 if(classSym.registered.fixed && !classSym.registered.structSize)
10687 FreeSpecifier(exp._class);
10688 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10689 exp.type = constantExp;
10693 char className[1024];
10694 strcpy(className, "__ecereClass_");
10695 FullClassNameCat(className, classSym.string, true);
10697 DeclareClass(curExternal, classSym, className);
10699 FreeExpContents(exp);
10700 exp.type = pointerExp;
10701 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10702 exp.member.member = MkIdentifier("structSize");
10710 kind = intSizeType;
10712 // exp.isConstant = true;
10717 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10722 kind = intSizeType;
10724 exp.isConstant = true;
10726 DeclareType(curExternal, type, true, false);
10732 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10734 FreeType(exp.cast.exp.destType);
10735 exp.cast.exp.destType = type;
10737 type.casted = true;
10738 ProcessExpressionType(exp.cast.exp);
10739 type.casted = false;
10741 exp.expType = type;
10744 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10745 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10747 void * prev = exp.prev, * next = exp.next;
10748 Type expType = exp.cast.exp.destType;
10749 Expression castExp = exp.cast.exp;
10750 Type destType = exp.destType;
10752 if(expType) expType.refCount++;
10754 //FreeType(exp.destType);
10755 FreeType(exp.expType);
10756 FreeTypeName(exp.cast.typeName);
10759 FreeType(exp.expType);
10760 FreeType(exp.destType);
10762 exp.expType = expType;
10763 exp.destType = destType;
10773 exp.isConstant = exp.cast.exp.isConstant;
10778 case extensionInitializerExp:
10780 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10781 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10782 // ProcessInitializer(exp.initializer.initializer, type);
10783 exp.expType = type;
10788 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10789 ProcessExpressionType(exp.vaArg.exp);
10790 exp.expType = type;
10796 Type t = exp.destType;
10797 if(t && !exp.destType.casted)
10800 CopyTypeInto(t, exp.destType);
10806 exp.isConstant = true;
10808 FreeType(exp.cond.cond.destType);
10809 exp.cond.cond.destType = MkClassType("bool");
10810 exp.cond.cond.destType.truth = true;
10811 ProcessExpressionType(exp.cond.cond);
10812 if(!exp.cond.cond.isConstant)
10813 exp.isConstant = false;
10814 for(e = exp.cond.exp->first; e; e = e.next)
10818 FreeType(e.destType);
10820 if(e.destType) e.destType.refCount++;
10822 ProcessExpressionType(e);
10825 exp.expType = e.expType;
10826 if(e.expType) e.expType.refCount++;
10829 exp.isConstant = false;
10832 FreeType(exp.cond.elseExp.destType);
10833 // Added this check if we failed to find an expType
10834 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10837 exp.cond.elseExp.destType = t ? t : exp.expType;
10839 if(exp.cond.elseExp.destType)
10840 exp.cond.elseExp.destType.refCount++;
10841 ProcessExpressionType(exp.cond.elseExp);
10843 // FIXED THIS: Was done before calling process on elseExp
10844 if(!exp.cond.elseExp.isConstant)
10845 exp.isConstant = false;
10850 case extensionCompoundExp:
10852 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10854 Statement last = exp.compound.compound.statements->last;
10855 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10857 ((Expression)last.expressions->last).destType = exp.destType;
10859 exp.destType.refCount++;
10861 ProcessStatement(exp.compound);
10862 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10864 exp.expType.refCount++;
10870 Specifier spec = exp._classExp.specifiers->first;
10871 if(spec && spec.type == nameSpecifier)
10873 exp.expType = MkClassType(spec.name);
10874 exp.expType.kind = subClassType;
10875 exp.byReference = true;
10879 exp.expType = MkClassType("ecere::com::Class");
10880 exp.byReference = true;
10886 Class _class = thisClass ? thisClass : currentClass;
10889 Identifier id = exp.classData.id;
10890 char structName[1024];
10891 Expression classExp;
10892 strcpy(structName, "__ecereClassData_");
10893 FullClassNameCat(structName, _class.fullName, false);
10894 exp.type = pointerExp;
10895 exp.member.member = id;
10896 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10897 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10899 classExp = MkExpIdentifier(MkIdentifier("class"));
10901 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10902 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10903 MkExpBrackets(MkListOne(MkExpOp(
10904 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10905 MkExpMember(classExp, MkIdentifier("data"))), '+',
10906 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10909 ProcessExpressionType(exp);
10917 const char * typeString = null;
10918 char typeStringBuf[1024];
10919 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10920 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10922 Class templateClass = exp.destType._class.registered;
10923 typeString = templateClass.templateArgs[2].dataTypeString;
10927 // Guess type from expressions in the array
10929 for(e = exp.list->first; e; e = e.next)
10931 ProcessExpressionType(e);
10934 if(!type) { type = e.expType; type.refCount++; }
10937 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10938 if(!MatchTypeExpression(e, type, null, false, true))
10944 e = exp.list->first;
10945 ProcessExpressionType(e);
10948 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10949 if(!MatchTypeExpression(e, type, null, false, true))
10951 FreeType(e.expType);
10962 FreeType(e.expType);
10969 typeStringBuf[0] = '\0';
10970 PrintTypeNoConst(type, typeStringBuf, false, true);
10971 typeString = typeStringBuf;
10979 (Container)& (struct BuiltInContainer)
10981 ._vTbl = class(BuiltInContainer)._vTbl,
10982 ._class = class(BuiltInContainer),
10984 .data = (int[]){ 1, 7, 3, 4, 5 },
10986 .type = class(int),
10989 char templateString[1024];
10990 OldList * initializers = MkList();
10991 OldList * structInitializers = MkList();
10992 OldList * specs = MkList();
10994 Declarator decl = SpecDeclFromString(typeString, specs, null);
10995 sprintf(templateString, "Container<%s>", typeString);
11000 type = ProcessTypeString(typeString, false);
11001 while((e = exp.list->first))
11003 exp.list->Remove(e);
11006 ProcessExpressionType(e);
11007 ListAdd(initializers, MkInitializerAssignment(e));
11013 DeclareStruct(curExternal, "ecere::com::BuiltInContainer", false, true);
11015 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
11016 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11017 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
11018 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11019 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
11020 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11021 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
11022 MkTypeName(specs, MkDeclaratorArray(decl, null)),
11023 MkInitializerList(initializers))));
11024 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11025 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
11026 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11027 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
11028 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11029 exp.expType = ProcessTypeString(templateString, false);
11030 exp.type = bracketsExp;
11031 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
11033 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
11034 MkInitializerList(structInitializers)))));
11035 ProcessExpressionType(expExt);
11039 exp.expType = ProcessTypeString("Container", false);
11040 Compiler_Error($"Couldn't determine type of array elements\n");
11046 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
11048 FreeType(exp.expType);
11049 exp.expType = ReplaceThisClassType(thisClass);
11052 // Resolve structures here
11053 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
11055 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
11056 // TODO: Fix members reference...
11059 if(exp.expType.kind != enumType)
11062 String enumName = CopyString(exp.expType.enumName);
11064 // Fixed a memory leak on self-referencing C structs typedefs
11065 // by instantiating a new type rather than simply copying members
11066 // into exp.expType
11067 FreeType(exp.expType);
11068 exp.expType = Type { };
11069 exp.expType.kind = symbol.type.kind;
11070 exp.expType.refCount++;
11071 exp.expType.enumName = enumName;
11073 exp.expType.members = symbol.type.members;
11074 for(member = symbol.type.members.first; member; member = member.next)
11079 NamedLink64 member;
11080 for(member = symbol.type.members.first; member; member = member.next)
11082 NamedLink64 value { name = CopyString(member.name) };
11083 exp.expType.members.Add(value);
11090 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11091 else if(exp.destType && !exp.destType.keepCast)
11093 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11094 exp.needTemplateCast = 1;
11096 if(exp.destType.kind == voidType);
11097 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11099 // Warn for casting unrelated types to/from struct classes
11100 bool invalidCast = false;
11101 if(inCompiler && exp.destType.count && exp.expType)
11103 Class c1 = (exp.expType.kind == classType && exp.expType._class) ? exp.expType._class.registered : null;
11104 Class c2 = (exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
11105 if(c1 && c1.type != structClass) c1 = null;
11106 if(c2 && c2.type != structClass) c2 = null;
11107 if((c1 && !exp.expType.byReference && !c2 && !exp.destType.isPointerType) || (c2 && !exp.destType.byReference && !c1 && !exp.expType.isPointerType))
11108 invalidCast = true;
11110 if(!exp.destType.count || unresolved || invalidCast)
11115 if(exp.destType.kind != ellipsisType)
11121 char expString[10240];
11122 expString[0] = '\0';
11124 PrintType(exp.destType, type2, false, true);
11126 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11128 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11129 else if(exp.type != dummyExp)
11130 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11135 char expString[10240] ;
11136 expString[0] = '\0';
11137 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11140 Compiler_Error($"unresolved identifier %s\n", expString);
11141 else if(exp.type != dummyExp)
11142 Compiler_Error($"couldn't determine type of %s\n", expString);
11153 PrintType(exp.expType, type1, false, true);
11154 PrintType(exp.destType, type2, false, true);
11157 //CheckExpressionType(exp, exp.destType, false);
11159 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11160 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11161 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11164 char expString[10240];
11165 expString[0] = '\0';
11166 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11169 CheckExpressionType(exp, exp.destType, false, true);
11171 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11172 if(!sourceFile || (!strstr(sourceFile, "src\\lexer.ec") && !strstr(sourceFile, "src/lexer.ec") &&
11173 !strstr(sourceFile, "src\\grammar.ec") && !strstr(sourceFile, "src/grammar.ec") &&
11174 !strstr(sourceFile, "src\\type.ec") && !strstr(sourceFile, "src/type.ec") &&
11175 !strstr(sourceFile, "src\\expression.ec") && !strstr(sourceFile, "src/expression.ec")))
11178 Compiler_Error($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11180 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11183 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11186 FreeType(exp.expType);
11187 exp.destType.refCount++;
11188 exp.expType = exp.destType;
11194 // Cast function pointers to void * as eC already checked compatibility
11195 else if(exp.destType && exp.destType.kind == pointerType && exp.destType.type && exp.destType.type.kind == functionType &&
11196 exp.expType && (exp.expType.kind == functionType || exp.expType.kind == methodType))
11198 Expression nbExp = GetNonBracketsExp(exp);
11199 if(nbExp.type != castExp || !IsVoidPtrCast(nbExp.cast.typeName))
11201 Expression e = MoveExpContents(exp);
11202 exp.cast.exp = MkExpBrackets(MkListOne(e));
11203 exp.type = castExp;
11204 exp.cast.exp.destType = exp.destType;
11205 if(exp.destType) exp.destType.refCount++;
11206 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
11210 else if(unresolved)
11212 if(exp.identifier._class && exp.identifier._class.name)
11213 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11214 else if(exp.identifier.string && exp.identifier.string[0])
11215 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11217 else if(!exp.expType && exp.type != dummyExp)
11219 char expString[10240];
11220 expString[0] = '\0';
11221 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11222 Compiler_Error($"couldn't determine type of %s\n", expString);
11225 // Let's try to support any_object & typed_object here:
11227 ApplyAnyObjectLogic(exp);
11229 // Mark nohead classes as by reference, unless we're casting them to an integral type
11230 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11231 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11232 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11233 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11235 exp.byReference = true;
11237 yylloc = oldyylloc;
11240 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11242 // THIS CODE WILL FIND NEXT MEMBER...
11245 *curMember = (*curMember).next;
11247 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11249 *curMember = subMemberStack[--(*subMemberStackPos)];
11250 *curMember = (*curMember).next;
11253 // SKIP ALL PROPERTIES HERE...
11254 while((*curMember) && (*curMember).isProperty)
11255 *curMember = (*curMember).next;
11257 if(subMemberStackPos)
11259 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11261 subMemberStack[(*subMemberStackPos)++] = *curMember;
11263 *curMember = (*curMember).members.first;
11264 while(*curMember && (*curMember).isProperty)
11265 *curMember = (*curMember).next;
11273 if(subMemberStackPos && *subMemberStackPos)
11275 *curMember = subMemberStack[--(*subMemberStackPos)];
11276 *curMember = (*curMember).next;
11280 Class lastCurClass = *curClass;
11282 if(*curClass == _class) break; // REACHED THE END
11284 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11285 *curMember = (*curClass).membersAndProperties.first;
11288 while((*curMember) && (*curMember).isProperty)
11289 *curMember = (*curMember).next;
11290 if(subMemberStackPos)
11292 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11294 subMemberStack[(*subMemberStackPos)++] = *curMember;
11296 *curMember = (*curMember).members.first;
11297 while(*curMember && (*curMember).isProperty)
11298 *curMember = (*curMember).next;
11306 static void ProcessInitializer(Initializer init, Type type)
11310 case expInitializer:
11311 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11313 // TESTING THIS FOR SHUTTING = 0 WARNING
11314 if(init.exp && !init.exp.destType)
11316 FreeType(init.exp.destType);
11317 init.exp.destType = type;
11318 if(type) type.refCount++;
11322 ProcessExpressionType(init.exp);
11323 init.isConstant = init.exp.isConstant;
11329 Expression exp = init.exp;
11330 Instantiation inst = exp.instance;
11331 MembersInit members;
11333 init.type = listInitializer;
11334 init.list = MkList();
11338 for(members = inst.members->first; members; members = members.next)
11340 if(members.type == dataMembersInit)
11343 for(member = members.dataMembers->first; member; member = member.next)
11345 ListAdd(init.list, member.initializer);
11346 member.initializer = null;
11349 // Discard all MembersInitMethod
11352 FreeExpression(exp);
11354 case listInitializer:
11357 Type initializerType = null;
11358 Class curClass = null;
11359 DataMember curMember = null;
11360 DataMember subMemberStack[256];
11361 int subMemberStackPos = 0;
11363 if(type && type.kind == arrayType)
11364 initializerType = Dereference(type);
11365 else if(type && (type.kind == structType || type.kind == unionType))
11366 initializerType = type.members.first;
11368 for(i = init.list->first; i; i = i.next)
11370 if(type && type.kind == classType && type._class && type._class.registered)
11372 // 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)
11373 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11374 // TODO: Generate error on initializing a private data member this way from another module...
11377 if(!curMember.dataType)
11378 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11379 initializerType = curMember.dataType;
11382 ProcessInitializer(i, initializerType);
11383 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11384 initializerType = initializerType.next;
11386 init.isConstant = false;
11389 if(type && type.kind == arrayType)
11390 FreeType(initializerType);
11392 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11394 Compiler_Error($"Assigning list initializer to non list\n");
11401 static void ProcessSpecifier(Specifier spec, bool declareStruct)
11405 case baseSpecifier:
11407 if(spec.specifier == THISCLASS)
11411 spec.type = nameSpecifier;
11412 spec.name = ReplaceThisClass(thisClass);
11413 spec.symbol = FindClass(spec.name);
11414 ProcessSpecifier(spec, declareStruct);
11419 case nameSpecifier:
11421 Symbol symbol = FindType(curContext, spec.name);
11423 DeclareType(curExternal, symbol.type, true, true);
11424 else if(spec.symbol /*&& declareStruct*/)
11426 Class c = spec.symbol.registered;
11427 DeclareStruct(curExternal, spec.name, c && c.type == noHeadClass, declareStruct && c && c.type == structClass);
11431 case enumSpecifier:
11436 for(e = spec.list->first; e; e = e.next)
11439 ProcessExpressionType(e.exp);
11442 // Fall through for IDE type processing
11446 case structSpecifier:
11447 case unionSpecifier:
11449 if(spec.definitions)
11452 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11454 ProcessClass(spec.definitions, symbol);
11457 for(def = spec.definitions->first; def; def = def.next)
11459 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11460 ProcessDeclaration(def.decl);
11467 case classSpecifier:
11469 Symbol classSym = FindClass(spec.name);
11470 if(classSym && classSym.registered && classSym.registered.type == structClass)
11471 DeclareStruct(spec.name, false, true);
11479 static void ProcessDeclarator(Declarator decl, bool isFunction)
11483 case identifierDeclarator:
11484 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11486 FreeSpecifier(decl.identifier._class);
11487 decl.identifier._class = null;
11490 case arrayDeclarator:
11492 ProcessExpressionType(decl.array.exp);
11493 case structDeclarator:
11494 case bracketsDeclarator:
11495 case functionDeclarator:
11496 case pointerDeclarator:
11497 case extendedDeclarator:
11498 case extendedDeclaratorEnd:
11500 Identifier id = null;
11501 Specifier classSpec = null;
11502 if(decl.type == functionDeclarator)
11504 id = GetDeclId(decl);
11505 if(id && id._class)
11507 classSpec = id._class;
11511 if(decl.declarator)
11512 ProcessDeclarator(decl.declarator, isFunction);
11513 if(decl.type == functionDeclarator)
11519 qualifiers = MkListOne(classSpec);
11522 if(!decl.function.parameters)
11523 decl.function.parameters = MkList();
11524 decl.function.parameters->Insert(null, param);
11526 if(decl.function.parameters)
11530 for(param = decl.function.parameters->first; param; param = param.next)
11532 if(param.qualifiers)
11535 for(spec = param.qualifiers->first; spec; spec = spec.next)
11537 if(spec.type == baseSpecifier)
11539 if(spec.specifier == TYPED_OBJECT)
11541 Declarator d = param.declarator;
11544 qualifiers = MkListOne(MkSpecifier(VOID));
11545 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11547 if(d.type != pointerDeclarator)
11548 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11550 FreeList(param.qualifiers, FreeSpecifier);
11552 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11553 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11555 DeclareStruct(curExternal, "ecere::com::Class", false, true);
11557 decl.function.parameters->Insert(param, newParam);
11561 else if(spec.specifier == ANY_OBJECT)
11563 Declarator d = param.declarator;
11565 FreeList(param.qualifiers, FreeSpecifier);
11567 param.qualifiers = MkListOne(MkSpecifier(VOID));
11568 if(d.type != pointerDeclarator)
11569 param.qualifiers->Insert(null, MkSpecifier(CONST));
11570 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11573 else if(spec.specifier == THISCLASS)
11577 spec.type = nameSpecifier;
11578 spec.name = ReplaceThisClass(thisClass);
11579 spec.symbol = FindClass(spec.name);
11580 ProcessSpecifier(spec, false);
11585 else if(spec.type == nameSpecifier)
11587 ProcessSpecifier(spec, isFunction);
11592 if(param.declarator)
11593 ProcessDeclarator(param.declarator, false);
11602 static void ProcessDeclaration(Declaration decl)
11607 case initDeclaration:
11609 bool declareStruct = false;
11611 lineNum = decl.pos.line;
11612 column = decl.pos.col;
11615 if(decl.declarators)
11619 for(d = decl.declarators->first; d; d = d.next)
11621 Type type, subType;
11622 ProcessDeclarator(d.declarator, false);
11624 type = ProcessType(decl.specifiers, d.declarator);
11628 ProcessInitializer(d.initializer, type);
11630 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11632 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11633 d.initializer.exp.type == instanceExp)
11635 if(type.kind == classType && type._class ==
11636 d.initializer.exp.expType._class)
11638 Instantiation inst = d.initializer.exp.instance;
11639 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11641 d.initializer.exp.instance = null;
11642 if(decl.specifiers)
11643 FreeList(decl.specifiers, FreeSpecifier);
11644 FreeList(decl.declarators, FreeInitDeclarator);
11648 decl.type = instDeclaration;
11653 for(subType = type; subType;)
11655 if(subType.kind == classType)
11657 declareStruct = true;
11660 else if(subType.kind == pointerType)
11662 else if(subType.kind == arrayType)
11663 subType = subType.arrayType;
11673 if(decl.specifiers)
11676 for(s = decl.specifiers->first; s; s = s.next)
11678 ProcessSpecifier(s, declareStruct);
11683 case instDeclaration:
11685 ProcessInstantiationType(decl.inst);
11688 case structDeclaration:
11692 bool declareStruct = false;
11694 if(decl.declarators)
11696 for(d = decl.declarators->first; d; d = d.next)
11698 Type type = ProcessType(decl.specifiers, d.declarator);
11700 ProcessDeclarator(d, false);
11701 for(subType = type; subType;)
11703 if(subType.kind == classType)
11705 declareStruct = true;
11708 else if(subType.kind == pointerType)
11710 else if(subType.kind == arrayType)
11711 subType = subType.arrayType;
11718 if(decl.specifiers)
11720 for(spec = decl.specifiers->first; spec; spec = spec.next)
11721 ProcessSpecifier(spec, declareStruct);
11728 static FunctionDefinition curFunction;
11730 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11732 char propName[1024], propNameM[1024];
11733 char getName[1024], setName[1024];
11736 DeclareProperty(curExternal, prop, setName, getName);
11738 // eInstance_FireWatchers(object, prop);
11739 strcpy(propName, "__ecereProp_");
11740 FullClassNameCat(propName, prop._class.fullName, false);
11741 strcat(propName, "_");
11742 FullClassNameCat(propName, prop.name, true);
11744 strcpy(propNameM, "__ecerePropM_");
11745 FullClassNameCat(propNameM, prop._class.fullName, false);
11746 strcat(propNameM, "_");
11747 FullClassNameCat(propNameM, prop.name, true);
11749 if(prop.isWatchable)
11752 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11753 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11754 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11757 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11758 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11759 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11761 DeclareFunctionUtil(curExternal, "eInstance_FireWatchers");
11766 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11767 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11768 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11771 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11772 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11773 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11775 DeclareFunctionUtil(curExternal, "eInstance_FireSelfWatchers");
11778 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11779 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11780 curFunction.propSet.fireWatchersDone = true;
11783 static void ProcessStatement(Statement stmt)
11787 lineNum = stmt.pos.line;
11788 column = stmt.pos.col;
11793 ProcessStatement(stmt.labeled.stmt);
11796 // This expression should be constant...
11797 if(stmt.caseStmt.exp)
11799 FreeType(stmt.caseStmt.exp.destType);
11800 stmt.caseStmt.exp.destType = curSwitchType;
11801 if(curSwitchType) curSwitchType.refCount++;
11802 ProcessExpressionType(stmt.caseStmt.exp);
11803 ComputeExpression(stmt.caseStmt.exp);
11805 if(stmt.caseStmt.stmt)
11806 ProcessStatement(stmt.caseStmt.stmt);
11810 if(stmt.compound.context)
11815 Statement prevCompound = curCompound;
11816 Context prevContext = curContext;
11818 if(!stmt.compound.isSwitch)
11819 curCompound = stmt;
11820 curContext = stmt.compound.context;
11822 if(stmt.compound.declarations)
11824 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11825 ProcessDeclaration(decl);
11827 if(stmt.compound.statements)
11829 for(s = stmt.compound.statements->first; s; s = s.next)
11830 ProcessStatement(s);
11833 curContext = prevContext;
11834 curCompound = prevCompound;
11838 case expressionStmt:
11841 if(stmt.expressions)
11843 for(exp = stmt.expressions->first; exp; exp = exp.next)
11844 ProcessExpressionType(exp);
11852 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11853 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11854 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11855 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11857 ProcessExpressionType(exp);
11859 if(stmt.ifStmt.stmt)
11860 ProcessStatement(stmt.ifStmt.stmt);
11861 if(stmt.ifStmt.elseStmt)
11862 ProcessStatement(stmt.ifStmt.elseStmt);
11867 Type oldSwitchType = curSwitchType;
11868 if(stmt.switchStmt.exp)
11871 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11881 e.exp.destType = destType;
11884 ProcessExpressionType(exp);
11887 curSwitchType = exp.expType;
11890 ProcessStatement(stmt.switchStmt.stmt);
11891 curSwitchType = oldSwitchType;
11896 if(stmt.whileStmt.exp)
11900 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11901 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11902 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11903 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11905 ProcessExpressionType(exp);
11908 if(stmt.whileStmt.stmt)
11909 ProcessStatement(stmt.whileStmt.stmt);
11914 if(stmt.doWhile.exp)
11918 if(stmt.doWhile.exp->last)
11920 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11921 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11922 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11924 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11926 ProcessExpressionType(exp);
11929 if(stmt.doWhile.stmt)
11930 ProcessStatement(stmt.doWhile.stmt);
11936 if(stmt.forStmt.init)
11937 ProcessStatement(stmt.forStmt.init);
11939 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11941 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11942 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11943 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11946 if(stmt.forStmt.check)
11947 ProcessStatement(stmt.forStmt.check);
11948 if(stmt.forStmt.increment)
11950 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11951 ProcessExpressionType(exp);
11954 if(stmt.forStmt.stmt)
11955 ProcessStatement(stmt.forStmt.stmt);
11960 Identifier id = stmt.forEachStmt.id;
11961 OldList * exp = stmt.forEachStmt.exp;
11962 OldList * filter = stmt.forEachStmt.filter;
11963 Statement block = stmt.forEachStmt.stmt;
11964 char iteratorType[1024];
11967 bool isBuiltin = exp && exp->last &&
11968 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11969 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11970 Expression arrayExp;
11971 const char * typeString = null;
11972 int builtinCount = 0;
11974 for(e = exp ? exp->first : null; e; e = e.next)
11978 FreeType(e.destType);
11979 e.destType = ProcessTypeString("Container", false);
11981 if(!isBuiltin || e.next)
11982 ProcessExpressionType(e);
11985 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11986 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11987 eClass_IsDerived(source._class.registered, containerClass)))
11989 Class _class = source ? source._class.registered : null;
11991 Expression expIt = null;
11992 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
11993 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11994 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11995 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11999 stmt.type = compoundStmt;
12001 stmt.compound.context = Context { };
12002 stmt.compound.context.parent = curContext;
12003 curContext = stmt.compound.context;
12006 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
12008 Class mapClass = eSystem_FindClass(privateModule, "Map");
12009 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
12010 isCustomAVLTree = true;
12011 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
12013 else */if(eClass_IsDerived(source._class.registered, mapClass))
12016 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
12017 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
12019 Class listClass = eSystem_FindClass(privateModule, "List");
12021 isList = eClass_IsDerived(source._class.registered, listClass);
12024 if(inCompiler && isArray)
12027 OldList * specs = MkList();
12028 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12029 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12030 stmt.compound.declarations = MkListOne(
12031 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12032 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12033 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
12034 MkInitializerAssignment(MkExpBrackets(exp))))));
12039 char typeStringBuf[1024];
12041 // TODO: Merge this code?
12042 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
12043 if(((Expression)exp->last).type == castExp)
12045 TypeName typeName = ((Expression)exp->last).cast.typeName;
12047 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
12050 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
12051 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
12052 arrayExp.destType._class.registered.templateArgs)
12054 Class templateClass = arrayExp.destType._class.registered;
12055 typeString = templateClass.templateArgs[2].dataTypeString;
12057 else if(arrayExp.list)
12059 // Guess type from expressions in the array
12061 for(e = arrayExp.list->first; e; e = e.next)
12063 ProcessExpressionType(e);
12066 if(!type) { type = e.expType; type.refCount++; }
12069 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
12070 if(!MatchTypeExpression(e, type, null, false, true))
12076 e = arrayExp.list->first;
12077 ProcessExpressionType(e);
12080 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
12081 if(!MatchTypeExpression(e, type, null, false, true))
12083 FreeType(e.expType);
12094 FreeType(e.expType);
12101 typeStringBuf[0] = '\0';
12102 PrintType(type, typeStringBuf, false, true);
12103 typeString = typeStringBuf;
12111 OldList * initializers = MkList();
12113 OldList * specs = MkList();
12118 builtinCount = arrayExp.list->count;
12119 type = ProcessTypeString(typeString, false);
12120 while((e = arrayExp.list->first))
12122 arrayExp.list->Remove(e);
12125 ProcessExpressionType(e);
12127 ListAdd(initializers, MkInitializerAssignment(e));
12130 delete arrayExp.list;
12132 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12134 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12135 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12137 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12139 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12140 ), MkInitializerList(initializers)))));
12141 FreeList(exp, FreeExpression);
12143 else if(arrayExp.list)
12146 type = ProcessTypeString(typeString, false);
12147 for(e = arrayExp.list->first; e; e = e.next)
12151 ProcessExpressionType(e);
12158 arrayExp.expType = ProcessTypeString("Container", false);
12159 Compiler_Error($"Couldn't determine type of array elements\n");
12164 OldList * specs = MkList();
12166 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12167 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12168 stmt.compound.declarations = MkListOne(
12169 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12170 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12171 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12172 MkInitializerAssignment(MkExpBrackets(exp))))));
12175 else if(inCompiler && isLinkList && !isList)
12178 OldList * specs = MkList();
12179 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12180 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12181 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12182 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12183 MkInitializerAssignment(MkExpBrackets(exp))))));
12185 /*else if(isCustomAVLTree)
12188 OldList * specs = MkList();
12189 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12190 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12191 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12192 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12193 MkInitializerAssignment(MkExpBrackets(exp))))));
12195 else if(inCompiler && _class.templateArgs)
12198 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12200 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12202 stmt.compound.declarations = MkListOne(
12203 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12204 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12205 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12209 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12213 // Reparent sub-contexts in this statement
12217 if(block.compound.context)
12218 block.compound.context.parent = stmt.compound.context;
12221 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12222 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12223 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12224 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12227 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12228 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12231 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12232 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12235 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12236 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12239 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12240 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12243 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12244 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12246 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12249 case expressionStmt:
12255 case badDeclarationStmt:
12256 case fireWatchersStmt:
12257 case stopWatchingStmt:
12265 block = MkIfStmt(filter, block, null);
12269 stmt.compound.statements = MkListOne(MkForStmt(
12270 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12271 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12272 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12273 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12275 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12276 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12277 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12282 //OldList * specs = MkList();
12283 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12285 sprintf(count, "%d", builtinCount);
12287 stmt.compound.statements = MkListOne(MkForStmt(
12288 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12289 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12290 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12291 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12295 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12296 stmt.compound.statements = MkListOne(MkForStmt(
12297 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12298 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12299 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12300 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12303 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12304 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12305 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12307 else if(isLinkList && !isList)
12309 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12310 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12311 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12312 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12314 stmt.compound.statements = MkListOne(MkForStmt(
12315 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12316 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12317 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12322 OldList * specs = MkList();
12323 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12324 stmt.compound.statements = MkListOne(MkForStmt(
12325 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12326 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12327 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12328 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12329 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12332 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12333 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12334 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12336 /*else if(isCustomAVLTree)
12338 stmt.compound.statements = MkListOne(MkForStmt(
12339 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12340 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12341 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12342 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12345 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12346 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12347 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12351 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12352 MkIdentifier("Next")), null)), block));
12354 ProcessExpressionType(expIt);
12355 if(stmt.compound.declarations->first)
12356 ProcessDeclaration(stmt.compound.declarations->first);
12359 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12361 ProcessStatement(stmt);
12364 ProcessStatement(stmt.forEachStmt.stmt);
12366 curContext = stmt.compound.context.parent;
12371 Compiler_Error($"Expression is not a container\n");
12384 if(stmt.expressions)
12386 for(exp = stmt.expressions->first; exp; exp = exp.next)
12390 if(curFunction && !curFunction.type)
12391 curFunction.type = ProcessType(
12392 curFunction.specifiers, curFunction.declarator);
12393 FreeType(exp.destType);
12394 // TODO: current property if not compiling
12395 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12396 if(exp.destType) exp.destType.refCount++;
12398 ProcessExpressionType(exp);
12403 case badDeclarationStmt:
12405 ProcessDeclaration(stmt.decl);
12411 if(stmt.asmStmt.inputFields)
12413 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12414 if(field.expression)
12415 ProcessExpressionType(field.expression);
12417 if(stmt.asmStmt.outputFields)
12419 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12420 if(field.expression)
12421 ProcessExpressionType(field.expression);
12423 if(stmt.asmStmt.clobberedFields)
12425 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12427 if(field.expression)
12428 ProcessExpressionType(field.expression);
12435 PropertyWatch propWatch;
12436 OldList * watches = stmt._watch.watches;
12437 Expression object = stmt._watch.object;
12438 Expression watcher = stmt._watch.watcher;
12440 ProcessExpressionType(watcher);
12442 ProcessExpressionType(object);
12446 if(watcher || thisClass)
12448 External external = curExternal;
12449 Context context = curContext;
12451 stmt.type = expressionStmt;
12452 stmt.expressions = MkList();
12454 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12456 ClassFunction func;
12457 char watcherName[1024];
12458 Class watcherClass = watcher ?
12459 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12460 External createdExternal;
12462 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12463 if(propWatch.deleteWatch)
12464 strcat(watcherName, "_delete");
12468 for(propID = propWatch.properties->first; propID; propID = propID.next)
12470 strcat(watcherName, "_");
12471 strcat(watcherName, propID.string);
12475 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12477 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
12478 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12479 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
12480 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12481 ProcessClassFunctionBody(func, propWatch.compound);
12482 propWatch.compound = null;
12484 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12486 curExternal = createdExternal;
12487 ProcessFunction(createdExternal.function);
12489 if(propWatch.deleteWatch)
12491 OldList * args = MkList();
12492 ListAdd(args, CopyExpression(object));
12493 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12494 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12495 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12499 Class _class = object.expType._class.registered;
12502 for(propID = propWatch.properties->first; propID; propID = propID.next)
12504 char propName[1024];
12505 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12508 char getName[1024], setName[1024];
12509 OldList * args = MkList();
12511 DeclareProperty(createdExternal, prop, setName, getName);
12513 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12514 strcpy(propName, "__ecereProp_");
12515 FullClassNameCat(propName, prop._class.fullName, false);
12516 strcat(propName, "_");
12517 FullClassNameCat(propName, prop.name, true);
12519 ListAdd(args, CopyExpression(object));
12520 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12521 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12522 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpIdentifier(MkIdentifier(watcherName))));
12524 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12526 external.CreateUniqueEdge(createdExternal, true);
12529 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12534 Compiler_Error($"Invalid watched object\n");
12537 curExternal = external;
12538 curContext = context;
12541 FreeExpression(watcher);
12543 FreeExpression(object);
12544 FreeList(watches, FreePropertyWatch);
12547 Compiler_Error($"No observer specified and not inside a class\n");
12551 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12553 ProcessStatement(propWatch.compound);
12559 case fireWatchersStmt:
12561 OldList * watches = stmt._watch.watches;
12562 Expression object = stmt._watch.object;
12564 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12565 // printf("%X\n", watches);
12566 // printf("%X\n", stmt._watch.watches);
12568 ProcessExpressionType(object);
12573 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12579 stmt.type = expressionStmt;
12580 stmt.expressions = MkList();
12582 // Check if we're inside a property set
12583 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12585 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12589 //Compiler_Error($"No property specified and not inside a property set\n");
12593 for(propID = watches->first; propID; propID = propID.next)
12595 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12598 CreateFireWatcher(prop, object, stmt);
12601 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12606 // Fire all properties!
12609 for(base = _class; base; base = base.base)
12611 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12613 if(prop.isProperty && prop.isWatchable)
12615 CreateFireWatcher(prop, object, stmt);
12622 FreeExpression(object);
12623 FreeList(watches, FreeIdentifier);
12626 Compiler_Error($"Invalid object specified and not inside a class\n");
12630 case stopWatchingStmt:
12632 OldList * watches = stmt._watch.watches;
12633 Expression object = stmt._watch.object;
12634 Expression watcher = stmt._watch.watcher;
12637 ProcessExpressionType(object);
12639 ProcessExpressionType(watcher);
12642 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12644 if(watcher || thisClass)
12650 stmt.type = expressionStmt;
12651 stmt.expressions = MkList();
12656 // eInstance_StopWatching(object, null, watcher);
12658 ListAdd(args, CopyExpression(object));
12659 ListAdd(args, MkExpConstant("0"));
12660 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12661 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12665 for(propID = watches->first; propID; propID = propID.next)
12667 char propName[1024];
12668 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12671 char getName[1024], setName[1024];
12672 OldList * args = MkList();
12674 DeclareProperty(curExternal, prop, setName, getName);
12676 // eInstance_StopWatching(object, prop, watcher);
12677 strcpy(propName, "__ecereProp_");
12678 FullClassNameCat(propName, prop._class.fullName, false);
12679 strcat(propName, "_");
12680 FullClassNameCat(propName, prop.name, true);
12682 ListAdd(args, CopyExpression(object));
12683 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12684 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12685 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12688 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12693 FreeExpression(object);
12695 FreeExpression(watcher);
12696 FreeList(watches, FreeIdentifier);
12699 Compiler_Error($"Invalid object specified and not inside a class\n");
12702 Compiler_Error($"No observer specified and not inside a class\n");
12709 static void ProcessFunction(FunctionDefinition function)
12711 Identifier id = GetDeclId(function.declarator);
12712 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12713 Type type = symbol ? symbol.type : null;
12714 Class oldThisClass = thisClass;
12715 Context oldTopContext = topContext;
12717 yylloc = function.loc;
12718 // Process thisClass
12720 if(type && type.thisClass)
12722 Symbol classSym = type.thisClass;
12723 Class _class = type.thisClass.registered;
12724 char className[1024];
12725 char structName[1024];
12726 Declarator funcDecl;
12729 bool typedObject = false;
12731 if(_class && !_class.base)
12733 _class = currentClass;
12734 if(_class && !_class.symbol)
12735 _class.symbol = FindClass(_class.fullName);
12736 classSym = _class ? _class.symbol : null;
12737 typedObject = true;
12740 thisClass = _class;
12742 if(inCompiler && _class)
12744 if(type.kind == functionType)
12746 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12748 //TypeName param = symbol.type.params.first;
12749 Type param = symbol.type.params.first;
12750 symbol.type.params.Remove(param);
12751 //FreeTypeName(param);
12754 if(type.classObjectType != classPointer)
12756 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12757 symbol.type.staticMethod = true;
12758 symbol.type.thisClass = null;
12760 // HIGH DANGER: VERIFYING THIS...
12761 symbol.type.extraParam = false;
12765 strcpy(className, "__ecereClass_");
12766 FullClassNameCat(className, _class.fullName, true);
12769 FullClassNameCat(structName, _class.fullName, false);
12772 funcDecl = GetFuncDecl(function.declarator);
12775 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12777 TypeName param = funcDecl.function.parameters->first;
12778 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12780 funcDecl.function.parameters->Remove(param);
12781 FreeTypeName(param);
12785 if(!function.propertyNoThis)
12787 TypeName thisParam = null;
12789 if(type.classObjectType != classPointer)
12791 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12792 if(!funcDecl.function.parameters)
12793 funcDecl.function.parameters = MkList();
12794 funcDecl.function.parameters->Insert(null, thisParam);
12799 if(type.classObjectType != classPointer)
12801 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12802 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12805 thisParam = TypeName
12807 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12808 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12810 DeclareStruct(curExternal, "ecere::com::Class", false, true);
12811 funcDecl.function.parameters->Insert(null, thisParam);
12816 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12818 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12819 funcDecl = GetFuncDecl(initDecl.declarator);
12822 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12824 TypeName param = funcDecl.function.parameters->first;
12825 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12827 funcDecl.function.parameters->Remove(param);
12828 FreeTypeName(param);
12832 if(type.classObjectType != classPointer)
12834 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12836 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12838 if(!funcDecl.function.parameters)
12839 funcDecl.function.parameters = MkList();
12840 funcDecl.function.parameters->Insert(null, thisParam);
12847 // Add this to the context
12850 if(type.classObjectType != classPointer)
12852 thisSymbol = Symbol
12854 string = CopyString("this");
12855 type = classSym ? MkClassType(classSym.string) : null;
12857 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12859 if(typedObject && thisSymbol.type)
12861 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12862 thisSymbol.type.byReference = type.byReference;
12863 thisSymbol.type.typedByReference = type.byReference;
12868 // Pointer to class data
12869 if(inCompiler && _class && _class.type == normalClass && type.classObjectType != classPointer)
12871 DataMember member = null;
12874 for(base = _class; base && base.type != systemClass; base = base.next)
12876 for(member = base.membersAndProperties.first; member; member = member.next)
12877 if(!member.isProperty)
12883 for(member = _class.membersAndProperties.first; member; member = member.next)
12884 if(!member.isProperty)
12888 char pointerName[1024];
12891 Initializer initializer;
12892 Expression exp, bytePtr;
12894 strcpy(pointerName, "__ecerePointer_");
12895 FullClassNameCat(pointerName, _class.fullName, false);
12897 char className[1024];
12898 strcpy(className, "__ecereClass_");
12899 FullClassNameCat(className, classSym.string, true);
12901 DeclareClass(curExternal, classSym, className);
12905 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12910 if(_class.offset && _class.offset == _class.base.structSize)
12912 e = MkExpClassSize(MkSpecifierName(_class.base.fullName));
12913 ProcessExpressionType(e);
12918 sprintf(string, "%d", _class.offset); // Need Bootstrap Fix
12919 e = MkExpConstant(string);
12921 exp = QBrackets(MkExpOp(bytePtr, '+', e));
12925 // ([bytePtr] + [className]->offset)
12926 exp = QBrackets(MkExpOp(bytePtr, '+',
12927 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12930 // (this ? [exp] : 0)
12931 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12935 kind = pointerType;
12936 type = Type { refCount = 1, kind = voidType };
12941 yylloc = function.body.loc;
12942 // ([structName] *) [exp]
12943 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12944 initializer = MkInitializerAssignment(
12945 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12947 // [structName] * [pointerName] = [initializer];
12948 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12951 Context prevContext = curContext;
12953 curContext = function.body.compound.context;
12955 decl = MkDeclaration((list = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null))),
12956 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12957 list->Insert(null, MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
12959 curContext = prevContext;
12963 decl.symbol = null;
12965 if(!function.body.compound.declarations)
12966 function.body.compound.declarations = MkList();
12967 function.body.compound.declarations->Insert(null, decl);
12973 // Loop through the function and replace undeclared identifiers
12974 // which are a member of the class (methods, properties or data)
12975 // by "this.[member]"
12982 FreeSpecifier(id._class);
12985 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12987 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12988 id = GetDeclId(initDecl.declarator);
12990 FreeSpecifier(id._class);
12995 topContext = function.body.compound.context;
12997 FunctionDefinition oldFunction = curFunction;
12998 curFunction = function;
13000 ProcessStatement(function.body);
13002 // If this is a property set and no firewatchers has been done yet, add one here
13003 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
13005 Statement prevCompound = curCompound;
13006 Context prevContext = curContext;
13008 Statement fireWatchers = MkFireWatchersStmt(null, null);
13009 if(!function.body.compound.statements) function.body.compound.statements = MkList();
13010 ListAdd(function.body.compound.statements, fireWatchers);
13012 curCompound = function.body;
13013 curContext = function.body.compound.context;
13015 ProcessStatement(fireWatchers);
13017 curContext = prevContext;
13018 curCompound = prevCompound;
13022 curFunction = oldFunction;
13025 if(function.declarator)
13027 ProcessDeclarator(function.declarator, true);
13030 topContext = oldTopContext;
13031 thisClass = oldThisClass;
13034 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
13035 static void ProcessClass(OldList definitions, Symbol symbol)
13038 External external = curExternal;
13039 Class regClass = symbol ? symbol.registered : null;
13041 // Process all functions
13042 for(def = definitions.first; def; def = def.next)
13044 if(def.type == functionClassDef)
13046 if(def.function.declarator)
13047 curExternal = def.function.declarator.symbol.pointerExternal;
13049 curExternal = external;
13051 ProcessFunction((FunctionDefinition)def.function);
13053 else if(def.type == declarationClassDef)
13055 if(def.decl.type == instDeclaration)
13057 thisClass = regClass;
13058 ProcessInstantiationType(def.decl.inst);
13064 Class backThisClass = thisClass;
13065 if(regClass) thisClass = regClass;
13066 ProcessDeclaration(def.decl);
13067 thisClass = backThisClass;
13070 else if(def.type == defaultPropertiesClassDef && def.defProperties)
13072 MemberInit defProperty;
13074 // Add this to the context
13075 Symbol thisSymbol = Symbol
13077 string = CopyString("this");
13078 type = regClass ? MkClassType(regClass.fullName) : null;
13080 globalContext.symbols.Add((BTNode)thisSymbol);
13082 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
13084 thisClass = regClass;
13085 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
13089 globalContext.symbols.Remove((BTNode)thisSymbol);
13090 FreeSymbol(thisSymbol);
13092 else if(def.type == propertyClassDef && def.propertyDef)
13094 PropertyDef prop = def.propertyDef;
13096 // Add this to the context
13097 thisClass = regClass;
13104 string = CopyString("this");
13105 type = MkClassType(regClass.fullName);
13107 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13110 curExternal = prop.symbol ? prop.symbol.externalSet : null;
13111 ProcessStatement(prop.setStmt);
13119 string = CopyString("this");
13120 type = MkClassType(regClass.fullName);
13122 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13125 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13126 ProcessStatement(prop.getStmt);
13134 string = CopyString("this");
13135 type = MkClassType(regClass.fullName);
13137 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13140 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13141 ProcessStatement(prop.issetStmt);
13146 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13148 PropertyWatch propertyWatch = def.propertyWatch;
13150 thisClass = regClass;
13151 if(propertyWatch.compound)
13155 string = CopyString("this");
13156 type = regClass ? MkClassType(regClass.fullName) : null;
13159 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13161 curExternal = null;
13162 ProcessStatement(propertyWatch.compound);
13169 void DeclareFunctionUtil(External neededBy, const String s)
13171 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13176 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13177 strcpy(name, "__ecereFunction_");
13178 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13179 DeclareFunction(neededBy, function, name);
13182 FindSymbol(s, globalContext, globalContext, false, false);
13185 void ComputeDataTypes()
13189 currentClass = null;
13191 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13193 DeclareStruct(null, "ecere::com::Class", false, true);
13194 DeclareStruct(null, "ecere::com::Instance", false, true);
13195 DeclareStruct(null, "ecere::com::Property", false, true);
13196 DeclareStruct(null, "ecere::com::DataMember", false, true);
13197 DeclareStruct(null, "ecere::com::Method", false, true);
13198 DeclareStruct(null, "ecere::com::SerialBuffer", false, true);
13199 DeclareStruct(null, "ecere::com::ClassTemplateArgument", false, true);
13201 DeclareFunctionUtil(null, "eSystem_New");
13202 DeclareFunctionUtil(null, "eSystem_New0");
13203 DeclareFunctionUtil(null, "eSystem_Renew");
13204 DeclareFunctionUtil(null, "eSystem_Renew0");
13205 DeclareFunctionUtil(null, "eSystem_Delete");
13206 DeclareFunctionUtil(null, "eClass_GetProperty");
13207 DeclareFunctionUtil(null, "eClass_SetProperty");
13208 DeclareFunctionUtil(null, "eInstance_FireSelfWatchers");
13209 DeclareFunctionUtil(null, "eInstance_SetMethod");
13210 DeclareFunctionUtil(null, "eInstance_IncRef");
13211 DeclareFunctionUtil(null, "eInstance_StopWatching");
13212 DeclareFunctionUtil(null, "eInstance_Watch");
13213 DeclareFunctionUtil(null, "eInstance_FireWatchers");
13215 for(external = ast->first; external; external = external.next)
13217 afterExternal = curExternal = external;
13218 if(external.type == functionExternal)
13222 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13223 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13226 currentClass = external.function._class;
13227 ProcessFunction(external.function);
13229 // There shouldn't be any _class member access here anyways...
13230 else if(external.type == declarationExternal)
13232 if(memoryGuard && external.declaration && external.declaration.type == instDeclaration)
13234 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13235 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13238 currentClass = null;
13239 if(external.declaration)
13240 ProcessDeclaration(external.declaration);
13242 else if(external.type == classExternal)
13244 ClassDefinition _class = external._class;
13245 currentClass = external.symbol.registered;
13248 DeclareFunctionUtil(external, "MemoryGuard_PushLoc");
13249 DeclareFunctionUtil(external, "MemoryGuard_PopLoc");
13251 if(_class.definitions)
13253 ProcessClass(_class.definitions, _class.symbol);
13257 // Free class data...
13258 ast->Remove(external);
13262 else if(external.type == nameSpaceExternal)
13264 thisNameSpace = external.id.string;
13267 currentClass = null;
13268 thisNameSpace = null;
13269 curExternal = null;