4 #include <stdlib.h> // For strtoll
7 // UNTIL IMPLEMENTED IN GRAMMAR
8 #define ACCESS_CLASSDATA(_class, baseClass) \
9 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
11 #define YYLTYPE Location
15 extern int returnCode;
16 extern Expression parsedExpression;
18 public void SetYydebug(bool b) { yydebug = b; }
23 // TODO: Reset this to 0 on reinitialization
26 int expression_yyparse();
27 static Statement curCompound;
28 External curExternal, afterExternal;
29 static Type curSwitchType;
30 static Class currentClass;
32 public void SetThisClass(Class c) { thisClass = c; } public Class GetThisClass() { return thisClass; }
33 static char * thisNameSpace;
34 /*static */Class containerClass;
35 bool thisClassParams = true;
37 uint internalValueCounter;
40 Time findSymbolTotalTime;
43 // WARNING: PrintExpression CONCATENATES to string. Please initialize.
44 /*static */public void PrintExpression(Expression exp, char * string)
50 bool backOutputLineNumbers = outputLineNumbers;
51 outputLineNumbers = false;
54 OutputExpression(exp, f);
56 count = strlen(string);
57 count += f.Read(string + count, 1, 1023);
61 outputLineNumbers = backOutputLineNumbers;
65 Type ProcessTemplateParameterType(TemplateParameter param)
67 if(param && param.type == TemplateParameterType::type && (param.dataType || param.dataTypeString))
69 // TOFIX: Will need to free this Type
72 if(param.dataTypeString)
73 param.baseType = ProcessTypeString(param.dataTypeString, false);
75 param.baseType = ProcessType(param.dataType.specifiers, param.dataType.decl);
77 return param.baseType;
82 bool NeedCast(Type type1, Type type2)
84 if(!type1 || !type2 || type1.keepCast || type2.keepCast) return true;
86 if(type1.kind == templateType && type2.kind == int64Type && type2.passAsTemplate == false)
91 if(type1.kind == type2.kind)
102 if(type1.passAsTemplate && !type2.passAsTemplate)
104 return type1.isSigned != type2.isSigned;
106 return type1._class != type2._class;
108 return (type1.type && type2.type && type1.type.constant != type2.type.constant) || NeedCast(type1.type, type2.type);
110 return true; //false; ????
116 static void ReplaceClassMembers(Expression exp, Class _class)
118 if(exp.type == identifierExp && exp.identifier)
120 Identifier id = exp.identifier;
122 Symbol symbol = null;
123 if(!id._class || !id._class.name || strcmp(id._class.name, "property"))
125 // First, check if the identifier is declared inside the function
126 for(ctx = curContext; ctx != topContext.parent && !symbol; ctx = ctx.parent)
128 symbol = (Symbol)ctx.symbols.FindString(id.string);
133 // If it is not, check if it is a member of the _class
134 if(!symbol && ((!id._class || (id._class.name && !strcmp(id._class.name, "property"))) || (id.classSym && eClass_IsDerived(_class, id.classSym.registered))))
136 Property prop = eClass_FindProperty(_class, id.string, privateModule);
137 Method method = null;
138 DataMember member = null;
139 ClassProperty classProp = null;
142 method = eClass_FindMethod(_class, id.string, privateModule);
145 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
146 if(!prop && !method && !member)
148 classProp = eClass_FindClassProperty(_class, id.string);
150 if(prop || method || member || classProp)
152 // Replace by this.[member]
153 exp.type = memberExp;
154 exp.member.member = id;
155 exp.member.memberType = unresolvedMember;
156 exp.member.exp = QMkExpId("this");
157 //exp.member.exp.loc = exp.loc;
158 exp.addedThis = true;
160 else if(_class && _class.templateParams.first)
163 for(sClass = _class; sClass; sClass = sClass.base)
165 if(sClass.templateParams.first)
167 ClassTemplateParameter param;
168 for(param = sClass.templateParams.first; param; param = param.next)
170 if(param.type == expression && !strcmp(param.name, id.string))
172 Expression argExp = GetTemplateArgExpByName(param.name, _class, TemplateParameterType::expression);
177 OldList * specs = MkList();
179 FreeIdentifier(exp.member.member);
181 ProcessExpressionType(argExp);
183 decl = SpecDeclFromString(param.dataTypeString, specs, null);
185 exp.expType = ProcessType(specs, decl);
187 // *[expType] *[argExp]
188 exp.type = bracketsExp;
189 exp.list = MkListOne(MkExpOp(null, '*',
190 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpOp(null, '&', argExp))));
201 ////////////////////////////////////////////////////////////////////////
202 // PRINTING ////////////////////////////////////////////////////////////
203 ////////////////////////////////////////////////////////////////////////
205 public char * PrintInt(int64 result)
209 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
211 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
212 if(result > MAXINT || result < MININT)
214 return CopyString(temp);
217 public char * PrintUInt(uint64 result)
220 if(result > MAXDWORD)
221 sprintf(temp, FORMAT64HEXLL /*"0x%I64X"*/, result);
222 else if(result > MAXINT)
223 sprintf(temp, FORMAT64HEX /*"0x%I64X"*/, result);
225 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
226 return CopyString(temp);
229 public char * PrintInt64(int64 result)
232 if(result > MAXINT || result < MININT)
233 sprintf(temp, FORMAT64DLL /*"%I64d"*/, result);
235 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
236 return CopyString(temp);
239 public char * PrintUInt64(uint64 result)
242 if(result > MAXDWORD)
243 sprintf(temp, FORMAT64HEXLL /*"0x%I64XLL"*/, result);
244 else if(result > MAXINT)
245 sprintf(temp, FORMAT64HEX /*"0x%I64XLL"*/, result);
247 sprintf(temp, FORMAT64D /*"%I64d"*/, result);
248 return CopyString(temp);
251 public char * PrintHexUInt(uint64 result)
254 if(result > MAXDWORD)
255 sprintf(temp, FORMAT64HEX /*"0x%I64xLL"*/, result);
257 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
258 if(result > MAXDWORD)
260 return CopyString(temp);
263 public char * PrintHexUInt64(uint64 result)
266 if(result > MAXDWORD)
267 sprintf(temp, FORMAT64HEXLL /*"0x%I64xLL"*/, result);
269 sprintf(temp, FORMAT64HEX /*"0x%I64x"*/, result);
270 return CopyString(temp);
273 public char * PrintShort(short result)
276 sprintf(temp, "%d", (unsigned short)result);
277 return CopyString(temp);
280 public char * PrintUShort(unsigned short result)
284 sprintf(temp, "0x%X", (int)result);
286 sprintf(temp, "%d", (int)result);
287 return CopyString(temp);
290 public char * PrintChar(char result)
293 if(result > 0 && isprint(result))
294 sprintf(temp, "'%c'", result);
296 sprintf(temp, "%d", (int)result);
298 //sprintf(temp, "%#X", result);
299 sprintf(temp, "0x%X", (unsigned char)result);
300 return CopyString(temp);
303 public char * PrintUChar(unsigned char result)
306 sprintf(temp, "0x%X", result);
307 return CopyString(temp);
310 public char * PrintFloat(float result)
316 strcpy(temp, "-inf");
320 else if(result.isNan)
323 strcpy(temp, "-nan");
328 sprintf(temp, "%.16ff", result);
329 return CopyString(temp);
332 public char * PrintDouble(double result)
338 strcpy(temp, "-inf");
342 else if(result.isNan)
345 strcpy(temp, "-nan");
350 sprintf(temp, "%.16f", result);
351 return CopyString(temp);
354 ////////////////////////////////////////////////////////////////////////
355 ////////////////////////////////////////////////////////////////////////
357 //public Operand GetOperand(Expression exp);
359 #define GETVALUE(name, t) \
360 public bool GetOp##name(Operand op2, t * value2) \
362 if(op2.kind == intType && op2.type.isSigned) *value2 = (t) op2.i; \
363 else if(op2.kind == intType) *value2 = (t) op2.ui; \
364 else if(op2.kind == int64Type && op2.type.isSigned) *value2 = (t) op2.i64; \
365 else if(op2.kind == int64Type) *value2 = (t) op2.ui64; \
366 else if(op2.kind == intSizeType && op2.type.isSigned) *value2 = (t) op2.i64; \
367 else if(op2.kind == intSizeType) *value2 = (t) op2.ui64; \
368 else if(op2.kind == intPtrType && op2.type.isSigned) *value2 = (t) op2.i64; \
369 else if(op2.kind == intPtrType) *value2 = (t) op2.ui64; \
370 else if(op2.kind == shortType && op2.type.isSigned) *value2 = (t) op2.s; \
371 else if(op2.kind == shortType) *value2 = (t) op2.us; \
372 else if(op2.kind == charType && op2.type.isSigned) *value2 = (t) op2.c; \
373 else if(op2.kind == _BoolType || op2.kind == charType) *value2 = (t) op2.uc; \
374 else if(op2.kind == floatType) *value2 = (t) op2.f; \
375 else if(op2.kind == doubleType) *value2 = (t) op2.d; \
376 else if(op2.kind == pointerType) *value2 = (t) op2.ui64; \
381 public bool Get##name(Expression exp, t * value2) \
383 Operand op2 = GetOperand(exp); \
384 return GetOp##name(op2, value2); \
387 // To help the debugger currently not preprocessing...
390 GETVALUE(Int, HELP(int));
391 GETVALUE(UInt, HELP(unsigned int));
392 GETVALUE(Int64, HELP(int64));
393 GETVALUE(UInt64, HELP(uint64));
394 GETVALUE(IntPtr, HELP(intptr));
395 GETVALUE(UIntPtr, HELP(uintptr));
396 GETVALUE(IntSize, HELP(intsize));
397 GETVALUE(UIntSize, HELP(uintsize));
398 GETVALUE(Short, HELP(short));
399 GETVALUE(UShort, HELP(unsigned short));
400 GETVALUE(Char, HELP(char));
401 GETVALUE(UChar, HELP(unsigned char));
402 GETVALUE(Float, HELP(float));
403 GETVALUE(Double, HELP(double));
405 void ComputeExpression(Expression exp);
407 void ComputeClassMembers(Class _class, bool isMember)
409 DataMember member = isMember ? (DataMember) _class : null;
410 Context context = isMember ? null : SetupTemplatesContext(_class);
411 if(member || ((_class.type == bitClass || _class.type == normalClass || _class.type == structClass || _class.type == noHeadClass) &&
412 (_class.type == bitClass || (!_class.structSize || _class.structSize == _class.offset)) && _class.computeSize))
414 int unionMemberOffset = 0;
418 if(!member && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass) && _class.memberOffset && _class.memberOffset > _class.base.structSize)
419 _class.memberOffset = (_class.base && _class.base.type != systemClass) ? _class.base.structSize : 0;
424 member.memberOffset = 0;
425 if(targetBits < sizeof(void *) * 8)
426 member.structAlignment = 0;
428 else if(targetBits < sizeof(void *) * 8)
429 _class.structAlignment = 0;
431 // Confusion here: non struct classes seem to have their memberOffset restart at 0 at each hierarchy level
432 if(!member && ((_class.type == normalClass || _class.type == noHeadClass) || (_class.type == structClass && _class.memberOffset && _class.memberOffset > _class.base.structSize)))
433 _class.memberOffset = (_class.base && _class.type == structClass) ? _class.base.structSize : 0;
435 if(!member && _class.destructionWatchOffset)
436 _class.memberOffset += sizeof(OldList);
438 // To avoid reentrancy...
439 //_class.structSize = -1;
442 DataMember dataMember;
443 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
445 if(!dataMember.isProperty)
447 if(dataMember.type == normalMember && dataMember.dataTypeString && !dataMember.dataType)
449 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
450 /*if(!dataMember.dataType)
451 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
459 DataMember dataMember;
460 for(dataMember = member ? member.members.first : _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
462 if(!dataMember.isProperty && (dataMember.type != normalMember || dataMember.dataTypeString))
464 if(!isMember && _class.type == bitClass && dataMember.dataType)
466 BitMember bitMember = (BitMember) dataMember;
470 ComputeTypeSize(dataMember.dataType);
472 if(bitMember.pos == -1) bitMember.pos = _class.memberOffset;
473 if(!bitMember.size) bitMember.size = dataMember.dataType.size * 8;
475 _class.memberOffset = bitMember.pos + bitMember.size;
476 for(d = 0; d<bitMember.size; d++)
482 bitMember.mask = mask << bitMember.pos;
484 else if(dataMember.type == normalMember && dataMember.dataType)
489 // Prevent infinite recursion
490 if(dataMember.dataType.kind != classType ||
491 ((!dataMember.dataType._class || !dataMember.dataType._class.registered || dataMember.dataType._class.registered != _class ||
492 _class.type != structClass)))
493 ComputeTypeSize(dataMember.dataType);
495 if(dataMember.dataType.bitFieldCount)
497 bitFields += dataMember.dataType.bitFieldCount;
504 int size = (bitFields + 7) / 8;
508 // TESTING THIS PADDING CODE
511 member.structAlignment = Max(member.structAlignment, alignment);
513 if(member.memberOffset % alignment)
514 member.memberOffset += alignment - (member.memberOffset % alignment);
517 dataMember.offset = member.memberOffset;
518 if(member.type == unionMember)
519 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
522 member.memberOffset += size;
527 // TESTING THIS PADDING CODE
530 _class.structAlignment = Max(_class.structAlignment, alignment);
532 if(_class.memberOffset % alignment)
533 _class.memberOffset += alignment - (_class.memberOffset % alignment);
536 dataMember.offset = _class.memberOffset;
537 _class.memberOffset += size;
541 size = dataMember.dataType.size;
542 alignment = dataMember.dataType.alignment;
547 // TESTING THIS PADDING CODE
550 member.structAlignment = Max(member.structAlignment, alignment);
552 if(member.memberOffset % alignment)
553 member.memberOffset += alignment - (member.memberOffset % alignment);
556 dataMember.offset = member.memberOffset;
557 if(member.type == unionMember)
558 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
561 member.memberOffset += size;
566 // TESTING THIS PADDING CODE
569 _class.structAlignment = Max(_class.structAlignment, alignment);
571 if(_class.memberOffset % alignment)
572 _class.memberOffset += alignment - (_class.memberOffset % alignment);
575 dataMember.offset = _class.memberOffset;
576 _class.memberOffset += size;
583 ComputeClassMembers((Class)dataMember, true);
584 alignment = dataMember.structAlignment;
590 if(member.memberOffset % alignment)
591 member.memberOffset += alignment - (member.memberOffset % alignment);
593 member.structAlignment = Max(member.structAlignment, alignment);
595 dataMember.offset = member.memberOffset;
596 if(member.type == unionMember)
597 unionMemberOffset = Max(unionMemberOffset, dataMember.memberOffset);
599 member.memberOffset += dataMember.memberOffset;
605 if(_class.memberOffset % alignment)
606 _class.memberOffset += alignment - (_class.memberOffset % alignment);
607 _class.structAlignment = Max(_class.structAlignment, alignment);
609 dataMember.offset = _class.memberOffset;
610 _class.memberOffset += dataMember.memberOffset;
618 int size = (bitFields + 7) / 8;
622 // TESTING THIS PADDING CODE
625 member.structAlignment = Max(member.structAlignment, alignment);
627 if(member.memberOffset % alignment)
628 member.memberOffset += alignment - (member.memberOffset % alignment);
631 if(member.type == unionMember)
632 unionMemberOffset = Max(unionMemberOffset, dataMember.dataType.size);
635 member.memberOffset += size;
640 // TESTING THIS PADDING CODE
643 _class.structAlignment = Max(_class.structAlignment, alignment);
645 if(_class.memberOffset % alignment)
646 _class.memberOffset += alignment - (_class.memberOffset % alignment);
648 _class.memberOffset += size;
653 if(member && member.type == unionMember)
655 member.memberOffset = unionMemberOffset;
660 /*if(_class.type == structClass)
661 _class.size = _class.memberOffset;
665 if(_class.type != bitClass)
668 if(_class.structAlignment)
670 if(_class.memberOffset % _class.structAlignment)
671 extra += _class.structAlignment - (_class.memberOffset % _class.structAlignment);
673 _class.structSize = (_class.base ? (_class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize) : 0) + _class.memberOffset + extra;
677 for(prop = _class.membersAndProperties.first; prop; prop = prop.next)
679 if(prop.isProperty && prop.isWatchable)
681 prop.watcherOffset = _class.structSize;
682 _class.structSize += sizeof(OldList);
690 for(derivative = _class.derivatives.first; derivative; derivative = derivative.next)
692 Class deriv = derivative.data;
694 if(deriv.computeSize)
696 // TESTING THIS NEW CODE HERE... TRYING TO FIX ScrollBar MEMBERS DEBUGGING
697 deriv.offset = /*_class.offset + */_class.structSize;
698 deriv.memberOffset = 0;
699 // ----------------------
701 deriv.structSize = deriv.offset;
703 ComputeClassMembers(deriv, false);
711 FinishTemplatesContext(context);
714 public void ComputeModuleClasses(Module module)
719 for(subModule = module.modules.first; subModule; subModule = subModule.next)
720 ComputeModuleClasses(subModule.data);
721 for(_class = module.classes.first; _class; _class = _class.next)
722 ComputeClassMembers(_class, false);
726 public int ComputeTypeSize(Type type)
728 uint size = type ? type.size : 0;
729 if(!size && type && !type.computing)
731 type.computing = true;
734 case _BoolType: type.alignment = size = sizeof(char); break; // Assuming 1 byte _Bool
735 case charType: type.alignment = size = sizeof(char); break;
736 case intType: type.alignment = size = sizeof(int); break;
737 case int64Type: type.alignment = size = sizeof(int64); break;
738 case intPtrType: type.alignment = size = targetBits / 8; break;
739 case intSizeType: type.alignment = size = targetBits / 8; break;
740 case longType: type.alignment = size = sizeof(long); break;
741 case shortType: type.alignment = size = sizeof(short); break;
742 case floatType: type.alignment = size = sizeof(float); break;
743 case doubleType: type.alignment = size = sizeof(double); break;
746 Class _class = type._class ? type._class.registered : null;
748 if(_class && _class.type == structClass)
750 // Ensure all members are properly registered
751 ComputeClassMembers(_class, false);
752 type.alignment = _class.structAlignment;
753 size = _class.structSize;
754 if(type.alignment && size % type.alignment)
755 size += type.alignment - (size % type.alignment);
758 else if(_class && (_class.type == unitClass ||
759 _class.type == enumClass ||
760 _class.type == bitClass))
763 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
764 size = type.alignment = ComputeTypeSize(_class.dataType);
767 size = type.alignment = targetBits / 8; // sizeof(Instance *);
770 case pointerType: case subClassType: size = type.alignment = targetBits / 8; /*sizeof(void *); */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;
816 type.alignment = type.type.alignment;
821 if(!type.members.first && type.enumName)
823 Symbol symbol = FindStruct(curContext, type.enumName);
824 if(symbol && symbol.type)
826 ComputeTypeSize(symbol.type);
827 size = symbol.type.size;
833 for(member = type.members.first; member; member = member.next)
835 uint addSize = ComputeTypeSize(member);
837 member.offset = size;
838 if(member.alignment && size % member.alignment)
839 member.offset += member.alignment - (size % member.alignment);
840 size = member.offset;
842 type.alignment = Max(type.alignment, member.alignment);
845 if(type.alignment && size % type.alignment)
846 size += type.alignment - (size % type.alignment);
852 if(!type.members.first && type.enumName)
854 Symbol symbol = FindStruct(curContext, type.enumName);
855 if(symbol && symbol.type)
857 ComputeTypeSize(symbol.type);
858 size = symbol.type.size;
864 for(member = type.members.first; member; member = member.next)
866 uint addSize = ComputeTypeSize(member);
868 member.offset = size;
869 if(member.alignment && size % member.alignment)
870 member.offset += member.alignment - (size % member.alignment);
871 size = member.offset;
873 type.alignment = Max(type.alignment, member.alignment);
874 size = Max(size, addSize);
876 if(type.alignment && size % type.alignment)
877 size += type.alignment - (size % type.alignment);
883 TemplateParameter param = type.templateParameter;
884 Type baseType = ProcessTemplateParameterType(param);
887 size = ComputeTypeSize(baseType);
888 type.alignment = baseType.alignment;
891 type.alignment = size = sizeof(uint64);
896 type.alignment = size = sizeof(enum { test });
901 type.alignment = size = targetBits / 8; //sizeof(void *);
906 type.computing = false;
912 /*static */int AddMembers(OldList * declarations, Class _class, bool isMember, uint * retSize, Class topClass, bool *addedPadding)
914 // This function is in need of a major review when implementing private members etc.
915 DataMember topMember = isMember ? (DataMember) _class : null;
922 Context context = isMember ? null : SetupTemplatesContext(_class);
924 *addedPadding = false;
926 if(!isMember && _class.base)
928 maxSize = _class.structSize;
929 //if(_class.base.type != systemClass) // Commented out with new Instance _class
931 // DANGER: Testing this noHeadClass here...
932 if(_class.type == structClass || _class.type == noHeadClass)
933 /*totalSize = */AddMembers(declarations, _class.base, false, &totalSize, topClass, null);
936 uint baseSize = _class.base.templateClass ? _class.base.templateClass.structSize : _class.base.structSize;
937 if(maxSize > baseSize)
945 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
947 if(!member.isProperty)
953 if(member.dataTypeString)
955 OldList * specs = MkList(), * decls = MkList();
958 decl = SpecDeclFromString(member.dataTypeString, specs,
959 MkDeclaratorIdentifier(MkIdentifier(member.name)));
960 ListAdd(decls, MkStructDeclarator(decl, null));
961 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, decls, null)));
964 member.dataType = ProcessType(specs, decl);
966 ReplaceThisClassSpecifiers(specs, topClass /*member._class*/);
969 Type type = ProcessType(specs, decl);
970 DeclareType(member.dataType, false, false);
974 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
975 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
976 DeclareStruct(member.dataType._class.string, false);
979 ComputeTypeSize(member.dataType);
980 size = member.dataType.size;
981 alignment = member.dataType.alignment;
985 if(totalSize % alignment)
986 totalSize += alignment - (totalSize % alignment);
995 OldList * specs = MkList(), * list = MkList();
997 sprintf(id, "__anon%d", anonID++);
1000 AddMembers(list, (Class)member, true, &size, topClass, null);
1002 MkStructOrUnion((member.type == unionMember)?unionSpecifier:structSpecifier, null, list));
1003 ListAdd(declarations, MkClassDefDeclaration(MkStructDeclaration(specs, MkListOne(MkDeclaratorIdentifier(MkIdentifier(id))),null)));
1004 alignment = member.structAlignment;
1008 if(totalSize % alignment)
1009 totalSize += alignment - (totalSize % alignment);
1019 if(topMember && topMember.type == unionMember)
1020 *retSize = Max(*retSize, totalSize);
1022 *retSize += totalSize;
1024 else if(totalSize < maxSize && _class.type != systemClass)
1026 int autoPadding = 0;
1027 if(!isMember && _class.structAlignment && totalSize % _class.structAlignment)
1028 autoPadding = _class.structAlignment - (totalSize % _class.structAlignment);
1029 if(totalSize + autoPadding < maxSize)
1031 char sizeString[50];
1032 sprintf(sizeString, "%d", maxSize - totalSize);
1033 ListAdd(declarations,
1034 MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(CHAR)),
1035 MkListOne(MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__ecere_padding")), MkExpConstant(sizeString))), null)));
1037 *addedPadding = true;
1041 FinishTemplatesContext(context);
1042 return topMember ? topMember.memberID : _class.memberID;
1045 static int DeclareMembers(Class _class, bool isMember)
1047 DataMember topMember = isMember ? (DataMember) _class : null;
1049 Context context = isMember ? null : SetupTemplatesContext(_class);
1051 if(!isMember && (_class.type == structClass || _class.type == noHeadClass) && _class.base.type != systemClass)
1052 DeclareMembers(_class.base, false);
1054 for(member = isMember ? topMember.members.first : _class.membersAndProperties.first; member; member = member.next)
1056 if(!member.isProperty)
1063 if(member.dataType && member.dataType.kind == classType && member.dataType._class &&
1064 member.dataType._class.registered && member.dataType._class.registered.type == structClass)
1065 DeclareStruct(member.dataType._class.string, false);
1067 if(!member.dataType && member.dataTypeString)
1068 member.dataType = ProcessTypeString(member.dataTypeString, false);
1070 DeclareType(member.dataType, false, false);
1076 DeclareMembers((Class)member, true);
1083 FinishTemplatesContext(context);
1085 return topMember ? topMember.memberID : _class.memberID;
1088 static void IdentifyAnonStructs(OldList/*<ClassDef>*/ * definitions)
1092 for(def = definitions->first; def; def = def.next)
1094 if(def.type == declarationClassDef)
1096 Declaration decl = def.decl;
1097 if(decl && decl.specifiers)
1100 bool isStruct = false;
1101 for(spec = decl.specifiers->first; spec; spec = spec.next)
1103 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1105 if(spec.definitions)
1106 IdentifyAnonStructs(spec.definitions);
1112 Declarator d = null;
1113 if(decl.declarators)
1115 for(d = decl.declarators->first; d; d = d.next)
1117 Identifier idDecl = GetDeclId(d);
1125 sprintf(id, "__anon%d", anonID++);
1126 if(!decl.declarators)
1127 decl.declarators = MkList();
1128 ListAdd(decl.declarators, MkDeclaratorIdentifier(MkIdentifier(id)));
1136 void DeclareStruct(const char * name, bool skipNoHead)
1138 External external = null;
1139 Symbol classSym = FindClass(name);
1141 if(!inCompiler || !classSym) return;
1143 // We don't need any declaration for bit classes...
1144 if(classSym.registered &&
1145 (classSym.registered.type == bitClass || classSym.registered.type == unitClass || classSym.registered.type == enumClass))
1148 /*if(classSym.registered.templateClass)
1149 return DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1152 if(classSym.registered && classSym.imported && !classSym.declaredStructSym)
1154 // Add typedef struct
1156 OldList * specifiers, * declarators;
1157 OldList * declarations = null;
1158 char structName[1024];
1159 Specifier spec = null;
1160 external = (classSym.registered && classSym.registered.type == structClass) ?
1161 classSym.pointerExternal : classSym.structExternal;
1163 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1164 // Moved this one up because DeclareClass done later will need it
1166 classSym.declaring++;
1168 if(strchr(classSym.string, '<'))
1170 if(classSym.registered.templateClass)
1172 DeclareStruct(classSym.registered.templateClass.fullName, skipNoHead);
1173 classSym.declaring--;
1179 DeclareMembers(classSym.registered, false);
1182 FullClassNameCat(structName, name, false);
1184 if(external && external.declaration && external.declaration.specifiers)
1186 for(spec = external.declaration.specifiers->first; spec; spec = spec.next)
1188 if(spec.type == structSpecifier || spec.type == unionSpecifier)
1194 external = MkExternalDeclaration(null);*/
1196 if(!skipNoHead && (!spec || !spec.definitions))
1198 bool addedPadding = false;
1199 classSym.declaredStructSym = true;
1201 declarations = MkList();
1203 AddMembers(declarations, classSym.registered, false, null, classSym.registered, &addedPadding);
1205 //ListAdd(specifiers, MkSpecifier(TYPEDEF));
1206 //ListAdd(specifiers, MkStructOrUnion(structSpecifier, null, declarations));
1208 if(!declarations->count || (declarations->count == 1 && addedPadding))
1210 FreeList(declarations, FreeClassDef);
1211 declarations = null;
1214 if(skipNoHead || declarations)
1219 spec.definitions = declarations;
1221 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1224 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1227 if(classSym.structExternal)
1228 ast->Move(classSym.structExternal, curExternal.prev);
1229 ast->Move(classSym.pointerExternal, curExternal.prev);
1231 classSym.id = curExternal.symbol.idCode;
1232 classSym.idCode = curExternal.symbol.idCode;
1233 // external = classSym.pointerExternal;
1234 //external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1240 external = MkExternalDeclaration(null);
1242 specifiers = MkList();
1243 declarators = MkList();
1244 ListAdd(specifiers, MkStructOrUnion(structSpecifier, MkIdentifier(structName), declarations));
1247 d = MkDeclaratorIdentifier(MkIdentifier(structName));
1248 ListAdd(declarators, MkInitDeclarator(d, null));
1250 external.declaration = decl = MkDeclaration(specifiers, declarators);
1251 if(decl.symbol && !decl.symbol.pointerExternal)
1252 decl.symbol.pointerExternal = external;
1254 // For simple classes, keep the declaration as the external to move around
1255 if(classSym.registered && classSym.registered.type == structClass)
1257 char className[1024];
1258 strcpy(className, "__ecereClass_");
1259 FullClassNameCat(className, classSym.string, true);
1260 //MangleClassName(className);
1263 DeclareClass(classSym, className);
1265 external.symbol = classSym;
1266 classSym.pointerExternal = external;
1267 classSym.id = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1268 classSym.idCode = (curExternal && curExternal.symbol) ? curExternal.symbol.idCode : 0;
1272 char className[1024];
1273 strcpy(className, "__ecereClass_");
1274 FullClassNameCat(className, classSym.string, true);
1275 //MangleClassName(className);
1277 // TOFIX: TESTING THIS...
1278 classSym.structExternal = external;
1279 DeclareClass(classSym, className);
1280 external.symbol = classSym;
1284 ast->Insert(curExternal ? curExternal.prev : null, external);
1288 classSym.declaring--;
1292 if(classSym.structExternal && classSym.structExternal.declaration && classSym.structExternal.declaration.specifiers)
1295 for(spec = classSym.structExternal.declaration.specifiers->first; spec; spec = spec.next)
1297 IdentifyAnonStructs(spec.definitions);
1301 if(curExternal && curExternal.symbol && curExternal.symbol.idCode < classSym.id)
1303 // TEMPORARY HACK: Pass 3 will move up struct declarations without moving members
1304 // Moved this one up because DeclareClass done later will need it
1307 classSym.declaring++;
1311 if(classSym.registered)
1312 DeclareMembers(classSym.registered, false);
1315 if(classSym.registered && (classSym.registered.type == structClass || classSym.registered.type == noHeadClass))
1318 //ast->Move(classSym.structExternal ? classSym.structExternal : classSym.pointerExternal, curExternal.prev);
1321 if(classSym.structExternal)
1322 ast->Move(classSym.structExternal, curExternal.prev);
1323 ast->Move(classSym.pointerExternal, curExternal.prev);
1325 classSym.id = curExternal.symbol.idCode;
1326 classSym.idCode = curExternal.symbol.idCode;
1327 // external = classSym.pointerExternal;
1328 // external = classSym.structExternal ? classSym.structExternal : classSym.pointerExternal;
1331 classSym.declaring--;
1337 void DeclareProperty(Property prop, char * setName, char * getName)
1339 Symbol symbol = prop.symbol;
1341 strcpy(setName, "__ecereProp_");
1342 FullClassNameCat(setName, prop._class.fullName, false);
1343 strcat(setName, "_Set_");
1344 // strcat(setName, prop.name);
1345 FullClassNameCat(setName, prop.name, true);
1346 //MangleClassName(setName);
1348 strcpy(getName, "__ecereProp_");
1349 FullClassNameCat(getName, prop._class.fullName, false);
1350 strcat(getName, "_Get_");
1351 FullClassNameCat(getName, prop.name, true);
1352 // strcat(getName, prop.name);
1354 // To support "char *" property
1355 //MangleClassName(getName);
1357 if(prop._class.type == structClass)
1358 DeclareStruct(prop._class.fullName, false);
1360 if(!symbol || curExternal.symbol.idCode < symbol.id)
1362 bool imported = false;
1363 bool dllImport = false;
1365 if(!symbol || symbol._import)
1370 if(!prop._class.symbol)
1371 prop._class.symbol = FindClass(prop._class.fullName);
1372 classSym = prop._class.symbol;
1373 if(classSym && !classSym._import)
1375 ModuleImport module;
1377 if(prop._class.module)
1378 module = FindModule(prop._class.module);
1380 module = mainModule;
1382 classSym._import = ClassImport
1384 name = CopyString(prop._class.fullName);
1385 isRemote = prop._class.isRemote;
1387 module.classes.Add(classSym._import);
1389 symbol = prop.symbol = Symbol { };
1390 symbol._import = (ClassImport)PropertyImport
1392 name = CopyString(prop.name);
1393 isVirtual = false; //prop.isVirtual;
1394 hasSet = prop.Set ? true : false;
1395 hasGet = prop.Get ? true : false;
1398 classSym._import.properties.Add(symbol._import);
1401 // Ugly work around for isNan properties declared within float/double classes which are initialized with ecereCOM
1402 if((prop._class.module != privateModule || !strcmp(prop._class.name, "float") || !strcmp(prop._class.name, "double")) &&
1403 prop._class.module.importType != staticImport)
1409 Context context = SetupTemplatesContext(prop._class);
1410 symbol.type = ProcessTypeString(prop.dataTypeString, false);
1411 FinishTemplatesContext(context);
1417 if(!symbol.externalGet || symbol.externalGet.type == functionExternal)
1420 OldList * specifiers, * declarators;
1425 Declarator typeDecl;
1426 bool simple = false;
1428 specifiers = MkList();
1429 declarators = MkList();
1432 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName /*MkClassName*/(prop._class.fullName)),
1433 MkDeclaratorIdentifier(MkIdentifier("this"))));
1435 d = MkDeclaratorIdentifier(MkIdentifier(getName));
1438 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1441 Context context = SetupTemplatesContext(prop._class);
1442 typeDecl = SpecDeclFromString(prop.dataTypeString, specifiers, null);
1443 FinishTemplatesContext(context);
1446 // Make sure the simple _class's type is declared
1447 for(spec = specifiers->first; spec; spec = spec.next)
1449 if(spec.type == nameSpecifier /*SpecifierClass*/)
1451 if((!typeDecl || typeDecl.type == identifierDeclarator))
1453 Symbol classSym = spec.symbol; // FindClass(spec.name);
1454 symbol._class = classSym.registered;
1455 if(classSym.registered && classSym.registered.type == structClass)
1457 DeclareStruct(spec.name, false);
1465 d = PlugDeclarator(typeDecl, d);
1468 ListAdd(params, MkTypeName(specifiers,
1469 PlugDeclarator(typeDecl, MkDeclaratorIdentifier(MkIdentifier("value")))));
1470 specifiers = MkList();
1473 d = MkDeclaratorFunction(d, params);
1477 specifiers->Insert(null, MkSpecifier(EXTERN));
1478 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1479 specifiers->Insert(null, MkSpecifier(STATIC));
1481 ListAdd(specifiers, MkSpecifier(VOID));
1483 ListAdd(declarators, MkInitDeclarator(d, null));
1485 decl = MkDeclaration(specifiers, declarators);
1487 external = MkExternalDeclaration(decl);
1488 ast->Insert(curExternal.prev, external);
1489 external.symbol = symbol;
1490 symbol.externalGet = external;
1492 ReplaceThisClassSpecifiers(specifiers, prop._class);
1495 FreeDeclarator(typeDecl);
1499 // Move declaration higher...
1500 ast->Move(symbol.externalGet, curExternal.prev);
1507 if(!symbol.externalSet || symbol.externalSet.type == functionExternal)
1510 OldList * specifiers, * declarators;
1515 Declarator typeDecl;
1517 declarators = MkList();
1520 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1521 if(!prop.conversion || prop._class.type == structClass)
1523 ListAdd(params, MkTypeName(MkListOne(MkSpecifierName/*MkClassName*/(prop._class.fullName)),
1524 MkDeclaratorIdentifier(MkIdentifier("this"))));
1527 specifiers = MkList();
1530 Context context = SetupTemplatesContext(prop._class);
1531 typeDecl = d = SpecDeclFromString(prop.dataTypeString, specifiers,
1532 MkDeclaratorIdentifier(MkIdentifier("value")));
1533 FinishTemplatesContext(context);
1535 if(!strcmp(prop._class.base.fullName, "eda::Row") || !strcmp(prop._class.base.fullName, "eda::Id"))
1536 specifiers->Insert(null, MkSpecifier(CONST));
1538 ListAdd(params, MkTypeName(specifiers, d));
1540 d = MkDeclaratorIdentifier(MkIdentifier(setName));
1543 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
1544 d = MkDeclaratorFunction(d, params);
1546 // Make sure the simple _class's type is declared
1547 for(spec = specifiers->first; spec; spec = spec.next)
1549 if(spec.type == nameSpecifier /*SpecifierClass*/)
1551 if((!typeDecl || typeDecl.type == identifierDeclarator))
1553 Symbol classSym = spec.symbol; // FindClass(spec.name);
1554 symbol._class = classSym.registered;
1555 if(classSym.registered && classSym.registered.type == structClass)
1556 DeclareStruct(spec.name, false);
1561 ListAdd(declarators, MkInitDeclarator(d, null));
1563 specifiers = MkList();
1566 specifiers->Insert(null, MkSpecifier(EXTERN));
1567 else if(prop._class.symbol && ((Symbol)prop._class.symbol).isStatic)
1568 specifiers->Insert(null, MkSpecifier(STATIC));
1570 // TESTING COMMENTING THIS FIRST LINE OUT, what was the problem? Trying to add noHeadClass here ...
1571 if(!prop.conversion || prop._class.type == structClass)
1572 ListAdd(specifiers, MkSpecifier(VOID));
1574 ListAdd(specifiers, MkSpecifierName/*MkClassName*/(prop._class.fullName));
1576 decl = MkDeclaration(specifiers, declarators);
1578 external = MkExternalDeclaration(decl);
1579 ast->Insert(curExternal.prev, external);
1580 external.symbol = symbol;
1581 symbol.externalSet = external;
1583 ReplaceThisClassSpecifiers(specifiers, prop._class);
1587 // Move declaration higher...
1588 ast->Move(symbol.externalSet, curExternal.prev);
1592 // Property (for Watchers)
1593 if(!symbol.externalPtr)
1597 OldList * specifiers = MkList();
1598 char propName[1024];
1601 specifiers->Insert(null, MkSpecifier(EXTERN));
1604 specifiers->Insert(null, MkSpecifier(STATIC));
1605 specifiers->Add(MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
1608 ListAdd(specifiers, MkSpecifierName("Property"));
1610 strcpy(propName, "__ecereProp_");
1611 FullClassNameCat(propName, prop._class.fullName, false);
1612 strcat(propName, "_");
1613 FullClassNameCat(propName, prop.name, true);
1614 // strcat(propName, prop.name);
1615 //MangleClassName(propName);
1618 OldList * list = MkList();
1619 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1623 strcpy(propName, "__ecerePropM_");
1624 FullClassNameCat(propName, prop._class.fullName, false);
1625 strcat(propName, "_");
1626 // strcat(propName, prop.name);
1627 FullClassNameCat(propName, prop.name, true);
1629 //MangleClassName(propName);
1631 ListAdd(list, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(propName)), null));
1633 decl = MkDeclaration(specifiers, list);
1636 external = MkExternalDeclaration(decl);
1637 ast->Insert(curExternal.prev, external);
1638 external.symbol = symbol;
1639 symbol.externalPtr = external;
1643 // Move declaration higher...
1644 ast->Move(symbol.externalPtr, curExternal.prev);
1647 symbol.id = curExternal.symbol.idCode;
1651 // ***************** EXPRESSION PROCESSING ***************************
1652 public Type Dereference(Type source)
1657 if(source.kind == pointerType || source.kind == arrayType)
1660 source.type.refCount++;
1662 else if(source.kind == classType && !strcmp(source._class.string, "String"))
1670 // Support dereferencing of no head classes for now...
1671 else if(source.kind == classType && source._class && source._class.registered && source._class.registered.type == noHeadClass)
1677 Compiler_Error($"cannot dereference type\n");
1682 static Type Reference(Type source)
1698 void ProcessMemberInitData(MemberInit member, Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
1700 Identifier ident = member.identifiers ? member.identifiers->first : null;
1702 DataMember dataMember = null;
1703 Method method = null;
1704 bool freeType = false;
1706 yylloc = member.loc;
1712 eClass_FindNextMember(_class, curClass, curMember, subMemberStack, subMemberStackPos);
1716 dataMember = *curMember;
1722 DataMember thisMember = (DataMember)eClass_FindProperty(_class, ident.string, privateModule);
1723 DataMember _subMemberStack[256];
1724 int _subMemberStackPos = 0;
1726 // FILL MEMBER STACK
1728 thisMember = eClass_FindDataMember(_class, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
1731 dataMember = thisMember;
1732 if(curMember && thisMember.memberAccess == publicAccess)
1734 *curMember = thisMember;
1735 *curClass = thisMember._class;
1736 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
1737 *subMemberStackPos = _subMemberStackPos;
1744 method = eClass_FindMethod(_class, ident.string, privateModule);
1745 if(method && method.type == virtualMethod)
1757 if(!dataMember.dataType && dataMember.dataTypeString)
1759 //Context context = SetupTemplatesContext(dataMember._class);
1760 Context context = SetupTemplatesContext(_class);
1761 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
1762 FinishTemplatesContext(context);
1764 type = dataMember.dataType;
1768 // This is for destination type...
1769 if(!method.dataType)
1770 ProcessMethodType(method);
1771 //DeclareMethod(method);
1772 // method.dataType = ((Symbol)method.symbol)->type;
1773 type = method.dataType;
1776 if(ident && ident.next)
1778 for(ident = ident.next; ident && type; ident = ident.next)
1780 if(type.kind == classType)
1782 dataMember = (DataMember)eClass_FindProperty(type._class.registered, ident.string, privateModule);
1784 dataMember = eClass_FindDataMember(type._class.registered, ident.string, privateModule, null, null);
1786 type = dataMember.dataType;
1788 else if(type.kind == structType || type.kind == unionType)
1791 for(memberType = type.members.first; memberType; memberType = memberType.next)
1793 if(!strcmp(memberType.name, ident.string))
1803 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
1804 if(type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type && _class.templateArgs /* TODO: Watch out for these _class.templateClass*/)
1807 ClassTemplateParameter curParam = null;
1809 for(sClass = _class; sClass; sClass = sClass.base)
1812 if(sClass.templateClass) sClass = sClass.templateClass;
1813 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
1815 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
1817 for(sClass = sClass.base; sClass; sClass = sClass.base)
1819 if(sClass.templateClass) sClass = sClass.templateClass;
1820 id += sClass.templateParams.count;
1831 ClassTemplateArgument arg = _class.templateArgs[id];
1832 if(arg.dataTypeString)
1834 bool constant = type.constant;
1836 type = ProcessTypeString(arg.dataTypeString, false);
1837 if(type.kind == classType && constant) type.constant = true;
1838 else if(type.kind == pointerType)
1841 while(t.kind == pointerType) t = t.type;
1842 if(constant) t.constant = constant;
1845 if(type && _class.templateClass)
1846 type.passAsTemplate = true;
1852 exp.destType = ProcessTypeString(arg.dataTypeString, false);
1853 exp.destType.refCount++;
1859 if(type && type.kind == classType && type._class && type._class.registered && strchr(type._class.registered.fullName, '<'))
1861 Class expClass = type._class.registered;
1862 Class cClass = null;
1866 char templateString[1024];
1867 ClassTemplateParameter param;
1868 sprintf(templateString, "%s<", expClass.templateClass.fullName);
1869 for(cClass = expClass; cClass; cClass = cClass.base)
1872 if(cClass.templateClass) cClass = cClass.templateClass;
1873 for(param = cClass.templateParams.first; param; param = param.next)
1877 ClassTemplateArgument arg;
1878 for(sClass = cClass.base; sClass; sClass = sClass.base)
1880 if(sClass.templateClass) sClass = sClass.templateClass;
1881 id += sClass.templateParams.count;
1883 arg = expClass.templateArgs[id];
1885 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
1887 ClassTemplateParameter cParam;
1888 //int p = numParams - sClass.templateParams.count;
1891 if(sClass.templateClass) sClass = sClass.templateClass;
1893 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
1895 if(nextClass.templateClass) nextClass = nextClass.templateClass;
1896 p += nextClass.templateParams.count;
1899 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
1901 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
1903 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1905 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
1906 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
1918 strcat(argument, arg.name.string);
1919 strcat(argument, " = ");
1925 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
1926 char expString[1024];
1927 OldList * specs = MkList();
1928 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
1930 char * string = PrintHexUInt64(arg.expression.ui64);
1931 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
1934 ProcessExpressionType(exp);
1935 ComputeExpression(exp);
1936 expString[0] = '\0';
1937 PrintExpression(exp, expString);
1938 strcat(argument, expString);
1940 FreeExpression(exp);
1945 strcat(argument, arg.member.name);
1948 case TemplateParameterType::type:
1950 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
1951 strcat(argument, arg.dataTypeString);
1957 if(paramCount) strcat(templateString, ", ");
1958 if(lastParam != p - 1)
1960 strcat(templateString, param.name);
1961 strcat(templateString, " = ");
1963 strcat(templateString, argument);
1972 int len = strlen(templateString);
1973 if(templateString[len-1] == '<')
1977 if(templateString[len-1] == '>')
1978 templateString[len++] = ' ';
1979 templateString[len++] = '>';
1981 templateString[len++] = '\0';
1984 Context context = SetupTemplatesContext(_class);
1985 if(freeType) FreeType(type);
1986 type = ProcessTypeString(templateString, false);
1988 FinishTemplatesContext(context);
1992 if(method && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
1994 ProcessExpressionType(member.initializer.exp);
1995 if(!member.initializer.exp.expType)
1999 char expString[10240];
2000 expString[0] = '\0';
2001 PrintExpression(member.initializer.exp, expString);
2002 ChangeCh(expString, '\n', ' ');
2003 Compiler_Error($"unresolved symbol used as an instance method %s\n", expString);
2006 //else if(!MatchTypes(member.exp.expType, type, null, _class, null, true, true, false, false))
2007 else if(!MatchTypes(member.initializer.exp.expType, type, null, null, _class, true, true, false, false, true))
2009 Compiler_Error($"incompatible instance method %s\n", ident.string);
2012 else if(member.initializer)
2015 FreeType(member.exp.destType);
2016 member.exp.destType = type;
2017 if(member.exp.destType)
2018 member.exp.destType.refCount++;
2019 ProcessExpressionType(member.exp);
2022 ProcessInitializer(member.initializer, type);
2024 if(freeType) FreeType(type);
2028 if(_class && _class.type == unitClass)
2030 if(member.initializer)
2033 FreeType(member.exp.destType);
2034 member.exp.destType = MkClassType(_class.fullName);
2035 ProcessExpressionType(member.initializer, type);
2037 Type type = MkClassType(_class.fullName);
2038 ProcessInitializer(member.initializer, type);
2044 if(member.initializer)
2046 //ProcessExpressionType(member.exp);
2047 ProcessInitializer(member.initializer, null);
2053 Compiler_Error($"couldn't find virtual method %s in class %s\n", ident.string, _class.fullName);
2057 Compiler_Error($"couldn't find member %s in class %s\n", ident.string, _class.fullName);
2059 eClass_AddDataMember(_class, ident.string, "int", 0, 0, publicAccess);
2063 Compiler_Error($"too many initializers for instantiation of class %s\n", _class.fullName);
2068 void ProcessInstantiationType(Instantiation inst)
2073 MembersInit members;
2074 Symbol classSym; // = inst._class.symbol; // FindClass(inst._class.name);
2077 /*if(!inst._class.symbol)
2078 inst._class.symbol = FindClass(inst._class.name);*/
2079 classSym = inst._class.symbol;
2080 _class = classSym ? classSym.registered : null;
2082 // DANGER: Patch for mutex not declaring its struct when not needed
2083 if(!_class || _class.type != noHeadClass)
2084 DeclareStruct(inst._class.name, false); //_class && _class.type == noHeadClass);
2086 afterExternal = afterExternal ? afterExternal : curExternal;
2089 ProcessExpressionType(inst.exp);
2091 inst.isConstant = true;
2094 DataMember curMember = null;
2095 Class curClass = null;
2096 DataMember subMemberStack[256];
2097 int subMemberStackPos = 0;
2099 for(members = inst.members->first; members; members = members.next)
2101 switch(members.type)
2103 case methodMembersInit:
2106 static uint instMethodID = 0;
2107 External external = curExternal;
2108 Context context = curContext;
2109 Declarator declarator = members.function.declarator;
2110 Identifier nameID = GetDeclId(declarator);
2111 char * unmangled = nameID ? nameID.string : null;
2113 External createdExternal = null;
2118 //members.function.dontMangle = true;
2119 strcpy(name, "__ecereInstMeth_");
2120 FullClassNameCat(name, _class ? _class.fullName : "_UNKNOWNCLASS", false);
2122 strcat(name, nameID.string);
2124 sprintf(number, "_%08d", instMethodID++);
2125 strcat(name, number);
2126 nameID.string = CopyString(name);
2129 // Do modifications here...
2132 Symbol symbol = declarator.symbol;
2133 Method method = eClass_FindMethod(_class, unmangled, privateModule);
2135 if(method && method.type == virtualMethod)
2137 symbol.method = method;
2138 ProcessMethodType(method);
2140 if(!symbol.type.thisClass)
2142 if(method.dataType.thisClass && currentClass &&
2143 eClass_IsDerived(currentClass, method.dataType.thisClass.registered))
2145 if(!currentClass.symbol)
2146 currentClass.symbol = FindClass(currentClass.fullName);
2147 symbol.type.thisClass = currentClass.symbol;
2152 _class.symbol = FindClass(_class.fullName);
2153 symbol.type.thisClass = _class.symbol;
2156 // TESTING THIS HERE:
2157 DeclareType(symbol.type, true, true);
2162 Compiler_Error($"couldn't find virtual method %s in class %s\n",
2163 unmangled, classSym.string);
2167 //declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2168 createdExternal = ProcessClassFunction(classSym ? classSym.registered : null, members.function, ast, afterExternal, true);
2172 FreeSpecifier(nameID._class);
2173 nameID._class = null;
2178 //Type type = declarator.symbol.type;
2179 External oldExternal = curExternal;
2181 // *** Commented this out... Any negative impact? Yes: makes double prototypes declarations... Why was it commented out?
2182 // *** It was commented out for problems such as
2184 class VirtualDesktop : Window
2186 clientSize = Size { };
2197 // Commented Out: Good for bet.ec in Poker (Otherwise: obj\bet.c:187: error: `currentBet' undeclared (first use in this function))
2199 declarator.symbol.id = declarator.symbol.idCode = curExternal.symbol.idCode;
2202 if(strcmp(declarator.symbol.string, name))
2204 printf("TOCHECK: Look out for this\n");
2205 delete declarator.symbol.string;
2206 declarator.symbol.string = CopyString(name);
2209 if(!declarator.symbol.parent && globalContext.symbols.root != (BTNode)declarator.symbol)
2211 printf("TOCHECK: Will this ever be in a list? Yes.\n");
2212 excludedSymbols->Remove(declarator.symbol);
2213 globalContext.symbols.Add((BTNode)declarator.symbol);
2214 if(strstr(declarator.symbol.string), "::")
2215 globalContext.hasNameSpace = true;
2220 //curExternal = curExternal.prev;
2221 //afterExternal = afterExternal->next;
2223 //ProcessFunction(afterExternal->function);
2225 //curExternal = afterExternal;
2227 External externalDecl;
2228 externalDecl = MkExternalDeclaration(null);
2229 ast->Insert(oldExternal.prev, externalDecl);
2231 // Which function does this process?
2232 if(createdExternal.function)
2234 ProcessFunction(createdExternal.function);
2236 //curExternal = oldExternal;
2239 //Declaration decl = MkDeclaration(members.function.specifiers, MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2241 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
2242 MkListOne(MkInitDeclarator(CopyDeclarator(declarator), null)));
2244 //externalDecl = MkExternalDeclaration(decl);
2246 //***** ast->Insert(external.prev, externalDecl);
2247 //ast->Insert(curExternal.prev, externalDecl);
2248 externalDecl.declaration = decl;
2249 if(decl.symbol && !decl.symbol.pointerExternal)
2250 decl.symbol.pointerExternal = externalDecl;
2252 // Trying this out...
2253 declarator.symbol.pointerExternal = externalDecl;
2260 curExternal = declarator.symbol.pointerExternal;
2261 ProcessFunction((FunctionDefinition)members.function);
2263 curExternal = external;
2264 curContext = context;
2268 FreeClassFunction(members.function);
2270 // In this pass, turn this into a MemberInitData
2271 exp = QMkExpId(name);
2272 members.type = dataMembersInit;
2273 members.dataMembers = MkListOne(MkMemberInit(MkListOne(MkIdentifier(unmangled)), MkInitializerAssignment(exp)));
2279 case dataMembersInit:
2281 if(members.dataMembers && classSym)
2284 Location oldyyloc = yylloc;
2285 for(member = members.dataMembers->first; member; member = member.next)
2287 ProcessMemberInitData(member, classSym.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
2288 if(member.initializer && !member.initializer.isConstant)
2289 inst.isConstant = false;
2301 static void DeclareType(Type type, bool declarePointers, bool declareParams)
2303 // OPTIMIZATIONS: TESTING THIS...
2306 if(type.kind == functionType)
2311 for(param = type.params.first; param; param = param.next)
2312 DeclareType(param, declarePointers, true);
2314 DeclareType(type.returnType, declarePointers, true);
2316 else if(type.kind == pointerType && declarePointers)
2317 DeclareType(type.type, declarePointers, false);
2318 else if(type.kind == classType)
2320 if(type._class.registered && (type._class.registered.type == structClass || type._class.registered.type == noHeadClass) && !type._class.declaring)
2321 DeclareStruct(type._class.registered.fullName, type._class.registered.type == noHeadClass);
2323 else if(type.kind == structType || type.kind == unionType)
2326 for(member = type.members.first; member; member = member.next)
2327 DeclareType(member, false, false);
2329 else if(type.kind == arrayType)
2330 DeclareType(type.arrayType, declarePointers, false);
2334 ClassTemplateArgument * FindTemplateArg(Class _class, TemplateParameter param)
2336 ClassTemplateArgument * arg = null;
2338 ClassTemplateParameter curParam = null;
2340 for(sClass = _class; sClass; sClass = sClass.base)
2343 if(sClass.templateClass) sClass = sClass.templateClass;
2344 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
2346 if(curParam.type == TemplateParameterType::type && !strcmp(param.identifier.string, curParam.name))
2348 for(sClass = sClass.base; sClass; sClass = sClass.base)
2350 if(sClass.templateClass) sClass = sClass.templateClass;
2351 id += sClass.templateParams.count;
2361 arg = &_class.templateArgs[id];
2362 if(arg && param.type == type)
2363 arg->dataTypeClass = eSystem_FindClass(_class.module, arg->dataTypeString);
2368 public Context SetupTemplatesContext(Class _class)
2370 Context context = PushContext();
2371 context.templateTypesOnly = true;
2372 if(_class.symbol && ((Symbol)_class.symbol).templateParams)
2374 TemplateParameter param = ((Symbol)_class.symbol).templateParams->first;
2375 for(; param; param = param.next)
2377 if(param.type == type && param.identifier)
2379 TemplatedType type { key = (uintptr)param.identifier.string, param = param };
2380 curContext.templateTypes.Add((BTNode)type);
2387 for(sClass = _class; sClass; sClass = sClass.base)
2389 ClassTemplateParameter p;
2390 for(p = sClass.templateParams.first; p; p = p.next)
2392 //OldList * specs = MkList();
2393 //Declarator decl = null;
2394 //decl = SpecDeclFromString(p.dataTypeString, specs, null);
2397 TemplateParameter param = p.param;
2401 // ADD DATA TYPE HERE...
2402 p.param = param = TemplateParameter
2404 identifier = MkIdentifier(p.name), type = p.type,
2405 dataTypeString = p.dataTypeString /*, dataType = { specs, decl }*/
2408 type = TemplatedType { key = (uintptr)p.name, param = param };
2409 curContext.templateTypes.Add((BTNode)type);
2417 public void FinishTemplatesContext(Context context)
2419 PopContext(context);
2420 FreeContext(context);
2424 public void ProcessMethodType(Method method)
2426 if(!method.dataType)
2428 Context context = SetupTemplatesContext(method._class);
2430 method.dataType = ProcessTypeString(method.dataTypeString, false);
2432 FinishTemplatesContext(context);
2434 if(method.type != virtualMethod && method.dataType)
2436 if(!method.dataType.thisClass && !method.dataType.staticMethod)
2438 if(!method._class.symbol)
2439 method._class.symbol = FindClass(method._class.fullName);
2440 method.dataType.thisClass = method._class.symbol;
2444 // Why was this commented out? Working fine without now...
2447 if(method.dataType.kind == functionType && !method.dataType.staticMethod && !method.dataType.thisClass)
2448 method.dataType.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2455 char * par = strstr(type, "(");
2456 char * classOp = null;
2461 for(c = par-type-1; c >= 0; c++)
2463 if(type[c] == ':' && type[c+1] == ':')
2465 classOp = type + c - 1;
2466 for(c = c-1; c >=0 && !isspace(type[c]); c--)
2473 else if(!isspace(type[c]))
2480 int typeLen = strlen(type);
2481 memcpy(temp, classOp, classOpLen);
2482 temp[classOpLen] = '\0';
2484 _class = eSystem_FindClass(module, temp);
2487 method.dataTypeString = new char[typeLen - classOpLen + 1];
2488 memcpy(method.dataTypeString, type, classOp - type);
2489 memcpy(method.dataTypeString + (classOp - type), classOp + classOpLen, typeLen - (classOp - type + classOpLen));
2492 method.dataTypeString = type;
2498 public void ProcessPropertyType(Property prop)
2502 Context context = SetupTemplatesContext(prop._class);
2503 prop.dataType = ProcessTypeString(prop.dataTypeString, false);
2504 FinishTemplatesContext(context);
2508 public void DeclareMethod(Method method, const char * name)
2510 Symbol symbol = method.symbol;
2511 if(!symbol || (!symbol.pointerExternal && method.type == virtualMethod) || symbol.id > (curExternal ? curExternal.symbol.idCode : -1))
2513 //bool imported = false;
2514 bool dllImport = false;
2516 if(!method.dataType)
2517 method.dataType = ProcessTypeString(method.dataTypeString, false);
2519 if(!symbol || symbol._import || method.type == virtualMethod)
2521 if(!symbol || method.type == virtualMethod)
2524 if(!method._class.symbol)
2525 method._class.symbol = FindClass(method._class.fullName);
2526 classSym = method._class.symbol;
2527 if(!classSym._import)
2529 ModuleImport module;
2531 if(method._class.module && method._class.module.name)
2532 module = FindModule(method._class.module);
2534 module = mainModule;
2535 classSym._import = ClassImport
2537 name = CopyString(method._class.fullName);
2538 isRemote = method._class.isRemote;
2540 module.classes.Add(classSym._import);
2544 symbol = method.symbol = Symbol { };
2548 symbol._import = (ClassImport)MethodImport
2550 name = CopyString(method.name);
2551 isVirtual = method.type == virtualMethod;
2553 classSym._import.methods.Add(symbol._import);
2557 // Set the symbol type
2561 type.thisClass = method._class.symbol; // FindClass(method._class.fullName);
2563 else if(type.thisClass == (void *)-1)
2565 type.thisClass = null;
2568 // symbol.type = ProcessTypeString(method.dataTypeString, false);
2569 symbol.type = method.dataType;
2570 if(symbol.type) symbol.type.refCount++;
2573 if(!method.thisClass || strcmp(method.thisClass, "void"))
2574 symbol.type.params.Insert(null,
2575 MkClassType(method.thisClass ? method.thisClass : method._class.fullName));
2578 if(!method.dataType.dllExport)
2581 if((method._class.module != privateModule || !strcmp(method._class.name, "float") || !strcmp(method._class.name, "double")) && method._class.module.importType != staticImport)
2587 if(!method.dataType)
2588 method.dataType = ((Symbol)method.symbol).type;
2589 //ProcessMethodType(method);
2592 if(method.type != virtualMethod && method.dataType)
2593 DeclareType(method.dataType, true, true);
2595 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2597 // We need a declaration here :)
2599 OldList * specifiers, * declarators;
2601 Declarator funcDecl;
2604 specifiers = MkList();
2605 declarators = MkList();
2609 ListAdd(specifiers, MkSpecifier(EXTERN));
2610 else if(method._class.symbol && ((Symbol)method._class.symbol).isStatic)
2611 ListAdd(specifiers, MkSpecifier(STATIC));
2613 if(method.type == virtualMethod)
2615 ListAdd(specifiers, MkSpecifier(INT));
2616 d = MkDeclaratorIdentifier(MkIdentifier(name));
2620 d = MkDeclaratorIdentifier(MkIdentifier(name));
2623 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2625 Context context = SetupTemplatesContext(method._class);
2626 d = SpecDeclFromString(method.dataTypeString, specifiers, d);
2627 FinishTemplatesContext(context);
2629 funcDecl = GetFuncDecl(d);
2633 Specifier spec, next;
2634 for(spec = specifiers->first; spec; spec = next)
2637 if(spec.type == extendedSpecifier)
2639 specifiers->Remove(spec);
2640 FreeSpecifier(spec);
2645 // Add this parameter if not a static method
2646 if(method.dataType && !method.dataType.staticMethod)
2648 if(funcDecl && funcDecl.function.parameters && funcDecl.function.parameters->count)
2650 Class _class = method.dataType.thisClass ? method.dataType.thisClass.registered : method._class;
2651 TypeName thisParam = MkTypeName(MkListOne(
2652 MkSpecifierName/*MkClassName*/(method.dataType.thisClass ? method.dataType.thisClass.string : method._class.fullName)),
2653 (_class && _class.type == systemClass) ? MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("this"))) : MkDeclaratorIdentifier(MkIdentifier("this")));
2654 TypeName firstParam = ((TypeName)funcDecl.function.parameters->first);
2655 Specifier firstSpec = firstParam.qualifiers ? firstParam.qualifiers->first : null;
2657 if(firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
2659 TypeName param = funcDecl.function.parameters->first;
2660 funcDecl.function.parameters->Remove(param);
2661 FreeTypeName(param);
2664 if(!funcDecl.function.parameters)
2665 funcDecl.function.parameters = MkList();
2666 funcDecl.function.parameters->Insert(null, thisParam);
2669 // Make sure we don't have empty parameter declarations for static methods...
2671 else if(!funcDecl.function.parameters)
2673 funcDecl.function.parameters = MkList();
2674 funcDecl.function.parameters->Insert(null,
2675 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2679 ProcessDeclarator(d);
2681 ListAdd(declarators, MkInitDeclarator(d, null));
2683 decl = MkDeclaration(specifiers, declarators);
2685 ReplaceThisClassSpecifiers(specifiers, method._class);
2687 // Keep a different symbol for the function definition than the declaration...
2688 if(symbol.pointerExternal)
2690 Symbol functionSymbol { };
2694 *functionSymbol = *symbol;
2695 functionSymbol.string = CopyString(symbol.string);
2696 if(functionSymbol.type)
2697 functionSymbol.type.refCount++;
2700 excludedSymbols->Add(functionSymbol);
2701 symbol.pointerExternal.symbol = functionSymbol;
2703 external = MkExternalDeclaration(decl);
2705 ast->Insert(curExternal ? curExternal.prev : null, external);
2706 external.symbol = symbol;
2707 symbol.pointerExternal = external;
2711 // Move declaration higher...
2712 ast->Move(symbol.pointerExternal, curExternal.prev);
2715 symbol.id = curExternal ? curExternal.symbol.idCode : MAXINT;
2719 char * ReplaceThisClass(Class _class)
2721 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2725 ClassTemplateParameter param;
2728 char className[1024];
2729 strcpy(className, _class.fullName);
2730 for(param = _class.templateParams.first; param; param = param.next)
2732 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2734 if(first) strcat(className, "<");
2735 if(!first) strcat(className, ", ");
2736 if(lastParam + 1 != p)
2738 strcat(className, param.name);
2739 strcat(className, " = ");
2741 strcat(className, param.name);
2749 int len = strlen(className);
2750 if(className[len-1] == '>') className[len++] = ' ';
2751 className[len++] = '>';
2752 className[len++] = '\0';
2754 return CopyString(className);
2757 return CopyString(_class.fullName);
2760 Type ReplaceThisClassType(Class _class)
2763 if(thisClassParams && _class.templateParams.count && !_class.templateClass)
2767 ClassTemplateParameter param;
2769 char className[1024];
2770 strcpy(className, _class.fullName);
2772 for(param = _class.templateParams.first; param; param = param.next)
2774 // if((!param.defaultArg.dataTypeString && !param.defaultArg.expression.ui64))
2776 if(first) strcat(className, "<");
2777 if(!first) strcat(className, ", ");
2778 if(lastParam + 1 != p)
2780 strcat(className, param.name);
2781 strcat(className, " = ");
2783 strcat(className, param.name);
2791 int len = strlen(className);
2792 if(className[len-1] == '>') className[len++] = ' ';
2793 className[len++] = '>';
2794 className[len++] = '\0';
2796 type = MkClassType(className);
2797 //type = ProcessTypeString(className, false);
2801 type = MkClassType(_class.fullName);
2802 //type = ProcessTypeString(_class.fullName, false);
2804 //type.wasThisClass = true;
2808 void ReplaceThisClassSpecifiers(OldList specs, Class _class)
2810 if(specs != null && _class)
2813 for(spec = specs.first; spec; spec = spec.next)
2815 if(spec.type == baseSpecifier && spec.specifier == THISCLASS)
2817 spec.type = nameSpecifier;
2818 spec.name = ReplaceThisClass(_class);
2819 spec.symbol = FindClass(spec.name); //_class.symbol;
2825 // Returns imported or not
2826 bool DeclareFunction(GlobalFunction function, char * name)
2828 Symbol symbol = function.symbol;
2829 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2831 bool imported = false;
2832 bool dllImport = false;
2834 if(!function.dataType)
2836 function.dataType = ProcessTypeString(function.dataTypeString, false);
2837 if(!function.dataType.thisClass)
2838 function.dataType.staticMethod = true;
2845 ModuleImport module = FindModule(function.module);
2846 // WARNING: This is not added anywhere...
2847 symbol = function.symbol = Symbol { };
2851 if(!function.dataType.dllExport)
2853 symbol._import = (ClassImport)FunctionImport { name = CopyString(function.name) };
2854 module.functions.Add(symbol._import);
2857 // Set the symbol type
2859 symbol.type = ProcessTypeString(function.dataTypeString, false);
2860 if(!symbol.type.thisClass)
2861 symbol.type.staticMethod = true;
2864 imported = symbol._import ? true : false;
2865 if(imported && function.module != privateModule && function.module.importType != staticImport)
2869 DeclareType(function.dataType, true, true);
2873 if(!symbol.pointerExternal || symbol.pointerExternal.type == functionExternal)
2875 // We need a declaration here :)
2877 OldList * specifiers, * declarators;
2879 Declarator funcDecl;
2882 specifiers = MkList();
2883 declarators = MkList();
2886 ListAdd(specifiers, MkSpecifier(EXTERN));
2889 ListAdd(specifiers, MkSpecifier(STATIC));
2892 d = MkDeclaratorIdentifier(MkIdentifier(imported ? name : function.name));
2895 d = MkDeclaratorBrackets(MkDeclaratorPointer(MkPointer(null, null), d));
2897 d = SpecDeclFromString(function.dataTypeString, specifiers, d);
2898 // TAKE OUT THE DLL EXPORT IF STATICALLY IMPORTED:
2899 if(function.module.importType == staticImport)
2902 for(spec = specifiers->first; spec; spec = spec.next)
2903 if(spec.type == extendedSpecifier && spec.extDecl && spec.extDecl.type == extDeclString && !strcmp(spec.extDecl.s, "dllexport"))
2905 specifiers->Remove(spec);
2906 FreeSpecifier(spec);
2911 funcDecl = GetFuncDecl(d);
2913 // Make sure we don't have empty parameter declarations for static methods...
2914 if(funcDecl && !funcDecl.function.parameters)
2916 funcDecl.function.parameters = MkList();
2917 funcDecl.function.parameters->Insert(null,
2918 MkTypeName(MkListOne(MkSpecifier(VOID)),null));
2921 ListAdd(declarators, MkInitDeclarator(d, null));
2924 Context oldCtx = curContext;
2925 curContext = globalContext;
2926 decl = MkDeclaration(specifiers, declarators);
2927 curContext = oldCtx;
2930 // Keep a different symbol for the function definition than the declaration...
2931 if(symbol.pointerExternal)
2933 Symbol functionSymbol { };
2936 *functionSymbol = *symbol;
2937 functionSymbol.string = CopyString(symbol.string);
2938 if(functionSymbol.type)
2939 functionSymbol.type.refCount++;
2942 excludedSymbols->Add(functionSymbol);
2944 symbol.pointerExternal.symbol = functionSymbol;
2946 external = MkExternalDeclaration(decl);
2948 ast->Insert(curExternal.prev, external);
2949 external.symbol = symbol;
2950 symbol.pointerExternal = external;
2954 // Move declaration higher...
2955 ast->Move(symbol.pointerExternal, curExternal.prev);
2959 symbol.id = curExternal.symbol.idCode;
2962 return (symbol && symbol._import && function.module != privateModule && function.module.importType != staticImport) ? true : false;
2965 void DeclareGlobalData(GlobalData data)
2967 Symbol symbol = data.symbol;
2968 if(curExternal && (!symbol || symbol.id > curExternal.symbol.idCode))
2973 symbol = data.symbol = Symbol { };
2976 data.dataType = ProcessTypeString(data.dataTypeString, false);
2977 DeclareType(data.dataType, true, true);
2980 if(!symbol.pointerExternal)
2982 // We need a declaration here :)
2984 OldList * specifiers, * declarators;
2988 specifiers = MkList();
2989 declarators = MkList();
2991 ListAdd(specifiers, MkSpecifier(EXTERN));
2992 d = MkDeclaratorIdentifier(MkIdentifier(data.fullName));
2993 d = SpecDeclFromString(data.dataTypeString, specifiers, d);
2995 ListAdd(declarators, MkInitDeclarator(d, null));
2997 decl = MkDeclaration(specifiers, declarators);
2998 external = MkExternalDeclaration(decl);
3000 ast->Insert(curExternal.prev, external);
3001 external.symbol = symbol;
3002 symbol.pointerExternal = external;
3006 // Move declaration higher...
3007 ast->Move(symbol.pointerExternal, curExternal.prev);
3011 symbol.id = curExternal.symbol.idCode;
3016 class Conversion : struct
3018 Conversion prev, next;
3024 static bool CheckConstCompatibility(Type source, Type dest, bool warn)
3027 if(((source.kind == classType && source._class && source._class.registered) || source.kind == arrayType || source.kind == pointerType) &&
3028 ((dest.kind == classType && dest._class && dest._class.registered) || /*dest.kind == arrayType || */dest.kind == pointerType))
3030 Class sourceClass = source.kind == classType ? source._class.registered : null;
3031 Class destClass = dest.kind == classType ? dest._class.registered : null;
3032 if((!sourceClass || (sourceClass && sourceClass.type == normalClass && !sourceClass.structSize)) &&
3033 (!destClass || (destClass && destClass.type == normalClass && !destClass.structSize)))
3035 Type sourceType = source, destType = dest;
3036 while((sourceType.kind == pointerType || sourceType.kind == arrayType) && sourceType.type) sourceType = sourceType.type;
3037 while((destType.kind == pointerType || destType.kind == arrayType) && destType.type) destType = destType.type;
3038 if(!destType.constant && sourceType.constant)
3042 Compiler_Warning($"discarding const qualifier\n");
3049 public bool MatchTypes(Type source, Type dest, OldList conversions, Class owningClassSource, Class owningClassDest, bool doConversion, bool enumBaseType, bool acceptReversedParams,
3050 bool isConversionExploration, bool warnConst)
3055 CheckConstCompatibility(source, dest, true);
3056 // Property convert;
3058 if(source.kind == templateType && dest.kind != templateType)
3060 Type type = ProcessTemplateParameterType(source.templateParameter);
3061 if(type) source = type;
3064 if(dest.kind == templateType && source.kind != templateType)
3066 Type type = ProcessTemplateParameterType(dest.templateParameter);
3067 if(type) dest = type;
3070 if(dest.classObjectType == typedObject && dest.kind != functionType)
3072 if(source.classObjectType != anyObject)
3076 // If either the source or the destination defines the class, accepts any_object as compatible for a typed_object
3077 if((dest._class && strcmp(dest._class.string, "class")) || (source._class && strcmp(source._class.string, "class")))
3085 if(source.kind != functionType && source.classObjectType == anyObject)
3087 if(dest.kind != functionType && dest.classObjectType == anyObject && source.classObjectType != typedObject)
3091 if((dest.kind == structType && source.kind == structType) ||
3092 (dest.kind == unionType && source.kind == unionType))
3094 if((dest.enumName && source.enumName && !strcmp(dest.enumName, source.enumName)) ||
3095 (source.members.first && source.members.first == dest.members.first))
3099 if(dest.kind == ellipsisType && source.kind != voidType)
3102 if(dest.kind == pointerType && dest.type.kind == voidType &&
3103 ((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))
3104 || source.kind == subClassType || source.kind == pointerType || source.kind == arrayType || source.kind == functionType || source.kind == thisClassType)
3106 /*source.kind != voidType && source.kind != structType && source.kind != unionType */
3108 /*&& (source.kind != classType /-*|| source._class.registered.type != structClass)*/)
3110 if(!isConversionExploration && source.kind == pointerType && source.type.kind == voidType &&
3111 ((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))
3112 || dest.kind == subClassType || dest.kind == pointerType || dest.kind == arrayType || dest.kind == functionType || dest.kind == thisClassType)
3113 /* dest.kind != voidType && dest.kind != structType && dest.kind != unionType */
3115 /*&& (dest.kind != classType || dest._class.registered.type != structClass)*/)
3118 if(((source.kind == classType && dest.kind == classType) || (source.kind == subClassType && dest.kind == subClassType)) && source._class)
3120 if(source._class.registered && source._class.registered.type == unitClass)
3122 if(conversions != null)
3124 if(source._class.registered == dest._class.registered)
3129 Class sourceBase, destBase;
3130 for(sourceBase = source._class.registered; sourceBase && sourceBase.base.type != systemClass; sourceBase = sourceBase.base);
3131 for(destBase = dest._class.registered; destBase && destBase.base.type != systemClass; destBase = destBase.base);
3132 if(sourceBase == destBase)
3136 // Don't match enum inheriting from other enum if resolving enumeration values
3137 // TESTING: !dest.classObjectType
3138 else if(source._class && dest._class && (dest.classObjectType == source.classObjectType || !dest.classObjectType) &&
3140 (!source._class.registered || source._class.registered.type != enumClass) ||
3141 (!dest._class.registered || dest._class.registered.type != enumClass)) && eClass_IsDerived(source._class.registered, dest._class.registered))
3145 // Added this so that DefinedColor = Color doesn't go through ColorRGB property
3147 dest._class && dest._class.registered && dest._class.registered.type == enumClass &&
3148 ((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)
3150 if(eClass_IsDerived(dest._class.registered, source._class.registered))
3158 // JUST ADDED THIS...
3159 if(source.kind == subClassType && dest.kind == classType && dest._class && !strcmp(dest._class.string, "ecere::com::Class"))
3164 // Just added this for Straight conversion of ColorAlpha => Color
3165 if(source.kind == classType)
3168 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3171 for(convert = _class.conversions.first; convert; convert = convert.next)
3173 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3175 Conversion after = (conversions != null) ? conversions.last : null;
3177 if(!convert.dataType)
3178 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3179 // Only go ahead with this conversion flow while processing an existing conversion if the conversion data type is a class
3180 if((!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3181 MatchTypes(convert.dataType, dest, conversions, null, null,
3182 (convert.dataType.kind == classType && !strcmp(convert.dataTypeString, "String")) ? true : false,
3183 convert.dataType.kind == classType, false, true, warnConst))
3185 if(!conversions && !convert.Get)
3187 else if(conversions != null)
3189 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3190 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3191 (dest.kind != classType || dest._class.registered != _class.base))
3195 Conversion conv { convert = convert, isGet = true };
3196 // conversions.Add(conv);
3197 conversions.Insert(after, conv);
3210 if(dest.kind == classType)
3213 for(_class = dest._class ? dest._class.registered : null; _class; _class = _class.base)
3216 for(convert = _class.conversions.first; convert; convert = convert.next)
3218 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3220 Type constType = null;
3221 bool success = false;
3222 // Conversion after = (conversions != null) ? conversions.last : null;
3224 if(!convert.dataType)
3225 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3227 if(warnConst && convert.dataType.kind == pointerType && convert.dataType.type && dest.constant)
3230 constType = { kind = pointerType, refCount = 1, type = ptrType };
3231 CopyTypeInto(ptrType, convert.dataType.type);
3232 ptrType.constant = true;
3235 // Just added this equality check to prevent recursion.... Make it safer?
3236 // Changed enumBaseType to false here to prevent all int-compatible enums to show up in AnchorValues
3237 if((constType || convert.dataType != dest) && MatchTypes(source, constType ? constType : convert.dataType, conversions, null, null, true, false /*true*/, false, true, warnConst))
3239 if(!conversions && !convert.Set)
3241 else if(conversions != null)
3243 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3244 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3245 (source.kind != classType || source._class.registered != _class.base))
3249 // *** Testing this! ***
3250 Conversion conv { convert = convert };
3251 conversions.Add(conv);
3252 //conversions.Insert(after, conv);
3258 FreeType(constType);
3264 /*if(dest._class.registered && !strcmp(dest._class.registered.name, "bool"))
3266 if(source.kind != voidType && source.kind != structType && source.kind != unionType &&
3267 (source.kind != classType || source._class.registered.type != structClass))
3271 // TESTING THIS... IS THIS OK??
3272 if(enumBaseType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3274 if(!dest._class.registered.dataType)
3275 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3276 // Only support this for classes...
3277 if(dest._class.registered.dataType.kind == classType || source.truth || dest.truth/* ||
3278 !strcmp(dest._class.registered.name, "bool") || (source.kind == classType && !strcmp(source._class.string, "bool"))*/)
3280 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, dest._class.registered.dataType.kind == classType, false, false, warnConst))
3289 if(source.kind == classType)
3292 for(_class = source._class ? source._class.registered : null; _class; _class = _class.base)
3295 for(convert = _class.conversions.first; convert; convert = convert.next)
3297 if(convert.memberAccess == publicAccess || _class.module == privateModule)
3299 Conversion after = (conversions != null) ? conversions.last : null;
3301 if(!convert.dataType)
3302 convert.dataType = ProcessTypeString(convert.dataTypeString, false);
3303 if(convert.dataType != source &&
3304 (!isConversionExploration || convert.dataType.kind == classType || !strcmp(_class.name, "String")) &&
3305 MatchTypes(convert.dataType, dest, conversions, null, null, convert.dataType.kind == classType, convert.dataType.kind == classType, false, true, warnConst))
3307 if(!conversions && !convert.Get)
3309 else if(conversions != null)
3311 if(_class.type == unitClass && convert.dataType.kind == classType && convert.dataType._class &&
3312 convert.dataType._class.registered && _class.base == convert.dataType._class.registered.base &&
3313 (dest.kind != classType || dest._class.registered != _class.base))
3317 Conversion conv { convert = convert, isGet = true };
3319 // conversions.Add(conv);
3320 conversions.Insert(after, conv);
3329 // TESTING THIS... IS THIS OK??
3330 if(enumBaseType && source._class && source._class.registered && source._class.registered.type == enumClass)
3332 if(!source._class.registered.dataType)
3333 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3334 if(!isConversionExploration || source._class.registered.dataType.kind == classType || !strcmp(source._class.registered.name, "String"))
3336 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))
3338 // For bool to be accepted by byte, short, etc.
3339 else if(MatchTypes(dest, source._class.registered.dataType, null, null, null, false, false, false, false, warnConst))
3346 if(source.kind == classType || source.kind == subClassType)
3348 else if(dest.kind == source.kind &&
3349 (dest.kind != structType && dest.kind != unionType &&
3350 dest.kind != functionType && dest.kind != arrayType && dest.kind != pointerType && dest.kind != methodType))
3352 // RECENTLY ADDED THESE
3353 else if(dest.kind == doubleType && source.kind == floatType)
3355 else if(dest.kind == shortType && (source.kind == charType || source.kind == _BoolType))
3357 else if(dest.kind == intType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intSizeType /* Exception here for size_t */))
3359 else if(dest.kind == int64Type && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intPtrType || source.kind == intSizeType))
3361 else if(dest.kind == intPtrType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == intSizeType || source.kind == int64Type))
3363 else if(dest.kind == intSizeType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType || source.kind == int64Type || source.kind == intPtrType))
3365 else if(source.kind == enumType &&
3366 (dest.kind == intType || dest.kind == shortType || dest.kind == charType || source.kind == _BoolType || dest.kind == longType || dest.kind == int64Type || dest.kind == intPtrType || dest.kind == intSizeType))
3368 else if(dest.kind == enumType && !isConversionExploration &&
3369 (source.kind == intType || source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == longType || source.kind == int64Type || source.kind == intPtrType || source.kind == intSizeType))
3371 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) &&
3372 ((source.kind == functionType || (source.kind == pointerType && source.type.kind == functionType) || source.kind == methodType)))
3374 Type paramSource, paramDest;
3376 if(dest.kind == methodType)
3377 owningClassDest = dest.methodClass ? dest.methodClass : dest.method._class;
3378 if(source.kind == methodType)
3379 owningClassSource = source.methodClass ? source.methodClass : source.method._class;
3381 if(dest.kind == pointerType && dest.type.kind == functionType) dest = dest.type;
3382 if(source.kind == pointerType && source.type.kind == functionType) source = source.type;
3383 if(dest.kind == methodType)
3384 dest = dest.method.dataType;
3385 if(source.kind == methodType)
3386 source = source.method.dataType;
3388 paramSource = source.params.first;
3389 if(paramSource && paramSource.kind == voidType) paramSource = null;
3390 paramDest = dest.params.first;
3391 if(paramDest && paramDest.kind == voidType) paramDest = null;
3394 if((dest.staticMethod || (!dest.thisClass && !owningClassDest)) &&
3395 !(source.staticMethod || (!source.thisClass && !owningClassSource)))
3397 // Source thisClass must be derived from destination thisClass
3398 if(!paramDest || (!(paramDest.kind == pointerType && paramDest.type && paramDest.type.kind == voidType) && (paramDest.kind != classType ||
3399 !eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource,paramDest._class.registered))))
3401 if(paramDest && paramDest.kind == classType)
3402 Compiler_Error($"method class must be derived from %s\n", paramDest._class.string);
3404 Compiler_Error($"method class should not take an object\n");
3407 paramDest = paramDest.next;
3409 else if(!dest.staticMethod && (dest.thisClass || owningClassDest))
3411 if((source.staticMethod || (!source.thisClass && !owningClassSource)))
3415 if(!paramSource || paramSource.kind != classType || !eClass_IsDerived(paramSource._class.registered,dest.thisClass.registered))
3417 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3423 // THIS WAS BACKWARDS:
3424 // if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(owningClassDest, paramSource._class.registered)))
3425 if(!paramSource || paramSource.kind != classType || (owningClassDest && !eClass_IsDerived(paramSource._class.registered, owningClassDest)))
3428 Compiler_Error($"%s expected to be derived from method class\n", owningClassDest.fullName);
3430 Compiler_Error($"overriding class expected to be derived from method class\n");
3434 paramSource = paramSource.next;
3440 // Source thisClass must be derived from destination thisClass
3441 if(!eClass_IsDerived(source.thisClass ? source.thisClass.registered : owningClassSource, dest.thisClass.registered))
3443 Compiler_Error($"method class must be derived from %s\n", dest.thisClass.string);
3449 // THIS WAS BACKWARDS TOO??
3450 // if(source.thisClass && owningClassDest && !eClass_IsDerived(owningClassDest, source.thisClass.registered))
3451 if(source.thisClass && source.thisClass.registered && owningClassDest && !eClass_IsDerived(source.thisClass.registered, owningClassDest))
3454 Compiler_Error($"%s expected to be derived from method class\n", /*owningClass.name*/ source.thisClass.registered.fullName);
3456 //Compiler_Error($"overriding class expected to be derived from method class\n");
3464 // Source return type must be derived from destination return type
3465 if(!MatchTypes(source.returnType, dest.returnType, null, null, null, true, true, false, false, warnConst))
3467 Compiler_Warning($"incompatible return type for function\n");
3470 // The const check is backwards from the MatchTypes above (for derivative classes checks)
3472 CheckConstCompatibility(dest.returnType, source.returnType, true);
3476 for(; paramDest; paramDest = paramDest.next)
3480 //Compiler_Warning($"not enough parameters\n");
3481 Compiler_Error($"not enough parameters\n");
3485 Type paramDestType = paramDest;
3486 Type paramSourceType = paramSource;
3487 Type type = paramDestType;
3489 // *** WORKING CODE: TESTING THIS HERE FOR TEMPLATES ***
3490 if(paramDest.kind == templateType && paramDest.templateParameter.type == TemplateParameterType::type && owningClassSource &&
3491 paramSource.kind != templateType)
3494 ClassTemplateParameter curParam = null;
3496 for(sClass = owningClassSource; sClass; sClass = sClass.base)
3499 if(sClass.templateClass) sClass = sClass.templateClass;
3500 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
3502 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
3504 for(sClass = sClass.base; sClass; sClass = sClass.base)
3506 if(sClass.templateClass) sClass = sClass.templateClass;
3507 id += sClass.templateParams.count;
3518 ClassTemplateArgument arg = owningClassSource.templateArgs[id];
3519 paramDestType = type = ProcessTypeString(arg.dataTypeString, false);
3523 // paramDest must be derived from paramSource
3524 if(!MatchTypes(paramDestType, paramSourceType, null, null, null, true, true, false, false, warnConst) &&
3525 (!acceptReversedParams || !MatchTypes(paramSourceType, paramDestType, null, null, null, true, true, false, false, warnConst)))
3529 PrintType(paramDest, type, false, true);
3530 Compiler_Warning($"incompatible parameter %s (expected %s)\n", paramSource.name, type);
3532 if(paramDestType != paramDest)
3533 FreeType(paramDestType);
3536 if(paramDestType != paramDest)
3537 FreeType(paramDestType);
3540 paramSource = paramSource.next;
3544 Compiler_Error($"too many parameters\n");
3549 else if((dest.kind == functionType || (dest.kind == pointerType && dest.type.kind == functionType) || dest.kind == methodType) && (source.kind == pointerType && source.type.kind == voidType))
3553 else if((dest.kind == pointerType || dest.kind == arrayType) &&
3554 (source.kind == arrayType || source.kind == pointerType))
3556 ComputeTypeSize(source.type);
3557 ComputeTypeSize(dest.type);
3558 if(source.type.size == dest.type.size && MatchTypes(source.type, dest.type, null, null, null, true, true, false, false, warnConst))
3565 static void FreeConvert(Conversion convert)
3567 if(convert.resultType)
3568 FreeType(convert.resultType);
3571 bool MatchWithEnums_NameSpace(NameSpace nameSpace, Expression sourceExp, Type dest,
3572 char * string, OldList conversions)
3576 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
3578 Class _class = link.data;
3579 if(_class.type == enumClass)
3581 OldList converts { };
3583 type.kind = classType;
3586 _class.symbol = FindClass(_class.fullName);
3587 type._class = _class.symbol;
3589 if(MatchTypes(type, dest, &converts, null, null, true, false, false, false, false))
3592 Class enumClass = eSystem_FindClass(privateModule, "enum");
3596 for(baseClass = _class ; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
3598 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
3599 for(value = e.values.first; value; value = value.next)
3601 if(!strcmp(value.name, string))
3606 FreeExpContents(sourceExp);
3607 FreeType(sourceExp.expType);
3609 sourceExp.isConstant = true;
3610 sourceExp.expType = MkClassType(baseClass.fullName);
3614 sourceExp.type = constantExp;
3615 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "short") || !strcmp(baseClass.dataTypeString, "char"))
3616 sprintf(constant, FORMAT64D, value.data);
3618 sprintf(constant, FORMAT64HEXLL, value.data);
3619 sourceExp.constant = CopyString(constant);
3620 //for(;baseClass.base && baseClass.base.type != systemClass; baseClass = baseClass.base);
3623 while(converts.first)
3625 Conversion convert = converts.first;
3626 converts.Remove(convert);
3627 conversions.Add(convert);
3636 converts.Free(FreeConvert);
3640 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
3641 if(MatchWithEnums_NameSpace(nameSpace, sourceExp, dest, string, conversions))
3646 public bool ModuleVisibility(Module searchIn, Module searchFor)
3648 SubModule subModule;
3650 if(searchFor == searchIn)
3653 for(subModule = searchIn.modules.first; subModule; subModule = subModule.next)
3655 if(subModule.importMode == publicAccess || searchIn == searchIn.application)
3657 if(ModuleVisibility(subModule.module, searchFor))
3664 bool MatchWithEnums_Module(Module mainModule, Expression sourceExp, Type dest, char * string, OldList conversions)
3668 if(MatchWithEnums_NameSpace(mainModule.application.systemNameSpace, sourceExp, dest, string, conversions))
3670 if(MatchWithEnums_NameSpace(mainModule.application.privateNameSpace, sourceExp, dest, string, conversions))
3672 if(MatchWithEnums_NameSpace(mainModule.application.publicNameSpace, sourceExp, dest, string, conversions))
3675 for(module = mainModule.application.allModules.first; module; module = module.next)
3677 if(ModuleVisibility(mainModule, module) && MatchWithEnums_NameSpace(module.publicNameSpace, sourceExp, dest, string, conversions))
3683 bool MatchTypeExpression(Expression sourceExp, Type dest, OldList conversions, bool skipUnitBla, bool warnConst)
3686 Type realDest = dest;
3687 Type backupSourceExpType = null;
3688 Expression computedExp = sourceExp;
3691 if(sourceExp.isConstant && sourceExp.type != constantExp && sourceExp.type != identifierExp && sourceExp.type != castExp &&
3692 dest.kind == classType && dest._class && dest._class.registered && dest._class.registered.type == enumClass)
3694 computedExp = CopyExpression(sourceExp); // Keep the original expression, but compute for checking enum ranges
3695 ComputeExpression(computedExp /*sourceExp*/);
3698 source = sourceExp.expType;
3700 if(dest.kind == pointerType && sourceExp.type == constantExp && !strtoul(sourceExp.constant, null, 0))
3702 if(computedExp != sourceExp)
3704 FreeExpression(computedExp);
3705 computedExp = sourceExp;
3711 if(!skipUnitBla && source && dest && source.kind == classType && dest.kind == classType)
3713 if(source._class && source._class.registered && source._class.registered.type == unitClass)
3715 Class sourceBase, destBase;
3716 for(sourceBase = source._class.registered;
3717 sourceBase && sourceBase.base && sourceBase.base.type != systemClass;
3718 sourceBase = sourceBase.base);
3719 for(destBase = dest._class.registered;
3720 destBase && destBase.base && destBase.base.type != systemClass;
3721 destBase = destBase.base);
3722 //if(source._class.registered == dest._class.registered)
3723 if(sourceBase == destBase)
3725 if(computedExp != sourceExp)
3727 FreeExpression(computedExp);
3728 computedExp = sourceExp;
3740 int64 value = MAXINT;
3744 if(computedExp.type == constantExp)
3747 value = strtoll(computedExp.constant, null, 0);
3749 value = strtoull(computedExp.constant, null, 0);
3751 else if(computedExp.type == opExp && sourceExp.op.op == '-' && !computedExp.op.exp1 && computedExp.op.exp2 && computedExp.op.exp2.type == constantExp)
3754 value = -strtoll(computedExp.op.exp2.constant, null, 0);
3756 value = -strtoull(computedExp.op.exp2.constant, null, 0);
3758 if(computedExp != sourceExp)
3760 FreeExpression(computedExp);
3761 computedExp = sourceExp;
3764 if(dest.kind != classType && source.kind == classType && source._class && source._class.registered &&
3765 !strcmp(source._class.registered.fullName, "ecere::com::unichar"))
3768 source = Type { kind = intType, isSigned = false, refCount = 1 };
3771 if(dest.kind == classType)
3773 Class _class = dest._class ? dest._class.registered : null;
3775 if(_class && _class.type == unitClass)
3777 if(source.kind != classType)
3780 Type tempDest, tempSource;
3782 for(; _class.base.type != systemClass; _class = _class.base);
3784 tempDest = tempType;
3786 tempType.kind = classType;
3788 _class.symbol = FindClass(_class.fullName);
3790 tempType._class = _class.symbol;
3791 tempType.truth = dest.truth;
3793 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3795 // NOTE: To handle bad warnings on int64 vs 32 bit eda::Id incompatibilities
3796 backupSourceExpType = sourceExp.expType;
3797 sourceExp.expType = dest; dest.refCount++;
3798 //sourceExp.expType = MkClassType(_class.fullName);
3806 // Why wasn't there something like this?
3807 if(_class && _class.type == bitClass && source.kind != classType)
3809 if(!dest._class.registered.dataType)
3810 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3811 if(MatchTypes(source, dest._class.registered.dataType, conversions, null, null, true, true, false, false, warnConst))
3814 FreeType(sourceExp.expType);
3815 source = sourceExp.expType = MkClassType(dest._class.string);
3818 //source.kind = classType;
3819 //source._class = dest._class;
3823 // Adding two enumerations
3825 if(_class && _class.type == enumClass && source.kind == classType && source._class && source._class.registered && source._class.registered.type == enumClass)
3827 if(!source._class.registered.dataType)
3828 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3829 if(!dest._class.registered.dataType)
3830 dest._class.registered.dataType = ProcessTypeString(dest._class.registered.dataTypeString, false);
3832 if(MatchTypes(source._class.registered.dataType, dest._class.registered.dataType, conversions, null, null, true, false, false))
3835 source = sourceExp.expType = MkClassType(dest._class.string);
3838 //source.kind = classType;
3839 //source._class = dest._class;
3843 if(_class && !strcmp(_class.fullName, "ecere::com::Class") && source.kind == pointerType && source.type && source.type.kind == charType && sourceExp.type == stringExp)
3845 OldList * specs = MkList();
3849 ReadString(string, sourceExp.string);
3850 decl = SpecDeclFromString(string, specs, null);
3852 FreeExpContents(sourceExp);
3853 FreeType(sourceExp.expType);
3855 sourceExp.type = classExp;
3856 sourceExp._classExp.specifiers = specs;
3857 sourceExp._classExp.decl = decl;
3858 sourceExp.expType = dest;
3863 if(backupSourceExpType) FreeType(backupSourceExpType);
3867 else if(source.kind == classType)
3869 Class _class = source._class ? source._class.registered : null;
3871 if(_class && (_class.type == unitClass || /*!strcmp(_class.fullName, "bool") || /*_class.type == enumClass || */_class.type == bitClass )) // TOCHECK: enumClass, bitClass is new here...
3874 if(dest.kind != classType)
3876 // Testing this simpler piece of code... (Broke Units Conversion to no unit Logic)
3877 if(!source._class.registered.dataType)
3878 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3881 dest = MkClassType(source._class.string);
3882 //if(MatchTypes(source._class.registered.dataType, dest, conversions, null, null, true, false, false))
3883 // dest = MkClassType(source._class.string);
3887 if(dest.kind != classType)
3890 Type tempDest, tempSource;
3892 if(!source._class.registered.dataType)
3893 source._class.registered.dataType = ProcessTypeString(source._class.registered.dataTypeString, false);
3895 for(; _class.base.type != systemClass; _class = _class.base);
3897 tempSource = tempType;
3898 tempType.kind = classType;
3899 tempType._class = FindClass(_class.fullName);
3900 tempType.truth = source.truth;
3901 tempType.classObjectType = source.classObjectType;
3904 MatchTypes(tempSource, tempDest, conversions, null, null, true, true, false, false, warnConst);
3906 // PUT THIS BACK TESTING UNITS?
3907 if(conversions.last)
3909 ((Conversion)(conversions.last)).resultType = dest;
3913 FreeType(sourceExp.expType);
3914 sourceExp.expType = MkClassType(_class.fullName);
3915 sourceExp.expType.truth = source.truth;
3916 sourceExp.expType.classObjectType = source.classObjectType;
3918 // *** This if was commented out, put it back because "int a =^ Destroy()" shows up bool enum values in autocomplete ***
3920 if(!sourceExp.destType)
3922 FreeType(sourceExp.destType);
3923 sourceExp.destType = sourceExp.expType;
3924 if(sourceExp.expType)
3925 sourceExp.expType.refCount++;
3928 //source = _class.dataType;
3931 // TOCHECK: TESTING THIS NEW CODE
3932 if(!_class.dataType)
3933 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3935 dest = MkClassType(source._class.string);
3936 dest.truth = source.truth;
3937 dest.classObjectType = source.classObjectType;
3940 source = _class.dataType;
3950 if(MatchTypes(source, dest, conversions, null, null, true, true, false, false, warnConst))
3960 if(source.kind == classType)
3962 Class _class = source._class.registered;
3963 if(_class.type == unitClass)
3965 if(!_class.dataType)
3966 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
3967 source = _class.dataType;
3971 if(dest.kind == classType)
3973 Class _class = dest._class ? dest._class.registered : null;
3974 bool fittingValue = false;
3975 if(_class && _class.type == enumClass)
3977 Class enumClass = eSystem_FindClass(privateModule, "enum");
3978 EnumClassData c = ACCESS_CLASSDATA(_class, enumClass);
3979 if(c && value >= 0 && value <= c.largest)
3980 fittingValue = true;
3983 if(_class && !dest.truth && (_class.type == unitClass || fittingValue ||
3984 (/*_class.type == enumClass*/_class.type != structClass && !value && source.kind == intType) || _class.type == bitClass)) // TOCHECK: enumClass, bitClass is new here...
3986 if(_class.type == normalClass || _class.type == noHeadClass)
3988 Expression newExp { };
3989 *newExp = *sourceExp;
3990 if(sourceExp.destType) sourceExp.destType.refCount++;
3991 if(sourceExp.expType) sourceExp.expType.refCount++;
3992 sourceExp.type = castExp;
3993 sourceExp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
3994 sourceExp.cast.exp = newExp;
3995 FreeType(sourceExp.expType);
3996 sourceExp.expType = null;
3997 ProcessExpressionType(sourceExp);
3999 // In Debugger, this helps with addresses (e.g. null pointers) that end up casted to a void *: keeps a classType instead of a pointerType
4002 FreeType(sourceExp.expType);
4003 sourceExp.expType = dest;
4007 if(inCompiler) FreeType(dest);
4009 if(backupSourceExpType) FreeType(backupSourceExpType);
4013 if(!_class.dataType)
4014 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4016 dest = _class.dataType;
4020 // Accept lower precision types for units, since we want to keep the unit type
4021 if(dest.kind == doubleType &&
4022 (source.kind == doubleType || source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType ||
4023 source.kind == charType || source.kind == _BoolType))
4025 specs = MkListOne(MkSpecifier(DOUBLE));
4027 else if(dest.kind == floatType &&
4028 (source.kind == floatType || dest.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
4029 source.kind == _BoolType || source.kind == doubleType))
4031 specs = MkListOne(MkSpecifier(FLOAT));
4033 else if(dest.kind == int64Type && (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == charType ||
4034 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4037 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4038 ListAdd(specs, MkSpecifier(INT64));
4040 else if(dest.kind == intType && (source.kind == intType || source.kind == shortType || source.kind == charType ||
4041 source.kind == _BoolType || source.kind == floatType || source.kind == doubleType))
4044 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4045 ListAdd(specs, MkSpecifier(INT));
4047 else if(dest.kind == shortType && (source.kind == shortType || source.kind == charType || source.kind == _BoolType || source.kind == intType ||
4048 source.kind == floatType || source.kind == doubleType))
4051 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4052 ListAdd(specs, MkSpecifier(SHORT));
4054 else if(dest.kind == charType && (source.kind == charType || source.kind == _BoolType || source.kind == shortType || source.kind == intType ||
4055 source.kind == floatType || source.kind == doubleType))
4058 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4059 ListAdd(specs, MkSpecifier(CHAR));
4065 if(backupSourceExpType)
4067 // Failed to convert: revert previous exp type
4068 if(sourceExp.expType) FreeType(sourceExp.expType);
4069 sourceExp.expType = backupSourceExpType;
4074 else if(dest.kind == doubleType &&
4075 (source.kind == doubleType || source.kind == floatType || source.kind == int64Type || source.kind == intType || source.kind == enumType || source.kind == shortType ||
4076 source.kind == _BoolType || source.kind == charType))
4078 specs = MkListOne(MkSpecifier(DOUBLE));
4080 else if(dest.kind == floatType &&
4081 (source.kind == floatType || source.kind == enumType || source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4083 specs = MkListOne(MkSpecifier(FLOAT));
4085 else if(dest.kind == _BoolType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4086 (value == 1 || value == 0))
4089 ListAdd(specs, MkSpecifier(BOOL));
4091 else if(dest.kind == charType && (source.kind == _BoolType || source.kind == charType || source.kind == enumType || source.kind == shortType || source.kind == intType) &&
4092 (dest.isSigned ? (value >= -128 && value <= 127) : (value >= 0 && value <= 255)))
4095 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4096 ListAdd(specs, MkSpecifier(CHAR));
4098 else if(dest.kind == shortType && (source.kind == enumType || source.kind == _BoolType || source.kind == charType || source.kind == shortType ||
4099 (source.kind == intType && (dest.isSigned ? (value >= -32768 && value <= 32767) : (value >= 0 && value <= 65535)))))
4102 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4103 ListAdd(specs, MkSpecifier(SHORT));
4105 else if(dest.kind == intType && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType))
4108 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4109 ListAdd(specs, MkSpecifier(INT));
4111 else if(dest.kind == int64Type && (source.kind == enumType || source.kind == shortType || source.kind == _BoolType || source.kind == charType || source.kind == intType || source.kind == int64Type))
4114 if(!dest.isSigned) ListAdd(specs, MkSpecifier(UNSIGNED));
4115 ListAdd(specs, MkSpecifier(INT64));
4117 else if(dest.kind == enumType &&
4118 (source.kind == int64Type || source.kind == intType || source.kind == shortType || source.kind == _BoolType || source.kind == charType))
4120 specs = MkListOne(MkEnum(MkIdentifier(dest.enumName), null));
4126 if(backupSourceExpType)
4128 // Failed to convert: revert previous exp type
4129 if(sourceExp.expType) FreeType(sourceExp.expType);
4130 sourceExp.expType = backupSourceExpType;
4135 if(!flag && !sourceExp.opDestType)
4137 Expression newExp { };
4138 *newExp = *sourceExp;
4141 if(sourceExp.destType) sourceExp.destType.refCount++;
4142 if(sourceExp.expType) sourceExp.expType.refCount++;
4144 sourceExp.type = castExp;
4145 if(realDest.kind == classType)
4147 sourceExp.cast.typeName = QMkClass(realDest._class.string, null);
4148 FreeList(specs, FreeSpecifier);
4151 sourceExp.cast.typeName = MkTypeName(specs, null);
4152 if(newExp.type == opExp)
4154 sourceExp.cast.exp = MkExpBrackets(MkListOne(newExp));
4157 sourceExp.cast.exp = newExp;
4159 FreeType(sourceExp.expType);
4160 sourceExp.expType = null;
4161 ProcessExpressionType(sourceExp);
4164 FreeList(specs, FreeSpecifier);
4168 if(backupSourceExpType) FreeType(backupSourceExpType);
4174 if(computedExp != sourceExp)
4176 FreeExpression(computedExp);
4177 computedExp = sourceExp;
4180 while((sourceExp.type == bracketsExp || sourceExp.type == extensionExpressionExp) && sourceExp.list) sourceExp = sourceExp.list->last;
4181 if(sourceExp.type == identifierExp)
4183 Identifier id = sourceExp.identifier;
4184 if(dest.kind == classType)
4186 if(dest._class && dest._class.registered && dest._class.registered.type == enumClass)
4188 Class _class = dest._class.registered;
4189 Class enumClass = eSystem_FindClass(privateModule, "enum");
4192 for( ; _class && _class.type == ClassType::enumClass; _class = _class.base)
4195 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4196 for(value = e.values.first; value; value = value.next)
4198 if(!strcmp(value.name, id.string))
4203 FreeExpContents(sourceExp);
4204 FreeType(sourceExp.expType);
4206 sourceExp.isConstant = true;
4207 sourceExp.expType = MkClassType(_class.fullName);
4210 sourceExp.type = constantExp;
4211 if(_class.dataTypeString && (!strcmp(_class.dataTypeString, "int") || !strcmp(_class.dataTypeString, "int64") || !strcmp(_class.dataTypeString, "short") || !strcmp(_class.dataTypeString, "char"))) // _class cannot be null here!
4212 sourceExp.constant = PrintInt64(value.data);
4214 sourceExp.constant = PrintUInt64(value.data);
4215 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
4225 // Loop through all enum classes
4226 if(dest.classObjectType != typedObject && dest.kind == classType /*!= ellipsisType */&& MatchWithEnums_Module(privateModule, sourceExp, dest, id.string, conversions))
4237 #define TERTIARY(o, name, m, t, p) \
4238 static bool name(Expression exp, Operand op1, Operand op2, Operand op3) \
4240 exp.type = constantExp; \
4241 exp.string = p(op1.m ? op2.m : op3.m); \
4243 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4247 #define BINARY(o, name, m, t, p) \
4248 static bool name(Expression exp, Operand op1, Operand op2) \
4251 exp.type = constantExp; \
4252 exp.string = p((t)(op1.m o value2)); \
4254 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4258 #define BINARY_DIVIDEINT(o, name, m, t, p) \
4259 static bool name(Expression exp, Operand op1, Operand op2) \
4262 exp.type = constantExp; \
4263 exp.string = p(value2 ? (op1.m o value2) : 0); \
4265 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4269 #define BINARY_DIVIDEREAL(o, name, m, t, p) \
4270 static bool name(Expression exp, Operand op1, Operand op2) \
4273 exp.type = constantExp; \
4274 exp.string = p(op1.m o value2); \
4276 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4280 #define UNARY(o, name, m, t, p) \
4281 static bool name(Expression exp, Operand op1) \
4283 exp.type = constantExp; \
4284 exp.string = p((t)(o op1.m)); \
4286 { exp.expType = op1.type; if(op1.type) op1.type.refCount++; } \
4290 #define OPERATOR_ALL(macro, o, name) \
4291 macro(o, Int##name, i, int, PrintInt) \
4292 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4293 macro(o, Int64##name, i64, int64, PrintInt64) \
4294 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4295 macro(o, Short##name, s, short, PrintShort) \
4296 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4297 macro(o, Char##name, c, char, PrintChar) \
4298 macro(o, UChar##name, uc, unsigned char, PrintUChar) \
4299 macro(o, Float##name, f, float, PrintFloat) \
4300 macro(o, Double##name, d, double, PrintDouble)
4302 #define OPERATOR_INTTYPES(macro, o, name) \
4303 macro(o, Int##name, i, int, PrintInt) \
4304 macro(o, UInt##name, ui, unsigned int, PrintUInt) \
4305 macro(o, Int64##name, i64, int64, PrintInt64) \
4306 macro(o, UInt64##name, ui64, uint64, PrintUInt64) \
4307 macro(o, Short##name, s, short, PrintShort) \
4308 macro(o, UShort##name, us, unsigned short, PrintUShort) \
4309 macro(o, Char##name, c, char, PrintChar) \
4310 macro(o, UChar##name, uc, unsigned char, PrintUChar)
4312 #define OPERATOR_REALTYPES(macro, o, name) \
4313 macro(o, Float##name, f, float, PrintFloat) \
4314 macro(o, Double##name, d, double, PrintDouble)
4316 // binary arithmetic
4317 OPERATOR_ALL(BINARY, +, Add)
4318 OPERATOR_ALL(BINARY, -, Sub)
4319 OPERATOR_ALL(BINARY, *, Mul)
4320 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /, Div)
4321 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /, Div)
4322 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %, Mod)
4325 OPERATOR_ALL(UNARY, -, Neg)
4327 // unary arithmetic increment and decrement
4328 OPERATOR_ALL(UNARY, ++, Inc)
4329 OPERATOR_ALL(UNARY, --, Dec)
4331 // binary arithmetic assignment
4332 OPERATOR_ALL(BINARY, =, Asign)
4333 OPERATOR_ALL(BINARY, +=, AddAsign)
4334 OPERATOR_ALL(BINARY, -=, SubAsign)
4335 OPERATOR_ALL(BINARY, *=, MulAsign)
4336 OPERATOR_INTTYPES(BINARY_DIVIDEINT, /=, DivAsign)
4337 OPERATOR_REALTYPES(BINARY_DIVIDEREAL, /=, DivAsign)
4338 OPERATOR_INTTYPES(BINARY_DIVIDEINT, %=, ModAsign)
4341 OPERATOR_INTTYPES(BINARY, &, BitAnd)
4342 OPERATOR_INTTYPES(BINARY, |, BitOr)
4343 OPERATOR_INTTYPES(BINARY, ^, BitXor)
4344 OPERATOR_INTTYPES(BINARY, <<, LShift)
4345 OPERATOR_INTTYPES(BINARY, >>, RShift)
4348 OPERATOR_INTTYPES(UNARY, ~, BitNot)
4350 // binary bitwise assignment
4351 OPERATOR_INTTYPES(BINARY, &=, AndAsign)
4352 OPERATOR_INTTYPES(BINARY, |=, OrAsign)
4353 OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
4354 OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
4355 OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
4357 // unary logical negation
4358 OPERATOR_INTTYPES(UNARY, !, Not)
4360 // binary logical equality
4361 OPERATOR_ALL(BINARY, ==, Equ)
4362 OPERATOR_ALL(BINARY, !=, Nqu)
4365 OPERATOR_ALL(BINARY, &&, And)
4366 OPERATOR_ALL(BINARY, ||, Or)
4368 // binary logical relational
4369 OPERATOR_ALL(BINARY, >, Grt)
4370 OPERATOR_ALL(BINARY, <, Sma)
4371 OPERATOR_ALL(BINARY, >=, GrtEqu)
4372 OPERATOR_ALL(BINARY, <=, SmaEqu)
4374 // tertiary condition operator
4375 OPERATOR_INTTYPES(TERTIARY, ?, Cond)
4377 //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
4378 #define OPERATOR_TABLE_ALL(name, type) \
4379 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, type##Mod, \
4381 type##Inc, type##Dec, \
4382 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, type##ModAsign, \
4383 type##BitAnd, type##BitOr, type##BitXor, type##LShift, type##RShift, \
4385 type##AndAsign, type##OrAsign, type##XorAsign, type##LShiftAsign, type##RShiftAsign, \
4387 type##Equ, type##Nqu, \
4388 type##And, type##Or, \
4389 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu, type##Cond \
4392 #define OPERATOR_TABLE_INTTYPES(name, type) \
4393 OpTable name##Ops = { type##Add, type##Sub, type##Mul, type##Div, null, \
4395 type##Inc, type##Dec, \
4396 type##Asign, type##AddAsign, type##SubAsign, type##MulAsign, type##DivAsign, null, \
4397 null, null, null, null, null, \
4399 null, null, null, null, null, \
4401 type##Equ, type##Nqu, \
4402 type##And, type##Or, \
4403 type##Grt, type##Sma, type##GrtEqu, type##SmaEqu \
4406 OPERATOR_TABLE_ALL(int, Int)
4407 OPERATOR_TABLE_ALL(uint, UInt)
4408 OPERATOR_TABLE_ALL(int64, Int64)
4409 OPERATOR_TABLE_ALL(uint64, UInt64)
4410 OPERATOR_TABLE_ALL(short, Short)
4411 OPERATOR_TABLE_ALL(ushort, UShort)
4412 OPERATOR_TABLE_INTTYPES(float, Float)
4413 OPERATOR_TABLE_INTTYPES(double, Double)
4414 OPERATOR_TABLE_ALL(char, Char)
4415 OPERATOR_TABLE_ALL(uchar, UChar)
4417 //OpTable intOps = { IntAdd, IntSub, IntMul, IntDiv, IntMod, IntExp, IntNot, IntBwn, IntOr, IntAnd, IntEqu, IntNqu, IntGrt, IntSma, IntGrtEqu, IntSmaEqu, IntNeg, IntLBitSft, IntRBitSft };
4418 //OpTable uintOps = { UIntAdd, UIntSub, UIntMul, UIntDiv, UIntMod, UIntExp, UIntNot, UIntBwn, UIntOr, UIntAnd, UIntEqu, UIntNqu, UIntGrt, UIntSma, UIntGrtEqu, UIntSmaEqu, UIntNeg, UIntLBitSft, UIntRBitSft };
4419 //OpTable shortOps = { ShortAdd, ShortSub, ShortMul, ShortDiv, ShortMod, ShortExp, ShortNot, ShortBwn, ShortOr, ShortAnd, ShortEqu, ShortNqu, ShortGrt, ShortSma, ShortGrtEqu, ShortSmaEqu, ShortNeg, ShortLBitSft, ShortRBitSft };
4420 //OpTable ushortOps = { UShortAdd, UShortSub, UShortMul, UShortDiv, UShortMod, UShortExp, UShortNot, UShortBwn, UShortOr, UShortAnd, UShortEqu, UShortNqu, UShortGrt, UShortSma, UShortGrtEqu, UShortSmaEqu, UShortNeg, UShortLBitSft, UShortRBitSft };
4421 //OpTable floatOps = { FloatAdd, FloatSub, FloatMul, FloatDiv, null, null, null, null, null, null, FloatEqu, FloatNqu, FloatGrt, FloatSma, FloatGrtEqu, FloatSmaEqu, FloatNeg, null, null };
4422 //OpTable doubleOps = { DoubleAdd, DoubleSub, DoubleMul, DoubleDiv, null, null, null, null, null, null, DoubleEqu, DoubleNqu, DoubleGrt, DoubleSma, DoubleGrtEqu, DoubleSmaEqu, DoubleNeg, null, null };
4423 //OpTable charOps = { CharAdd, CharSub, CharMul, CharDiv, CharMod, CharExp, CharNot, CharBwn, CharOr, CharAnd, CharEqu, CharNqu, CharGrt, CharSma, CharGrtEqu, CharSmaEqu, CharNeg, CharLBitSft, CharRBitSft };
4424 //OpTable ucharOps = { UCharAdd, UCharSub, UCharMul, UCharDiv, UCharMod, UCharExp, UCharNot, UCharBwn, UCharOr, UCharAnd, UCharEqu, UCharNqu, UCharGrt, UCharSma, UCharGrtEqu, UCharSmaEqu, UCharNeg, UCharLBitSft, UCharRBitSft };
4426 public void ReadString(char * output, char * string)
4428 int len = strlen(string);
4430 bool quoted = false, escaped = false;
4431 for(c = 0; c<len; c++)
4433 char ch = string[c];
4438 case 'n': output[d] = '\n'; break;
4439 case 't': output[d] = '\t'; break;
4440 case 'a': output[d] = '\a'; break;
4441 case 'b': output[d] = '\b'; break;
4442 case 'f': output[d] = '\f'; break;
4443 case 'r': output[d] = '\r'; break;
4444 case 'v': output[d] = '\v'; break;
4445 case '\\': output[d] = '\\'; break;
4446 case '\"': output[d] = '\"'; break;
4447 case '\'': output[d] = '\''; break;
4448 default: output[d] = ch;
4469 // String Unescape Copy
4471 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
4472 // This is the same as ReadString above (which also misses numeric escape codes) except it doesn't handle external quotes
4473 public int UnescapeString(char * d, char * s, int len)
4477 while(j < len && (ch = s[j]))
4482 switch((ch = s[++j]))
4484 case 'n': d[k] = '\n'; break;
4485 case 't': d[k] = '\t'; break;
4486 case 'a': d[k] = '\a'; break;
4487 case 'b': d[k] = '\b'; break;
4488 case 'f': d[k] = '\f'; break;
4489 case 'r': d[k] = '\r'; break;
4490 case 'v': d[k] = '\v'; break;
4491 case '\\': d[k] = '\\'; break;
4492 case '\"': d[k] = '\"'; break;
4493 case '\'': d[k] = '\''; break;
4494 default: d[k] = '\\'; d[k] = ch;
4506 public char * OffsetEscapedString(char * s, int len, int offset)
4510 while(j < len && k < offset && (ch = s[j]))
4515 return (k == offset) ? s + j : null;
4518 public Operand GetOperand(Expression exp)
4521 Type type = exp.expType;
4524 while(type.kind == classType &&
4525 type._class.registered && (type._class.registered.type == bitClass || type._class.registered.type == unitClass || type._class.registered.type == enumClass))
4527 if(!type._class.registered.dataType)
4528 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
4529 type = type._class.registered.dataType;
4532 if(exp.type == stringExp && op.kind == pointerType)
4534 op.ui64 = (uint64)exp.string;
4535 op.kind = pointerType;
4538 else if(exp.isConstant && exp.type == constantExp)
4540 op.kind = type.kind;
4548 if(exp.constant[0] == '\'')
4550 op.c = exp.constant[1];
4553 else if(type.isSigned)
4555 op.c = (char)strtol(exp.constant, null, 0);
4560 op.uc = (unsigned char)strtoul(exp.constant, null, 0);
4568 op.s = (short)strtol(exp.constant, null, 0);
4573 op.us = (unsigned short)strtoul(exp.constant, null, 0);
4581 op.i = (int)strtol(exp.constant, null, 0);
4586 op.ui = (unsigned int)strtoul(exp.constant, null, 0);
4594 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4599 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4602 op.kind = int64Type;
4607 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4612 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4615 op.kind = int64Type;
4620 op.i64 = (int64)_strtoi64(exp.constant, null, 0);
4625 op.ui64 = (uint64)_strtoui64(exp.constant, null, 0);
4628 op.kind = int64Type;
4631 if(!strcmp(exp.constant, "inf")) op.f = float::inf();
4632 else if(!strcmp(exp.constant, "-inf")) op.f = -float::inf();
4633 else if(!strcmp(exp.constant, "nan")) op.f = float::nan();
4634 else if(!strcmp(exp.constant, "-nan")) op.f = -float::nan();
4636 op.f = (float)strtod(exp.constant, null);
4640 if(!strcmp(exp.constant, "inf")) op.d = double::inf();
4641 else if(!strcmp(exp.constant, "-inf")) op.d = -double::inf();
4642 else if(!strcmp(exp.constant, "nan")) op.d = double::nan();
4643 else if(!strcmp(exp.constant, "-nan")) op.d = -double::nan();
4645 op.d = (double)strtod(exp.constant, null);
4648 //case classType: For when we have operator overloading...
4649 // Pointer additions
4650 //case functionType:
4654 op.ui64 = _strtoui64(exp.constant, null, 0);
4655 op.kind = pointerType;
4665 static int64 GetEnumValue(Class _class, void * ptr)
4668 switch(_class.typeSize)
4671 if(!strcmp(_class.dataTypeString, "uint64"))
4672 v = (int64)*(uint64 *)ptr;
4674 v = (int64)*(int64 *)ptr;
4677 if(!strcmp(_class.dataTypeString, "uint"))
4678 v = (int64)*(uint *)ptr;
4680 v = (int64)*(int *)ptr;
4683 if(!strcmp(_class.dataTypeString, "uint16"))
4684 v = (int64)*(uint16 *)ptr;
4686 v = (int64)*(short *)ptr;
4689 if(!strcmp(_class.dataTypeString, "byte"))
4690 v = (int64)*(byte *)ptr;
4692 v = (int64)*(char *)ptr;
4698 static __attribute__((unused)) void UnusedFunction()
4701 a.OnGetString(0,0,0);
4704 extern int __ecereVMethodID_class_OnGetString;
4707 static void PopulateInstanceProcessMember(Instantiation inst, OldList * memberList, DataMember parentDataMember, uint offset)
4709 DataMember dataMember;
4710 for(dataMember = parentDataMember.members.first; dataMember; dataMember = dataMember.next)
4712 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4713 PopulateInstanceProcessMember(inst, memberList, dataMember, offset + dataMember.offset);
4717 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4719 void * ptr = inst.data + dataMember.offset + offset;
4720 char * result = null;
4721 exp.loc = member.loc = inst.loc;
4722 ((Identifier)member.identifiers->first).loc = inst.loc;
4724 if(!dataMember.dataType)
4725 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4726 type = dataMember.dataType;
4727 if(type.kind == classType)
4729 Class _class = type._class.registered;
4730 if(_class.type == enumClass)
4732 Class enumClass = eSystem_FindClass(privateModule, "enum");
4735 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4737 for(item = e.values.first; item; item = item.next)
4739 if(item.data == GetEnumValue(_class, ptr))
4747 exp.identifier = MkIdentifier(result);
4748 exp.type = identifierExp;
4749 exp.destType = MkClassType(_class.fullName);
4750 ProcessExpressionType(exp);
4754 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4756 if(!_class.dataType)
4757 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4758 type = _class.dataType;
4767 FreeExpContents(exp);
4769 exp.constant = PrintFloat(*(float*)ptr);
4770 exp.type = constantExp;
4775 FreeExpContents(exp);
4777 exp.constant = PrintDouble(*(double*)ptr);
4778 exp.type = constantExp;
4783 FreeExpContents(exp);
4785 exp.constant = PrintInt(*(int*)ptr);
4786 exp.type = constantExp;
4791 FreeExpContents(exp);
4793 exp.constant = PrintInt64(*(int64*)ptr);
4794 exp.type = constantExp;
4799 FreeExpContents(exp);
4800 // TODO: This should probably use proper type
4801 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4802 exp.type = constantExp;
4807 FreeExpContents(exp);
4808 // TODO: This should probably use proper type
4809 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4810 exp.type = constantExp;
4814 Compiler_Error($"Unhandled type populating instance\n");
4817 ListAdd(memberList, member);
4820 if(parentDataMember.type == unionMember)
4825 void PopulateInstance(Instantiation inst)
4827 Symbol classSym = inst._class.symbol; // FindClass(inst._class.name);
4828 Class _class = classSym.registered;
4829 DataMember dataMember;
4830 OldList * memberList = MkList();
4831 // Added this check and ->Add to prevent memory leaks on bad code
4833 inst.members = MkListOne(MkMembersInitList(memberList));
4835 inst.members->Add(MkMembersInitList(memberList));
4836 for(dataMember = _class.membersAndProperties.first; dataMember; dataMember = dataMember.next)
4838 if(!dataMember.isProperty)
4840 if(!dataMember.name && (dataMember.type == structMember || dataMember.type == unionMember))
4841 PopulateInstanceProcessMember(inst, memberList, dataMember, dataMember.offset);
4845 MemberInit member = MkMemberInit(MkListOne(MkIdentifier(dataMember.name)), MkInitializerAssignment(exp));
4847 void * ptr = inst.data + dataMember.offset;
4848 char * result = null;
4850 exp.loc = member.loc = inst.loc;
4851 ((Identifier)member.identifiers->first).loc = inst.loc;
4853 if(!dataMember.dataType)
4854 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
4855 type = dataMember.dataType;
4856 if(type.kind == classType)
4858 Class _class = type._class.registered;
4859 if(_class.type == enumClass)
4861 Class enumClass = eSystem_FindClass(privateModule, "enum");
4864 EnumClassData e = ACCESS_CLASSDATA(_class, enumClass);
4866 for(item = e.values.first; item; item = item.next)
4868 if(item.data == GetEnumValue(_class, ptr))
4877 exp.identifier = MkIdentifier(result);
4878 exp.type = identifierExp;
4879 exp.destType = MkClassType(_class.fullName);
4880 ProcessExpressionType(exp);
4883 if(_class.type == enumClass || _class.type == unitClass || _class.type == bitClass)
4885 if(!_class.dataType)
4886 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
4887 type = _class.dataType;
4896 exp.constant = PrintFloat(*(float*)ptr);
4897 exp.type = constantExp;
4902 exp.constant = PrintDouble(*(double*)ptr);
4903 exp.type = constantExp;
4908 exp.constant = PrintInt(*(int*)ptr);
4909 exp.type = constantExp;
4914 exp.constant = PrintInt64(*(int64*)ptr);
4915 exp.type = constantExp;
4920 exp.constant = PrintInt64((int64)*(intptr*)ptr);
4921 exp.type = constantExp;
4925 Compiler_Error($"Unhandled type populating instance\n");
4928 ListAdd(memberList, member);
4934 void ComputeInstantiation(Expression exp)
4936 Instantiation inst = exp.instance;
4937 MembersInit members;
4938 Symbol classSym = inst._class ? inst._class.symbol : null; // FindClass(inst._class.name);
4939 Class _class = classSym ? classSym.registered : null;
4940 DataMember curMember = null;
4941 Class curClass = null;
4942 DataMember subMemberStack[256];
4943 int subMemberStackPos = 0;
4946 if(_class && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass ))
4948 // Don't recompute the instantiation...
4949 // Non Simple classes will have become constants by now
4953 if(_class.type == normalClass || _class.type == noHeadClass)
4955 inst.data = (byte *)eInstance_New(_class);
4956 if(_class.type == normalClass)
4957 ((Instance)inst.data)._refCount++;
4960 inst.data = new0 byte[_class.structSize];
4965 for(members = inst.members->first; members; members = members.next)
4967 switch(members.type)
4969 case dataMembersInit:
4971 if(members.dataMembers)
4974 for(member = members.dataMembers->first; member; member = member.next)
4976 Identifier ident = member.identifiers ? member.identifiers->first : null;
4979 Property prop = null;
4980 DataMember dataMember = null;
4981 uint dataMemberOffset;
4985 eClass_FindNextMember(_class, &curClass, &curMember, subMemberStack, &subMemberStackPos);
4988 if(curMember.isProperty)
4989 prop = (Property)curMember;
4992 dataMember = curMember;
4994 // CHANGED THIS HERE
4995 eClass_FindDataMemberAndOffset(_class, dataMember.name, &dataMemberOffset, privateModule, null, null);
4997 // 2013/17/29 -- It seems that this was missing here!
4998 if(_class.type == normalClass)
4999 dataMemberOffset += _class.base.structSize;
5000 // dataMemberOffset = dataMember.offset;
5007 prop = eClass_FindProperty(_class, ident.string, privateModule);
5011 if(prop.memberAccess == publicAccess)
5013 curMember = (DataMember)prop;
5014 curClass = prop._class;
5019 DataMember _subMemberStack[256];
5020 int _subMemberStackPos = 0;
5022 // FILL MEMBER STACK
5023 dataMember = eClass_FindDataMemberAndOffset(_class, ident.string, &dataMemberOffset, privateModule, _subMemberStack, &_subMemberStackPos);
5028 if(dataMember.memberAccess == publicAccess)
5030 curMember = dataMember;
5031 curClass = dataMember._class;
5032 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
5033 subMemberStackPos = _subMemberStackPos;
5039 if(found && member.initializer && member.initializer.type == expInitializer)
5041 Expression value = member.initializer.exp;
5043 bool deepMember = false;
5046 type = prop.dataType;
5050 if(!dataMember.dataType)
5051 dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
5053 type = dataMember.dataType;
5056 if(ident && ident.next)
5060 // for(; ident && type; ident = ident.next)
5061 for(ident = ident.next; ident && type; ident = ident.next)
5063 if(type.kind == classType)
5065 prop = eClass_FindProperty(type._class.registered,
5066 ident.string, privateModule);
5068 type = prop.dataType;
5071 dataMember = eClass_FindDataMemberAndOffset(type._class.registered,
5072 ident.string, &dataMemberOffset, privateModule, null, null);
5074 type = dataMember.dataType;
5077 else if(type.kind == structType || type.kind == unionType)
5080 for(memberType = type.members.first; memberType; memberType = memberType.next)
5082 if(!strcmp(memberType.name, ident.string))
5093 FreeType(value.destType);
5094 value.destType = type;
5095 if(type) type.refCount++;
5096 ComputeExpression(value);
5098 if(!deepMember && type && value && (_class.type == structClass || _class.type == normalClass || _class.type == noHeadClass /*&& value.expType.kind == type.kind*/))
5100 if(type.kind == classType)
5102 Class _class = type._class.registered;
5103 if(_class.type == bitClass || _class.type == unitClass ||
5104 _class.type == enumClass)
5106 if(!_class.dataType)
5107 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5108 type = _class.dataType;
5114 void * ptr = inst.data + dataMemberOffset;
5116 if(value.type == constantExp)
5122 GetInt(value, (int*)ptr);
5127 GetInt64(value, (int64*)ptr);
5132 GetIntPtr(value, (intptr*)ptr);
5137 GetIntSize(value, (intsize*)ptr);
5142 GetFloat(value, (float*)ptr);
5147 GetDouble(value, (double *)ptr);
5152 else if(value.type == instanceExp)
5154 if(type.kind == classType)
5156 Class _class = type._class.registered;
5157 if(_class.type == structClass)
5159 ComputeTypeSize(type);
5160 if(value.instance.data)
5161 memcpy(ptr, value.instance.data, type.size);
5168 if(value.type == instanceExp && value.instance.data)
5170 if(type.kind == classType)
5172 Class _class = type._class.registered;
5173 if(_class && (_class.type != normalClass || eClass_IsDerived(((Instance)value.instance.data)._class, _class)))
5175 void (*Set)(void *, void *) = (void *)prop.Set;
5176 Set(inst.data, value.instance.data);
5177 PopulateInstance(inst);
5181 else if(value.type == constantExp)
5187 void (*Set)(void *, double) = (void *)prop.Set;
5188 Set(inst.data, strtod(value.constant, null) );
5193 void (*Set)(void *, float) = (void *)prop.Set;
5194 Set(inst.data, (float)(strtod(value.constant, null)));
5199 void (*Set)(void *, int) = (void *)prop.Set;
5200 Set(inst.data, (int)strtol(value.constant, null, 0));
5205 void (*Set)(void *, int64) = (void *)prop.Set;
5206 Set(inst.data, _strtoi64(value.constant, null, 0));
5211 void (*Set)(void *, intptr) = (void *)prop.Set;
5212 Set(inst.data, (intptr)_strtoi64(value.constant, null, 0));
5217 void (*Set)(void *, intsize) = (void *)prop.Set;
5218 Set(inst.data, (intsize)_strtoi64(value.constant, null, 0));
5223 else if(value.type == stringExp)
5226 ReadString(temp, value.string);
5227 ((void (*)(void *, void *))(void *)prop.Set)(inst.data, temp);
5231 else if(!deepMember && type && _class.type == unitClass)
5235 // Only support converting units to units for now...
5236 if(value.type == constantExp)
5238 if(type.kind == classType)
5240 Class _class = type._class.registered;
5241 if(_class.type == unitClass)
5243 if(!_class.dataType)
5244 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5245 type = _class.dataType;
5248 // TODO: Assuming same base type for units...
5254 float (*Set)(float) = (void *)prop.Set;
5255 GetFloat(member.initializer.exp, &fValue);
5256 exp.constant = PrintFloat(Set(fValue));
5257 exp.type = constantExp;
5263 double (*Set)(double) = (void *)prop.Set;
5264 GetDouble(member.initializer.exp, &dValue);
5265 exp.constant = PrintDouble(Set(dValue));
5266 exp.type = constantExp;
5273 else if(!deepMember && type && _class.type == bitClass)
5277 if(value.type == instanceExp && value.instance.data)
5279 unsigned int (*Set)(void *) = (void *)prop.Set;
5280 bits = Set(value.instance.data);
5282 else if(value.type == constantExp)
5288 BitMember bitMember = (BitMember) dataMember;
5291 bits = (bits & ~bitMember.mask);
5292 if(!bitMember.dataType)
5293 bitMember.dataType = ProcessTypeString(bitMember.dataTypeString, false);
5294 type = bitMember.dataType;
5295 if(type.kind == classType && type._class && type._class.registered)
5297 if(!type._class.registered.dataType)
5298 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
5299 type = type._class.registered.dataType;
5304 case charType: { byte v; type.isSigned ? GetChar(value, (char *)&v) : GetUChar(value, &v); part = (uint64)v; break; }
5305 case shortType: { uint16 v; type.isSigned ? GetShort(value, (short *)&v) : GetUShort(value, &v); part = (uint64)v; break; }
5307 case longType: { uint v; type.isSigned ? GetInt(value, (int *)&v) : GetUInt(value, &v); part = (uint64)v; break; }
5308 case int64Type: { uint64 v; type.isSigned ? GetInt64(value, (int64 *)&v) : GetUInt64(value, &v); part = (uint64)v; break; }
5309 case intPtrType: { uintptr v; type.isSigned ? GetIntPtr(value, (intptr *)&v) : GetUIntPtr(value, &v); part = (uint64)v; break; }
5310 case intSizeType: { uintsize v; type.isSigned ? GetIntSize(value, (intsize *)&v) : GetUIntSize(value, &v); part = (uint64)v; break; }
5312 bits |= part << bitMember.pos;
5318 if(_class && _class.type == unitClass)
5320 ComputeExpression(member.initializer.exp);
5321 exp.constant = member.initializer.exp.constant;
5322 exp.type = constantExp;
5324 member.initializer.exp.constant = null;
5334 if(_class && _class.type == bitClass)
5336 exp.constant = PrintHexUInt(bits);
5337 exp.type = constantExp;
5339 if(exp.type != instanceExp)
5345 static bool Promote(Operand op, TypeKind kind, bool isSigned)
5347 bool result = false;
5351 if(op.kind == charType || op.kind == enumType || op.kind == _BoolType)
5352 result = isSigned ? GetOpShort(op, &op.s) : GetOpUShort(op, &op.us);
5356 if(op.kind == charType || op.kind == shortType || op.kind == enumType || op.kind == _BoolType)
5357 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5360 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5361 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5362 result = isSigned ? GetOpInt64(op, &op.i64) : GetOpUInt64(op, &op.ui64);
5365 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType ||
5366 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5367 result = GetOpFloat(op, &op.f);
5370 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType ||
5371 op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5372 result = GetOpDouble(op, &op.d);
5375 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5376 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5377 result = GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5380 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == int64Type || op.kind == longType || op.kind == floatType || op.kind == doubleType ||
5381 op.kind == pointerType || op.kind == enumType || op.kind == intPtrType || op.kind == intSizeType || op.kind == _BoolType)
5382 result = isSigned ? GetOpInt(op, &op.i) : GetOpUInt(op, &op.ui);
5385 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5386 result = isSigned ? GetOpInt64 /*GetOpIntPtr*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntPtr*/(op, &op.ui64);
5389 if(op.kind == charType || op.kind == shortType || op.kind == intType || op.kind == longType || op.kind == enumType || op.kind == _BoolType)
5390 result = isSigned ? GetOpInt64 /*GetOpIntSize*/(op, &op.i64) : GetOpUInt64 /*GetOpUIntSize*/(op, &op.ui64);
5396 void CallOperator(Expression exp, Expression exp1, Expression exp2, Operand op1, Operand op2)
5398 if(exp.op.op == SIZEOF)
5400 FreeExpContents(exp);
5401 exp.type = constantExp;
5402 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5413 // Provide default unary +
5414 Expression exp2 = exp.op.exp2;
5416 FreeExpContents(exp);
5417 FreeType(exp.expType);
5418 FreeType(exp.destType);
5424 if(op1.ops.Neg) { FreeExpContents(exp); op1.ops.Neg(exp, op1); }
5426 // unary arithmetic increment and decrement
5427 //OPERATOR_ALL(UNARY, ++, Inc)
5428 //OPERATOR_ALL(UNARY, --, Dec)
5431 if(op1.ops.BitNot) { FreeExpContents(exp); op1.ops.BitNot(exp, op1); }
5433 // unary logical negation
5435 if(op1.ops.Not) { FreeExpContents(exp); op1.ops.Not(exp, op1); }
5441 if(op1 && op2 && op1.type && op2.type && op1.kind != op2.kind)
5443 if(Promote(op2, op1.kind, op1.type.isSigned))
5444 op2.kind = op1.kind, op2.ops = op1.ops;
5445 else if(Promote(op1, op2.kind, op2.type.isSigned))
5446 op1.kind = op2.kind, op1.ops = op2.ops;
5450 // binary arithmetic
5452 if(op1.ops.Add) { FreeExpContents(exp); op1.ops.Add(exp, op1, op2); }
5455 if(op1.ops.Sub) { FreeExpContents(exp); op1.ops.Sub(exp, op1, op2); }
5458 if(op1.ops.Mul) { FreeExpContents(exp); op1.ops.Mul(exp, op1, op2); }
5461 if(op1.ops.Div) { FreeExpContents(exp); op1.ops.Div(exp, op1, op2); }
5464 if(op1.ops.Mod) { FreeExpContents(exp); op1.ops.Mod(exp, op1, op2); }
5466 // binary arithmetic assignment
5467 //OPERATOR_ALL(BINARY, =, Asign)
5468 //OPERATOR_ALL(BINARY, +=, AddAsign)
5469 //OPERATOR_ALL(BINARY, -=, SubAsign)
5470 //OPERATOR_ALL(BINARY, *=, MulAsign)
5471 //OPERATOR_ALL(BINARY, /=, DivAsign)
5472 //OPERATOR_ALL(BINARY, %=, ModAsign)
5477 if(op1.ops.BitAnd) { FreeExpContents(exp); op1.ops.BitAnd(exp, op1, op2); }
5481 if(op1.ops.BitOr) { FreeExpContents(exp); op1.ops.BitOr(exp, op1, op2); }
5484 if(op1.ops.BitXor) { FreeExpContents(exp); op1.ops.BitXor(exp, op1, op2); }
5487 if(op1.ops.LShift) { FreeExpContents(exp); op1.ops.LShift(exp, op1, op2); }
5490 if(op1.ops.RShift) { FreeExpContents(exp); op1.ops.RShift(exp, op1, op2); }
5492 // binary bitwise assignment
5493 //OPERATOR_INTTYPES(BINARY, &=, AndAsign)
5494 //OPERATOR_INTTYPES(BINARY, |=, OrAsign)
5495 //OPERATOR_INTTYPES(BINARY, ^=, XorAsign)
5496 //OPERATOR_INTTYPES(BINARY, <<=, LShiftAsign)
5497 //OPERATOR_INTTYPES(BINARY, >>=, RShiftAsign)
5498 // binary logical equality
5500 if(op1.ops.Equ) { FreeExpContents(exp); op1.ops.Equ(exp, op1, op2); }
5503 if(op1.ops.Nqu) { FreeExpContents(exp); op1.ops.Nqu(exp, op1, op2); }
5507 if(op1.ops.And) { FreeExpContents(exp); op1.ops.And(exp, op1, op2); }
5510 if(op1.ops.Or) { FreeExpContents(exp); op1.ops.Or(exp, op1, op2); }
5512 // binary logical relational
5514 if(op1.ops.Grt) { FreeExpContents(exp); op1.ops.Grt(exp, op1, op2); }
5517 if(op1.ops.Sma) { FreeExpContents(exp); op1.ops.Sma(exp, op1, op2); }
5520 if(op1.ops.GrtEqu) { FreeExpContents(exp); op1.ops.GrtEqu(exp, op1, op2); }
5523 if(op1.ops.SmaEqu) { FreeExpContents(exp); op1.ops.SmaEqu(exp, op1, op2); }
5530 void ComputeExpression(Expression exp)
5533 char expString[10240];
5534 expString[0] = '\0';
5535 PrintExpression(exp, expString);
5542 ComputeInstantiation(exp);
5551 Expression exp1, exp2 = null;
5555 // We don't care about operations with only exp2 (INC_OP, DEC_OP...)
5558 Expression e = exp.op.exp2;
5560 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
5562 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
5564 if(e.type == extensionCompoundExp)
5565 e = ((Statement)e.compound.compound.statements->last).expressions->last;
5570 if(exp.op.op == TokenType::sizeOf && e && e.expType)
5572 if(e.type == stringExp && e.string)
5574 char * string = e.string;
5575 int len = strlen(string);
5576 char * tmp = new char[len-2+1];
5577 len = UnescapeString(tmp, string + 1, len - 2);
5579 FreeExpContents(exp);
5580 exp.type = constantExp;
5581 exp.constant = PrintUInt(len + 1);
5585 Type type = e.expType;
5587 FreeExpContents(exp);
5588 exp.type = constantExp;
5589 exp.constant = PrintUInt(ComputeTypeSize(type));
5595 ComputeExpression(exp.op.exp2);
5599 ComputeExpression(exp.op.exp1);
5602 op1 = GetOperand(exp1);
5603 if(op1.type) op1.type.refCount++;
5606 op2 = GetOperand(exp2);
5607 if(op2.type) op2.type.refCount++;
5613 op1 = GetOperand(exp1);
5614 if(op1.type) op1.type.refCount++;
5617 CallOperator(exp, exp1, exp2, op1, op2);
5624 if(exp.op.exp1 && exp.op.exp2)
5629 FreeExpContents(exp);
5630 op1.ops.BitAnd(exp, op1, op2);
5639 FreeExpContents(exp);
5640 op1.ops.Mul(exp, op1, op2);
5649 FreeExpContents(exp);
5650 op1.ops.Add(exp, op1, op2);
5655 // Provide default unary +
5656 Expression exp2 = exp.op.exp2;
5658 FreeExpContents(exp);
5659 FreeType(exp.expType);
5660 FreeType(exp.destType);
5671 FreeExpContents(exp);
5672 op1.ops.Sub(exp, op1, op2);
5679 FreeExpContents(exp);
5680 op1.ops.Neg(exp, op1);
5687 FreeExpContents(exp);
5688 op1.ops.BitNot(exp, op1);
5694 FreeExpContents(exp);
5695 op1.ops.Not(exp, op1);
5698 // Binary only operators
5702 FreeExpContents(exp);
5703 op1.ops.Div(exp, op1, op2);
5709 FreeExpContents(exp);
5710 op1.ops.Mod(exp, op1, op2);
5722 FreeExpContents(exp);
5723 op1.ops.Sma(exp, op1, op2);
5732 FreeExpContents(exp);
5733 op1.ops.Grt(exp, op1, op2);
5742 FreeExpContents(exp);
5743 op1.ops.SmaEqu(exp, op1, op2);
5752 FreeExpContents(exp);
5753 op1.ops.GrtEqu(exp, op1, op2);
5762 FreeExpContents(exp);
5763 op1.ops.Equ(exp, op1, op2);
5772 FreeExpContents(exp);
5773 op1.ops.Nqu(exp, op1, op2);
5780 FreeExpContents(exp);
5781 op1.ops.BitOr(exp, op1, op2);
5787 FreeExpContents(exp);
5788 op1.ops.BitXor(exp, op1, op2);
5796 FreeExpContents(exp);
5797 exp.type = constantExp;
5798 exp.constant = PrintUInt(ComputeTypeSize(op1.type));
5802 if(op1.type) FreeType(op1.type);
5803 if(op2.type) FreeType(op2.type);
5807 case extensionExpressionExp:
5810 for(e = exp.list->first; e; e = n)
5815 OldList * list = exp.list;
5816 Expression prev = exp.prev;
5817 Expression next = exp.next;
5818 ComputeExpression(e);
5819 //FreeExpContents(exp);
5820 FreeType(exp.expType);
5821 FreeType(exp.destType);
5840 exp.isConstant = true;
5842 ComputeExpression(exp.index.exp);
5843 if(!exp.index.exp.isConstant)
5844 exp.isConstant = false;
5846 for(e = exp.index.index->first; e; e = e.next)
5848 ComputeExpression(e);
5851 // Check if this type is int
5854 exp.isConstant = false;
5856 exp.expType = Dereference(exp.index.exp.expType);
5862 Expression memberExp = exp.member.exp;
5863 Identifier memberID = exp.member.member;
5866 ComputeExpression(exp.member.exp);
5867 type = exp.member.exp.expType;
5870 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);
5871 Property prop = null;
5872 DataMember member = null;
5873 Class convertTo = null;
5874 if(type.kind == subClassType && exp.member.exp.type == classExp)
5875 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
5882 PrintTypeNoConst(type, string, false, true);
5883 classSym = FindClass(string);
5884 _class = classSym ? classSym.registered : null;
5887 if(exp.member.member)
5889 prop = eClass_FindProperty(_class, exp.member.member.string, privateModule);
5891 member = eClass_FindDataMember(_class, exp.member.member.string, privateModule, null, null);
5893 if(!prop && !member && _class && exp.member.member)
5895 Symbol classSym = FindClass(exp.member.member.string);
5897 _class = classSym ? classSym.registered : null;
5898 prop = eClass_FindProperty(_class, convertTo.fullName, privateModule);
5905 Type type = prop.dataType;
5906 // TODO: Assuming same base type for units...
5907 if(_class.type == unitClass)
5909 if(type.kind == classType)
5911 Class _class = type._class.registered;
5912 if(_class.type == unitClass)
5914 if(!_class.dataType)
5915 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
5916 type = _class.dataType;
5924 float (*Get)(float) = (void *)prop.Get;
5925 GetFloat(exp.member.exp, &value);
5926 exp.constant = PrintFloat(Get ? Get(value) : value);
5927 exp.type = constantExp;
5933 double (*Get)(double);
5934 GetDouble(exp.member.exp, &value);
5937 Get = (void *)prop.Set;
5939 Get = (void *)prop.Get;
5940 exp.constant = PrintDouble(Get ? Get(value) : value);
5941 exp.type = constantExp;
5950 Expression value = exp.member.exp;
5953 ProcessPropertyType(prop);
5955 type = prop.dataType;
5958 // printf("Investigate this\n");
5960 else if(_class.type == structClass)
5966 Class propertyClass = type._class.registered;
5967 if(propertyClass.type == structClass && value.type == instanceExp)
5969 void (*Set)(void *, void *) = (void *)prop.Set;
5970 exp.instance = Instantiation { };
5971 exp.instance.data = new0 byte[_class.structSize];
5972 exp.instance._class = MkSpecifierName(_class.fullName);
5973 exp.instance.loc = exp.loc;
5974 exp.type = instanceExp;
5975 Set(exp.instance.data, value.instance.data);
5976 PopulateInstance(exp.instance);
5983 void (*Set)(void *, int) = (void *)prop.Set;
5985 exp.instance = Instantiation { };
5986 exp.instance.data = new0 byte[_class.structSize];
5987 exp.instance._class = MkSpecifierName(_class.fullName);
5988 exp.instance.loc = exp.loc;
5989 exp.type = instanceExp;
5991 GetInt(value, &intValue);
5993 Set(exp.instance.data, intValue);
5994 PopulateInstance(exp.instance);
6000 void (*Set)(void *, int64) = (void *)prop.Set;
6002 exp.instance = Instantiation { };
6003 exp.instance.data = new0 byte[_class.structSize];
6004 exp.instance._class = MkSpecifierName/*MkClassName*/(_class.fullName);
6005 exp.instance.loc = exp.loc;
6006 exp.type = instanceExp;
6008 GetInt64(value, &intValue);
6010 Set(exp.instance.data, intValue);
6011 PopulateInstance(exp.instance);
6018 void (*Set)(void *, intptr) = (void *)prop.Set;
6020 exp.instance = Instantiation { };
6021 exp.instance.data = new0 byte[_class.structSize];
6022 exp.instance._class = MkSpecifierName(_class.fullName);
6023 exp.instance.loc = exp.loc;
6024 exp.type = instanceExp;
6026 GetIntPtr(value, &intValue);
6028 Set(exp.instance.data, intValue);
6029 PopulateInstance(exp.instance);
6036 void (*Set)(void *, intsize) = (void *)prop.Set;
6038 exp.instance = Instantiation { };
6039 exp.instance.data = new0 byte[_class.structSize];
6040 exp.instance._class = MkSpecifierName(_class.fullName);
6041 exp.instance.loc = exp.loc;
6042 exp.type = instanceExp;
6044 GetIntSize(value, &intValue);
6046 Set(exp.instance.data, intValue);
6047 PopulateInstance(exp.instance);
6053 void (*Set)(void *, float) = (void *)prop.Set;
6055 exp.instance = Instantiation { };
6056 exp.instance.data = new0 byte[_class.structSize];
6057 exp.instance._class = MkSpecifierName(_class.fullName);
6058 exp.instance.loc = exp.loc;
6059 exp.type = instanceExp;
6061 GetFloat(value, &floatValue);
6063 Set(exp.instance.data, floatValue);
6064 PopulateInstance(exp.instance);
6070 void (*Set)(void *, double) = (void *)prop.Set;
6072 exp.instance = Instantiation { };
6073 exp.instance.data = new0 byte[_class.structSize];
6074 exp.instance._class = MkSpecifierName(_class.fullName);
6075 exp.instance.loc = exp.loc;
6076 exp.type = instanceExp;
6078 GetDouble(value, &doubleValue);
6080 Set(exp.instance.data, doubleValue);
6081 PopulateInstance(exp.instance);
6086 else if(_class.type == bitClass)
6092 Class propertyClass = type._class.registered;
6093 if(propertyClass.type == structClass && value.instance.data)
6095 unsigned int (*Set)(void *) = (void *)prop.Set;
6096 unsigned int bits = Set(value.instance.data);
6097 exp.constant = PrintHexUInt(bits);
6098 exp.type = constantExp;
6101 else if(_class.type == bitClass)
6104 unsigned int (*Set)(unsigned int) = (void *)prop.Set;
6107 GetUInt(exp.member.exp, &value);
6109 exp.constant = PrintHexUInt(bits);
6110 exp.type = constantExp;
6118 if(_class.type == bitClass)
6121 GetUInt(exp.member.exp, &value);
6127 Class _class = type._class.registered;
6128 if(_class.type == structClass)
6130 void (*Get)(unsigned int, void *) = (void *)prop.Get;
6132 exp.instance = Instantiation { };
6133 exp.instance.data = new0 byte[_class.structSize];
6134 exp.instance._class = MkSpecifierName(_class.fullName);
6135 exp.instance.loc = exp.loc;
6136 //exp.instance.fullSet = true;
6137 exp.type = instanceExp;
6138 Get(value, exp.instance.data);
6139 PopulateInstance(exp.instance);
6141 else if(_class.type == bitClass)
6143 unsigned int (*Get)(unsigned int) = (void *)prop.Get;
6144 uint64 bits = Get(value);
6145 exp.constant = PrintHexUInt64(bits);
6146 exp.type = constantExp;
6152 else if(_class.type == structClass)
6154 byte * value = (exp.member.exp.type == instanceExp ) ? exp.member.exp.instance.data : null;
6159 Class _class = type._class.registered;
6160 if(_class.type == structClass && value)
6162 void (*Get)(void *, void *) = (void *)prop.Get;
6164 exp.instance = Instantiation { };
6165 exp.instance.data = new0 byte[_class.structSize];
6166 exp.instance._class = MkSpecifierName(_class.fullName);
6167 exp.instance.loc = exp.loc;
6168 //exp.instance.fullSet = true;
6169 exp.type = instanceExp;
6170 Get(value, exp.instance.data);
6171 PopulateInstance(exp.instance);
6179 char * value = exp.member.exp.instance.data;
6184 Class _class = type._class.registered;
6185 if(_class.type == normalClass)
6187 void *(*Get)(void *) = (void *)prop.Get;
6189 exp.instance = Instantiation { };
6190 exp.instance._class = MkSpecifierName(_class.fullName); //MkClassName(_class.fullName);
6191 exp.type = instanceExp;
6192 exp.instance.data = Get(value, exp.instance.data);
6204 exp.isConstant = false;
6212 if(exp.type != ExpressionType::memberExp)
6214 FreeExpression(memberExp);
6215 FreeIdentifier(memberID);
6221 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
6222 FreeExpContents(exp);
6223 exp.constant = PrintUInt(ComputeTypeSize(type));
6224 exp.type = constantExp;
6230 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
6231 if(classSym && classSym.registered)
6233 if(classSym.registered.fixed)
6235 FreeSpecifier(exp._class);
6236 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
6237 exp.type = constantExp;
6241 char className[1024];
6242 strcpy(className, "__ecereClass_");
6243 FullClassNameCat(className, classSym.string, true);
6244 //MangleClassName(className);
6246 DeclareClass(classSym, className);
6248 FreeExpContents(exp);
6249 exp.type = pointerExp;
6250 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
6251 exp.member.member = MkIdentifier("structSize");
6261 if(exp.type == castExp)
6264 ComputeExpression(exp.cast.exp);
6267 if(e && exp.expType)
6270 type = exp.destType;
6273 if(type.kind == classType)
6275 Class _class = type._class.registered;
6276 if(_class && (_class.type == unitClass || _class.type == bitClass))
6278 if(!_class.dataType)
6279 _class.dataType = ProcessTypeString(_class.dataTypeString, false);
6280 type = _class.dataType;
6291 if(GetChar(e, &value))
6293 FreeExpContents(exp);
6294 exp.constant = PrintChar(value);
6295 exp.type = constantExp;
6300 unsigned char value = 0;
6301 if(GetUChar(e, &value))
6303 FreeExpContents(exp);
6304 exp.constant = PrintUChar(value);
6305 exp.type = constantExp;
6313 if(GetShort(e, &value))
6315 FreeExpContents(exp);
6316 exp.constant = PrintShort(value);
6317 exp.type = constantExp;
6322 unsigned short value = 0;
6323 if(GetUShort(e, &value))
6325 FreeExpContents(exp);
6326 exp.constant = PrintUShort(value);
6327 exp.type = constantExp;
6335 if(GetInt(e, &value))
6337 FreeExpContents(exp);
6338 exp.constant = PrintInt(value);
6339 exp.type = constantExp;
6344 unsigned int value = 0;
6345 if(GetUInt(e, &value))
6347 FreeExpContents(exp);
6348 exp.constant = PrintUInt(value);
6349 exp.type = constantExp;
6357 if(GetInt64(e, &value))
6359 FreeExpContents(exp);
6360 exp.constant = PrintInt64(value);
6361 exp.type = constantExp;
6367 if(GetUInt64(e, &value))
6369 FreeExpContents(exp);
6370 exp.constant = PrintUInt64(value);
6371 exp.type = constantExp;
6379 if(GetIntPtr(e, &value))
6381 FreeExpContents(exp);
6382 exp.constant = PrintInt64((int64)value);
6383 exp.type = constantExp;
6389 if(GetUIntPtr(e, &value))
6391 FreeExpContents(exp);
6392 exp.constant = PrintUInt64((uint64)value);
6393 exp.type = constantExp;
6401 if(GetIntSize(e, &value))
6403 FreeExpContents(exp);
6404 exp.constant = PrintInt64((int64)value);
6405 exp.type = constantExp;
6411 if(GetUIntSize(e, &value))
6413 FreeExpContents(exp);
6414 exp.constant = PrintUInt64((uint64)value);
6415 exp.type = constantExp;
6422 if(GetFloat(e, &value))
6424 FreeExpContents(exp);
6425 exp.constant = PrintFloat(value);
6426 exp.type = constantExp;
6433 if(GetDouble(e, &value))
6435 FreeExpContents(exp);
6436 exp.constant = PrintDouble(value);
6437 exp.type = constantExp;
6452 // Caring only about last expression for now...
6453 ComputeExpression(exp.cond.exp->last);
6454 if(exp.cond.elseExp)
6455 ComputeExpression(exp.cond.elseExp);
6457 ComputeExpression(exp.cond.cond);
6459 op1 = GetOperand(exp.cond.cond);
6460 if(op1.type) op1.type.refCount++;
6461 op2 = GetOperand(exp.cond.exp->last);
6462 if(op2.type) op2.type.refCount++;
6463 op3 = GetOperand(exp.cond.elseExp);
6464 if(op3.type) op3.type.refCount++;
6466 if(op1.ops.Cond) { FreeExpContents(exp); op1.ops.Cond(exp, op1, op2, op3); }
6467 if(op1.type) FreeType(op1.type);
6468 if(op2.type) FreeType(op2.type);
6469 if(op3.type) FreeType(op3.type);
6475 static bool CheckExpressionType(Expression exp, Type destType, bool skipUnitBla, bool warnConst)
6480 OldList converts { };
6483 if(destType.kind == voidType)
6486 if(!MatchTypeExpression(exp, destType, &converts, skipUnitBla, warnConst))
6490 // for(convert = converts.last; convert; convert = convert.prev)
6491 for(convert = converts.first; convert; convert = convert.next)
6493 bool empty = !(convert.isGet ? (void *)convert.convert.Get : (void *)convert.convert.Set);
6496 Expression newExp { };
6497 ClassObjectType objectType = exp.expType ? exp.expType.classObjectType : none;
6499 // TODO: Check this...
6503 newExp.destType = null;
6508 exp.type = memberExp;
6509 exp.addedThis = true;
6510 exp.member.exp = newExp;
6511 FreeType(exp.member.exp.expType);
6513 exp.member.exp.expType = MkClassType(convert.convert._class.fullName);
6514 exp.member.exp.expType.classObjectType = objectType;
6515 exp.member.member = MkIdentifier(convert.convert.dataTypeString);
6516 exp.member.memberType = propertyMember;
6517 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6518 // TESTING THIS... for (int)degrees
6519 exp.needCast = true;
6520 if(exp.expType) exp.expType.refCount++;
6521 ApplyAnyObjectLogic(exp.member.exp);
6526 /*if(exp.isConstant)
6528 // Color { ColorRGB = [exp] };
6529 exp.type = instanceExp;
6530 exp.instance = MkInstantiation(MkSpecifierName((convert.convert._class.fullName), //MkClassName(convert.convert._class.fullName),
6531 null, MkListOne(MkMembersInitList(MkListOne(MkMemberInit(
6532 MkListOne(MkIdentifier(convert.convert.dataTypeString)), newExp)))));
6536 // If not constant, don't turn it yet into an instantiation
6537 // (Go through the deep members system first)
6538 exp.type = memberExp;
6539 exp.addedThis = true;
6540 exp.member.exp = newExp;
6542 // ADDED THIS HERE TO SOLVE PROPERTY ISSUES WITH NOHEAD CLASSES
6543 if(/*!notByReference && */newExp.expType && newExp.expType.kind == classType && newExp.expType._class && newExp.expType._class.registered &&
6544 newExp.expType._class.registered.type == noHeadClass)
6546 newExp.byReference = true;
6549 FreeType(exp.member.exp.expType);
6550 /*exp.member.exp.expType = convert.convert.dataType;
6551 if(convert.convert.dataType) convert.convert.dataType.refCount++;*/
6552 exp.member.exp.expType = null;
6553 if(convert.convert.dataType)
6555 exp.member.exp.expType = { };
6556 CopyTypeInto(exp.member.exp.expType, convert.convert.dataType);
6557 exp.member.exp.expType.refCount = 1;
6558 exp.member.exp.expType.classObjectType = objectType;
6559 ApplyAnyObjectLogic(exp.member.exp);
6562 exp.member.member = MkIdentifier(convert.convert._class.fullName);
6563 exp.member.memberType = reverseConversionMember;
6564 exp.expType = convert.resultType ? convert.resultType :
6565 MkClassType(convert.convert._class.fullName);
6566 exp.needCast = true;
6567 if(convert.resultType) convert.resultType.refCount++;
6573 FreeType(exp.expType);
6576 exp.expType = convert.resultType ? convert.resultType : convert.convert.dataType;
6577 if(exp.destType.casted)
6578 exp.needCast = true;
6579 if(exp.expType) exp.expType.refCount++;
6583 exp.expType = convert.resultType ? convert.resultType : MkClassType(convert.convert._class.fullName);
6584 if(exp.destType.casted)
6585 exp.needCast = true;
6586 if(convert.resultType)
6587 convert.resultType.refCount++;
6591 if(exp.isConstant && inCompiler)
6592 ComputeExpression(exp);
6594 converts.Free(FreeConvert);
6597 if(!result && exp.expType && converts.count) // TO TEST: Added converts.count here to avoid a double warning with function type
6599 result = MatchTypes(exp.expType, exp.destType, null, null, null, true, true, false, false, warnConst);
6601 if(!result && exp.expType && exp.destType)
6603 if((exp.destType.kind == classType && exp.expType.kind == pointerType &&
6604 exp.expType.type.kind == classType && exp.expType.type._class == exp.destType._class && exp.destType._class.registered && exp.destType._class.registered.type == structClass) ||
6605 (exp.expType.kind == classType && exp.destType.kind == pointerType &&
6606 exp.destType.type.kind == classType && exp.destType.type._class == exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass))
6610 // if(result) CheckTemplateTypes(exp);
6614 void CheckTemplateTypes(Expression exp)
6616 Expression nbExp = GetNonBracketsExp(exp);
6617 if(exp.destType && exp.destType.passAsTemplate && exp.expType && exp.expType.kind != templateType && !exp.expType.passAsTemplate &&
6618 (nbExp == exp || nbExp.type != castExp))
6620 Expression newExp { };
6623 if(exp.destType) exp.destType.refCount++;
6624 if(exp.expType) exp.expType.refCount++;
6628 switch(exp.expType.kind)
6631 if(exp.destType.classObjectType)
6633 // We need to pass the address, just pass it along (Undo what was done above)
6634 if(exp.destType) exp.destType.refCount--;
6635 if(exp.expType) exp.expType.refCount--;
6640 // If we're looking for value:
6641 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6643 OldList * unionDefs = MkList();
6644 OldList * statements = MkList();
6645 context = PushContext();
6646 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6647 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6648 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6649 exp.type = extensionCompoundExp;
6650 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6651 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")), '=', newExp))));
6652 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")))));
6653 exp.compound.compound.context = context;
6654 PopContext(context);
6659 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6660 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6661 exp.needCast = true;
6665 else if(exp.expType && exp.expType.passAsTemplate && exp.destType && exp.usage.usageGet && exp.destType.kind != templateType && !exp.destType.passAsTemplate)
6667 Expression newExp { };
6670 if(exp.destType) exp.destType.refCount++;
6671 if(exp.expType) exp.expType.refCount++;
6675 switch(exp.expType.kind)
6678 if(exp.destType.classObjectType)
6680 // We need to pass the address, just pass it along (Undo what was done above)
6681 if(exp.destType) exp.destType.refCount--;
6682 if(exp.expType) exp.expType.refCount--;
6687 // If we're looking for value:
6688 // ({ union { double d; uint64 i; } u; u.i = [newExp]; u.d; })
6690 OldList * unionDefs = MkList();
6691 OldList * statements = MkList();
6692 context = PushContext();
6693 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifier(DOUBLE)), MkListOne(MkDeclaratorIdentifier(MkIdentifier("d"))), null)));
6694 ListAdd(unionDefs, MkClassDefDeclaration(MkStructDeclaration(MkListOne(MkSpecifierName("uint64")), MkListOne(MkDeclaratorIdentifier(MkIdentifier("i"))), null)));
6695 specs = MkListOne(MkStructOrUnion(unionSpecifier, null, unionDefs ));
6696 exp.type = extensionCompoundExp;
6697 exp.compound = MkCompoundStmt(MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internal_union")), null)))),statements);
6698 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("i")), '=', newExp))));
6699 ListAdd(statements, MkExpressionStmt(MkListOne(MkExpMember(MkExpIdentifier(MkIdentifier("__internal_union")), MkIdentifier("d")))));
6700 exp.compound.compound.context = context;
6701 PopContext(context);
6706 if(exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass)
6708 exp.type = bracketsExp;
6709 exp.list = MkListOne(MkExpOp(null, '*', MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)),
6710 MkDeclaratorPointer(MkPointer(null, null), null)), newExp)));
6711 ProcessExpressionType(exp.list->first);
6716 exp.type = bracketsExp;
6717 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(exp.expType._class.string)), null), newExp));
6718 exp.needTemplateCast = 2;
6719 newExp.needCast = true;
6720 newExp.needTemplateCast = 2;
6721 ProcessExpressionType(exp.list->first);
6727 if(exp.expType.kind == templateType)
6729 Type type = ProcessTemplateParameterType(exp.expType.templateParameter);
6732 FreeType(exp.destType);
6733 FreeType(exp.expType);
6738 if(newExp.type == memberExp && newExp.member.memberType == dataMember)
6743 exp.op.exp2 = MkExpCast(MkTypeName(MkListOne(MkSpecifierName("uint64")), MkDeclaratorPointer(MkPointer(null, null), null)),
6744 MkExpBrackets(MkListOne(MkExpOp(null, '&', newExp))));
6748 char typeString[1024];
6750 OldList * specs = MkList();
6751 typeString[0] = '\0';
6752 PrintType(exp.expType, typeString, false, false);
6753 decl = SpecDeclFromString(typeString, specs, null);
6756 //exp.cast.typeName = MkTypeName(MkListOne(MkSpecifierName("uint64")), null);
6757 exp.cast.typeName = MkTypeName(specs, decl);
6758 exp.cast.exp = MkExpBrackets(MkListOne(newExp));
6759 exp.cast.exp.needCast = true;
6766 // TODO: The Symbol tree should be reorganized by namespaces
6768 // - Tree of all symbols within (stored without namespace)
6769 // - Tree of sub-namespaces
6771 static Symbol ScanWithNameSpace(BinaryTree tree, const char * nameSpace, const char * name)
6773 int nsLen = strlen(nameSpace);
6775 // Start at the name space prefix
6776 for(symbol = (Symbol)tree.FindPrefix(nameSpace); symbol; symbol = (Symbol)((BTNode)symbol).next)
6778 char * s = symbol.string;
6779 if(!strncmp(s, nameSpace, nsLen))
6781 // This supports e.g. matching ecere::Socket to ecere::net::Socket
6784 for(c = strlen(s)-1; c >= 0; c--)
6789 if(!strcmp(namePart, name))
6791 // TODO: Error on ambiguity
6801 static Symbol FindWithNameSpace(BinaryTree tree, const char * name)
6804 char nameSpace[1024];
6805 const char * namePart;
6806 bool gotColon = false;
6808 nameSpace[0] = '\0';
6809 for(c = strlen(name)-1; c >= 0; c--)
6816 namePart = name+c+1;
6817 while(c >= 0 && name[c] == ':') c--;
6820 // Try an exact match first
6821 Symbol symbol = (Symbol)tree.FindString(name);
6825 // Namespace specified
6826 memcpy(nameSpace, name, c + 1);
6829 return ScanWithNameSpace(tree, nameSpace, namePart);
6833 // Looking for a global symbol, e.g. ::Sleep()
6834 Symbol symbol = (Symbol)tree.FindString(namePart);
6839 // Name only (no namespace specified)
6840 Symbol symbol = (Symbol)tree.FindString(namePart);
6843 return ScanWithNameSpace(tree, "", namePart);
6848 static void ProcessDeclaration(Declaration decl);
6850 /*static */Symbol FindSymbol(const char * name, Context startContext, Context endContext, bool isStruct, bool globalNameSpace)
6853 //Time startTime = GetTime();
6855 // Optimize this later? Do this before/less?
6857 Symbol symbol = null;
6858 // First, check if the identifier is declared inside the function
6859 //for(ctx = curContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6861 for(ctx = startContext; ctx /*!= topContext.parent */&& !symbol; ctx = ctx.parent)
6863 if(ctx == globalContext && !globalNameSpace && ctx.hasNameSpace)
6869 strcpy(curName, thisNameSpace);
6870 strcat(curName, "::");
6871 strcat(curName, name);
6872 // Try to resolve in current namespace first
6873 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, curName);
6876 symbol = FindWithNameSpace(isStruct ? ctx.structSymbols : ctx.symbols, name);
6879 symbol = (Symbol)(isStruct ? ctx.structSymbols : ctx.symbols).FindString(name);
6881 if(symbol || ctx == endContext) break;
6883 if(inCompiler && curExternal && symbol && ctx == globalContext && curExternal.symbol && symbol.id > curExternal.symbol.idCode && symbol.pointerExternal)
6885 if(symbol.pointerExternal.type == functionExternal)
6887 FunctionDefinition function = symbol.pointerExternal.function;
6889 // Modified this recently...
6890 Context tmpContext = curContext;
6892 symbol.pointerExternal = MkExternalDeclaration(MkDeclaration(CopyList(function.specifiers, CopySpecifier), MkListOne(MkInitDeclarator(CopyDeclarator(function.declarator), null))));
6893 curContext = tmpContext;
6895 symbol.pointerExternal.symbol = symbol;
6898 DeclareType(symbol.type, true, true);
6900 ast->Insert(curExternal.prev, symbol.pointerExternal);
6902 symbol.id = curExternal.symbol.idCode;
6905 else if(symbol.pointerExternal.type == declarationExternal && curExternal.symbol.idCode < symbol.pointerExternal.symbol.id) // Added id comparison because Global Function prototypes were broken
6907 ast->Move(symbol.pointerExternal, curExternal.prev);
6908 symbol.id = curExternal.symbol.idCode;
6912 //findSymbolTotalTime += GetTime() - startTime;
6917 static void GetTypeSpecs(Type type, OldList * specs)
6919 if(!type.isSigned && type.kind != intPtrType && type.kind != intSizeType) ListAdd(specs, MkSpecifier(UNSIGNED));
6924 if(type._class.registered)
6926 if(!type._class.registered.dataType)
6927 type._class.registered.dataType = ProcessTypeString(type._class.registered.dataTypeString, false);
6928 GetTypeSpecs(type._class.registered.dataType, specs);
6932 case doubleType: ListAdd(specs, MkSpecifier(DOUBLE)); break;
6933 case floatType: ListAdd(specs, MkSpecifier(FLOAT)); break;
6934 case charType: ListAdd(specs, MkSpecifier(CHAR)); break;
6935 case _BoolType: ListAdd(specs, MkSpecifier(_BOOL)); break;
6936 case shortType: ListAdd(specs, MkSpecifier(SHORT)); break;
6937 case int64Type: ListAdd(specs, MkSpecifier(INT64)); break;
6938 case intPtrType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intptr" : "uintptr")); break;
6939 case intSizeType: ListAdd(specs, MkSpecifierName(type.isSigned ? "intsize" : "uintsize")); break;
6942 ListAdd(specs, MkSpecifier(INT)); break;
6946 static void PrintArraySize(Type arrayType, char * string)
6951 if(arrayType.enumClass)
6952 strcat(size, arrayType.enumClass.string);
6953 else if(arrayType.arraySizeExp)
6954 PrintExpression(arrayType.arraySizeExp, size);
6956 strcat(string, size);
6959 // WARNING : This function expects a null terminated string since it recursively concatenate...
6960 static void PrintTypeSpecs(Type type, char * string, bool fullName, bool printConst)
6964 if(printConst && type.constant)
6965 strcat(string, "const ");
6970 Symbol c = type._class;
6971 // TODO: typed_object does not fully qualify the type, as it may have taken up an actual class (Stored in _class) from overriding
6972 // look into merging with thisclass ?
6973 if(type.classObjectType == typedObject)
6974 strcat(string, "typed_object");
6975 else if(type.classObjectType == anyObject)
6976 strcat(string, "any_object");
6980 strcat(string, (fullName || !c.registered) ? c.string : c.registered.name);
6982 if(type.byReference)
6983 strcat(string, " &");
6986 case voidType: strcat(string, "void"); break;
6987 case intType: strcat(string, type.isSigned ? "int" : "uint"); break;
6988 case int64Type: strcat(string, type.isSigned ? "int64" : "uint64"); break;
6989 case intPtrType: strcat(string, type.isSigned ? "intptr" : "uintptr"); break;
6990 case intSizeType: strcat(string, type.isSigned ? "intsize" : "uintsize"); break;
6991 case charType: strcat(string, type.isSigned ? "char" : "byte"); break;
6992 case _BoolType: strcat(string, "_Bool"); break;
6993 case shortType: strcat(string, type.isSigned ? "short" : "uint16"); break;
6994 case floatType: strcat(string, "float"); break;
6995 case doubleType: strcat(string, "double"); break;
6999 strcat(string, "struct ");
7000 strcat(string, type.enumName);
7002 else if(type.typeName)
7003 strcat(string, type.typeName);
7007 strcat(string, "struct { ");
7008 for(member = type.members.first; member; member = member.next)
7010 PrintType(member, string, true, fullName);
7011 strcat(string,"; ");
7019 strcat(string, "union ");
7020 strcat(string, type.enumName);
7022 else if(type.typeName)
7023 strcat(string, type.typeName);
7026 strcat(string, "union ");
7027 strcat(string,"(unnamed)");
7033 strcat(string, "enum ");
7034 strcat(string, type.enumName);
7036 else if(type.typeName)
7037 strcat(string, type.typeName);
7039 strcat(string, "int"); // "enum");
7042 strcat(string, "...");
7045 strcat(string, "subclass(");
7046 strcat(string, type._class ? type._class.string : "int");
7047 strcat(string, ")");
7050 strcat(string, type.templateParameter.identifier.string);
7053 strcat(string, "thisclass");
7056 strcat(string, "__builtin_va_list");
7062 static void PrintName(Type type, char * string, bool fullName)
7064 if(type.name && type.name[0])
7067 strcat(string, type.name);
7070 char * name = RSearchString(type.name, "::", strlen(type.name), true, false);
7071 if(name) name += 2; else name = type.name;
7072 strcat(string, name);
7077 static void PrintAttribs(Type type, char * string)
7081 if(type.dllExport) strcat(string, "dllexport ");
7082 if(type.attrStdcall) strcat(string, "stdcall ");
7086 static void PrePrintType(Type type, char * string, bool fullName, Type parentType, bool printConst)
7088 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7090 if((type.kind == functionType || type.kind == methodType) && (!parentType || parentType.kind != pointerType))
7091 PrintAttribs(type, string);
7092 if(printConst && type.constant && (type.kind == functionType || type.kind == methodType))
7093 strcat(string, " const");
7094 PrePrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName, type, printConst);
7095 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7096 strcat(string, " (");
7097 if(type.kind == pointerType)
7099 if(type.type.kind == functionType || type.type.kind == methodType)
7100 PrintAttribs(type.type, string);
7102 if(type.kind == pointerType)
7104 if(type.type.kind == functionType || type.type.kind == methodType || type.type.kind == arrayType)
7105 strcat(string, "*");
7107 strcat(string, " *");
7109 if(printConst && type.constant && type.kind == pointerType)
7110 strcat(string, " const");
7113 PrintTypeSpecs(type, string, fullName, printConst);
7116 static void PostPrintType(Type type, char * string, bool fullName)
7118 if(type.kind == pointerType && (type.type.kind == arrayType || type.type.kind == functionType || type.type.kind == methodType))
7119 strcat(string, ")");
7120 if(type.kind == arrayType)
7121 PrintArraySize(type, string);
7122 else if(type.kind == functionType)
7125 strcat(string, "(");
7126 for(param = type.params.first; param; param = param.next)
7128 PrintType(param, string, true, fullName);
7129 if(param.next) strcat(string, ", ");
7131 strcat(string, ")");
7133 if(type.kind == arrayType || type.kind == pointerType || type.kind == functionType || type.kind == methodType)
7134 PostPrintType(type.kind == methodType ? type.method.dataType : type.type, string, fullName);
7138 // TODO: Add a max buffer size to avoid overflows. This function is used with static size char arrays.
7140 static void _PrintType(Type type, char * string, bool printName, bool fullName, bool printConst)
7142 PrePrintType(type, string, fullName, null, printConst);
7144 if(type.thisClass || (printName && type.name && type.name[0]))
7145 strcat(string, " ");
7146 if(/*(type.kind == methodType || type.kind == functionType) && */(type.thisClass || type.staticMethod))
7148 Symbol _class = type.thisClass;
7149 if((type.classObjectType == typedObject || type.classObjectType == classPointer) || (_class && !strcmp(_class.string, "class")))
7151 if(type.classObjectType == classPointer)
7152 strcat(string, "class");
7154 strcat(string, type.byReference ? "typed_object&" : "typed_object");
7156 else if(_class && _class.string)
7158 String s = _class.string;
7163 char * name = RSearchString(s, "::", strlen(s), true, false);
7164 if(name) name += 2; else name = s;
7165 strcat(string, name);
7168 strcat(string, "::");
7171 if(printName && type.name)
7172 PrintName(type, string, fullName);
7173 PostPrintType(type, string, fullName);
7174 if(type.bitFieldCount)
7177 sprintf(count, ":%d", type.bitFieldCount);
7178 strcat(string, count);
7182 void PrintType(Type type, char * string, bool printName, bool fullName)
7184 _PrintType(type, string, printName, fullName, true);
7187 void PrintTypeNoConst(Type type, char * string, bool printName, bool fullName)
7189 _PrintType(type, string, printName, fullName, false);
7192 static Type FindMember(Type type, char * string)
7195 for(memberType = type.members.first; memberType; memberType = memberType.next)
7197 if(!memberType.name)
7199 Type subType = FindMember(memberType, string);
7203 else if(!strcmp(memberType.name, string))
7209 Type FindMemberAndOffset(Type type, char * string, uint * offset)
7212 for(memberType = type.members.first; memberType; memberType = memberType.next)
7214 if(!memberType.name)
7216 Type subType = FindMember(memberType, string);
7219 *offset += memberType.offset;
7223 else if(!strcmp(memberType.name, string))
7225 *offset += memberType.offset;
7232 public bool GetParseError() { return parseError; }
7234 Expression ParseExpressionString(char * expression)
7238 fileInput = TempFile { };
7239 fileInput.Write(expression, 1, strlen(expression));
7240 fileInput.Seek(0, start);
7243 parsedExpression = null;
7245 expression_yyparse();
7248 return parsedExpression;
7251 static bool ResolveIdWithClass(Expression exp, Class _class, bool skipIDClassCheck)
7253 Identifier id = exp.identifier;
7254 Method method = null;
7255 Property prop = null;
7256 DataMember member = null;
7257 ClassProperty classProp = null;
7259 if(_class && _class.type == enumClass)
7261 NamedLink64 value = null;
7262 Class enumClass = eSystem_FindClass(privateModule, "enum");
7266 for(baseClass = _class; baseClass && baseClass.type == ClassType::enumClass; baseClass = baseClass.base)
7268 EnumClassData e = ACCESS_CLASSDATA(baseClass, enumClass);
7269 for(value = e.values.first; value; value = value.next)
7271 if(!strcmp(value.name, id.string))
7278 FreeExpContents(exp);
7280 exp.type = constantExp;
7281 exp.isConstant = true;
7282 if(!strcmp(baseClass.dataTypeString, "int") || !strcmp(baseClass.dataTypeString, "int64") || !strcmp(baseClass.dataTypeString, "char") || !strcmp(baseClass.dataTypeString, "short"))
7283 sprintf(constant, FORMAT64D, value.data);
7285 sprintf(constant, FORMAT64HEX, value.data);
7286 exp.constant = CopyString(constant);
7287 //for(;_class.base && _class.base.type != systemClass; _class = _class.base);
7288 exp.expType = MkClassType(baseClass.fullName);
7296 if((method = eClass_FindMethod(_class, id.string, privateModule)))
7298 ProcessMethodType(method);
7305 // TOCHECK: Put it back to what it was...
7306 // methodClass = _class;
7307 methodClass = (skipIDClassCheck || (id && id._class)) ? _class : null;
7312 else if((prop = eClass_FindProperty(_class, id.string, privateModule)))
7315 ProcessPropertyType(prop);
7316 exp.expType = prop.dataType;
7317 if(prop.dataType) prop.dataType.refCount++;
7320 else if((member = eClass_FindDataMember(_class, id.string, privateModule, null, null)))
7322 if(!member.dataType)
7323 member.dataType = ProcessTypeString(member.dataTypeString, false);
7324 exp.expType = member.dataType;
7325 if(member.dataType) member.dataType.refCount++;
7328 else if((classProp = eClass_FindClassProperty(_class, id.string)))
7330 if(!classProp.dataType)
7331 classProp.dataType = ProcessTypeString(classProp.dataTypeString, false);
7333 if(classProp.constant)
7335 FreeExpContents(exp);
7337 exp.isConstant = true;
7338 if(classProp.dataType.kind == pointerType && classProp.dataType.type.kind == charType)
7340 //char constant[256];
7341 exp.type = stringExp;
7342 exp.constant = QMkString((char *)classProp.Get(_class));
7347 exp.type = constantExp;
7348 sprintf(constant, "%d", (int)classProp.Get(_class));
7349 exp.constant = CopyString(constant);
7357 exp.expType = classProp.dataType;
7358 if(classProp.dataType) classProp.dataType.refCount++;
7364 static GlobalData ScanGlobalData(NameSpace nameSpace, char * name)
7366 BinaryTree * tree = &nameSpace.functions;
7367 GlobalData data = (GlobalData)tree->FindString(name);
7371 for(child = (NameSpace *)nameSpace.nameSpaces.first; child; child = (NameSpace *)((BTNode)child).next)
7373 data = ScanGlobalData(child, name);
7381 static GlobalData FindGlobalData(char * name)
7384 NameSpace * nameSpace;
7385 nameSpace = globalData;
7386 for(c = 0; name[c]; c++)
7388 if(name[c] == '.' || (name[c] == ':' && name[c+1] == ':'))
7390 NameSpace * newSpace;
7391 char * spaceName = new char[c - start + 1];
7392 strncpy(spaceName, name + start, c - start);
7393 spaceName[c-start] = '\0';
7394 newSpace = (NameSpace *)nameSpace->nameSpaces.FindString(spaceName);
7398 nameSpace = newSpace;
7399 if(name[c] == ':') c++;
7405 return ScanGlobalData(nameSpace, name + start);
7410 static int definedExpStackPos;
7411 static void * definedExpStack[512];
7413 // This function makes checkedExp equivalent to newExp, ending up freeing newExp
7414 void ReplaceExpContents(Expression checkedExp, Expression newExp)
7416 Expression prev = checkedExp.prev, next = checkedExp.next;
7418 FreeExpContents(checkedExp);
7419 FreeType(checkedExp.expType);
7420 FreeType(checkedExp.destType);
7422 *checkedExp = *newExp;
7426 checkedExp.prev = prev;
7427 checkedExp.next = next;
7430 void ApplyAnyObjectLogic(Expression e)
7432 Type destType = /*(e.destType && e.destType.kind == ellipsisType) ? ellipsisDestType : */e.destType;
7434 char debugExpString[4096];
7435 debugExpString[0] = '\0';
7436 PrintExpression(e, debugExpString);
7439 if(destType && (/*destType.classObjectType == ClassObjectType::typedObject || */destType.classObjectType == anyObject))
7441 //if(e.destType && e.destType.kind == ellipsisType) usedEllipsis = true;
7442 //ellipsisDestType = destType;
7445 Type type = e.expType;
7446 Class _class = null;
7447 //Type destType = e.destType;
7449 if(type.kind == classType && type._class && type._class.registered)
7451 _class = type._class.registered;
7453 else if(type.kind == subClassType)
7455 _class = FindClass("ecere::com::Class").registered;
7459 char string[1024] = "";
7462 PrintTypeNoConst(type, string, false, true);
7463 classSym = FindClass(string);
7464 if(classSym) _class = classSym.registered;
7467 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...
7468 (!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))) ||
7469 destType.byReference)))
7471 if(!_class || strcmp(_class.fullName, "char *")) // TESTING THIS WITH NEW String class...
7473 Expression checkedExp = e, newExp;
7475 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7477 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7479 if(checkedExp.type == extensionCompoundExp)
7481 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7484 checkedExp = checkedExp.list->last;
7486 else if(checkedExp.type == castExp)
7487 checkedExp = checkedExp.cast.exp;
7490 if(checkedExp && checkedExp.type == opExp && checkedExp.op.op == '*' && !checkedExp.op.exp1)
7492 newExp = checkedExp.op.exp2;
7493 checkedExp.op.exp2 = null;
7494 FreeExpContents(checkedExp);
7496 if(e.expType && e.expType.passAsTemplate)
7499 ComputeTypeSize(e.expType);
7500 sprintf(size, "%d", e.expType.size);
7501 newExp = MkExpBrackets(MkListOne(MkExpOp(MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)),
7502 MkDeclaratorPointer(MkPointer(null, null), null)), newExp), '+',
7503 MkExpCall(MkExpIdentifier(MkIdentifier("__ENDIAN_PAD")), MkListOne(MkExpConstant(size))))));
7506 ReplaceExpContents(checkedExp, newExp);
7507 e.byReference = true;
7509 else if(!e.byReference || (_class && _class.type == noHeadClass)) // TESTING THIS HERE...
7511 Expression checkedExp; //, newExp;
7514 // TODO: Move code from debugTools.ec for hasAddress flag, this is just temporary
7516 e.type == identifierExp ||
7517 (e.type == ExpressionType::memberExp && e.member.memberType == dataMember) ||
7518 (e.type == ExpressionType::pointerExp && e.member.memberType == dataMember) ||
7519 (e.type == opExp && !e.op.exp1 && e.op.op == '*') ||
7522 if(_class && _class.type != noHeadClass && _class.type != normalClass && _class.type != structClass && !hasAddress)
7524 Context context = PushContext();
7526 OldList * specs = MkList();
7527 char typeString[1024];
7528 Expression newExp { };
7530 typeString[0] = '\0';
7533 //if(e.destType) e.destType.refCount++;
7534 // if(exp.expType) exp.expType.refCount++;
7537 newExp.expType = null;
7539 PrintTypeNoConst(e.expType, typeString, false, true);
7540 decl = SpecDeclFromString(typeString, specs, null);
7541 newExp.destType = ProcessType(specs, decl);
7543 curContext = context;
7545 // We need a current compound for this
7549 OldList * stmts = MkList();
7550 e.type = extensionCompoundExp;
7551 sprintf(name, "__internalValue%03X", internalValueCounter++);
7552 if(!curCompound.compound.declarations)
7553 curCompound.compound.declarations = MkList();
7554 curCompound.compound.declarations->Insert(null, MkDeclaration(specs, MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(name)), null))));
7555 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(MkIdentifier(name)), '=', newExp))));
7556 ListAdd(stmts, MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier(name)))));
7557 e.compound = MkCompoundStmt(null, stmts);
7560 printf("libec: compiler error, curCompound is null in ApplyAnyObjectLogic\n");
7563 e.compound = MkCompoundStmt(
7564 MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(
7565 MkDeclaratorIdentifier(MkIdentifier("__internalValue")), MkInitializerAssignment(newExp))))),
7567 MkListOne(MkExpressionStmt(MkListOne(MkExpIdentifier(MkIdentifier("__internalValue"))))));
7571 Type type = e.destType;
7573 CopyTypeInto(e.destType, type);
7574 e.destType.refCount = 1;
7575 e.destType.classObjectType = none;
7579 e.compound.compound.context = context;
7580 PopContext(context);
7581 curContext = context.parent;
7585 // TODO: INTEGRATE THIS WITH VERSION ABOVE WHICH WAS ADDED TO ENCOMPASS OTHER CASE (*pointer)
7587 while(((checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp) && checkedExp.list) || checkedExp.type == castExp)
7589 if(checkedExp.type == bracketsExp || checkedExp.type == extensionExpressionExp || checkedExp.type == extensionCompoundExp)
7591 if(checkedExp.type == extensionCompoundExp)
7593 checkedExp = ((Statement)checkedExp.compound.compound.statements->last).expressions->last;
7596 checkedExp = checkedExp.list->last;
7598 else if(checkedExp.type == castExp)
7599 checkedExp = checkedExp.cast.exp;
7602 Expression operand { };
7603 operand = *checkedExp;
7605 checkedExp.destType = ProcessTypeString("void *", false);
7606 checkedExp.expType = checkedExp.destType;
7607 checkedExp.destType.refCount++;
7609 checkedExp.type = opExp;
7610 checkedExp.op.op = '&';
7611 checkedExp.op.exp1 = null;
7612 checkedExp.op.exp2 = operand;
7614 //newExp = MkExpOp(null, '&', checkedExp);
7616 //ReplaceExpContents(checkedExp, newExp);
7623 // If expression type is a simple class, make it an address
7624 // FixReference(e, true);
7627 if((!destType || destType.kind == ellipsisType || destType.kind == voidType) && e.expType && (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7628 (e.expType.byReference || (e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7629 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass ) )))
7631 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"))
7633 return; // LEAVE THIS CASE (typed_object & :: methods 's this) TO PASS 2 FOR NOW
7637 Expression thisExp { };
7640 thisExp.prev = null;
7641 thisExp.next = null;
7644 e.type = bracketsExp;
7645 e.list = MkListOne(MkExpOp(null, '*', thisExp.type == identifierExp ? thisExp : MkExpBrackets(MkListOne(thisExp))));
7646 if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && thisExp.expType._class.registered.type == noHeadClass)
7647 ((Expression)e.list->first).byReference = true;
7649 /*if(thisExp.expType.kind == classType && thisExp.expType._class && thisExp.expType._class.registered && !strcmp(thisExp.expType._class.registered.name, "class"))
7651 e.expType = thisExp.expType;
7652 e.expType.refCount++;
7657 CopyTypeInto(e.expType, thisExp.expType);
7658 e.expType.byReference = false;
7659 e.expType.refCount = 1;
7661 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered &&
7662 (e.expType._class.registered.type == bitClass || e.expType._class.registered.type == enumClass || e.expType._class.registered.type == unitClass))
7664 e.expType.classObjectType = none;
7669 // TOFIX: Try this for a nice IDE crash!
7671 // The other way around
7674 if(destType && e.expType &&
7675 //e.expType.kind == classType && e.expType._class && e.expType._class.registered && !strcmp(e.expType._class.registered.name, "class") &&
7676 (e.expType.classObjectType == anyObject || e.expType.classObjectType == typedObject) &&
7677 !destType.classObjectType && /*(destType.kind != pointerType || !destType.type || destType.type.kind != voidType) &&*/ destType.kind != voidType)
7679 if(destType.kind == ellipsisType)
7681 Compiler_Error($"Unspecified type\n");
7683 else if(!(destType.truth && e.expType.kind == classType && e.expType._class && e.expType._class.registered && e.expType._class.registered.type == structClass))
7685 bool byReference = e.expType.byReference;
7686 Expression thisExp { };
7688 OldList * specs = MkList();
7689 char typeString[1024]; // Watch buffer overruns
7691 ClassObjectType backupClassObjectType;
7692 bool backupByReference;
7694 if(e.expType.kind == classType && e.expType._class && e.expType._class.registered && strcmp(e.expType._class.registered.name, "class"))
7699 backupClassObjectType = type.classObjectType;
7700 backupByReference = type.byReference;
7702 type.classObjectType = none;
7703 type.byReference = false;
7705 typeString[0] = '\0';
7706 PrintType(type, typeString, false, true);
7707 decl = SpecDeclFromString(typeString, specs, null);
7709 type.classObjectType = backupClassObjectType;
7710 type.byReference = backupByReference;
7713 thisExp.prev = null;
7714 thisExp.next = null;
7717 if( ( type.kind == classType && type._class && type._class.registered &&
7718 (type._class.registered.type == systemClass || type._class.registered.type == bitClass ||
7719 type._class.registered.type == enumClass || type._class.registered.type == unitClass) ) ||
7720 (type.kind != pointerType && type.kind != intPtrType && type.kind != arrayType && type.kind != classType) ||
7721 (!destType.byReference && byReference && (destType.kind != pointerType || type.kind != pointerType)))
7726 e.op.exp2 = MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), thisExp);
7729 CopyTypeInto(e.expType, type);
7730 e.expType.byReference = false;
7731 e.expType.refCount = 1;
7736 e.cast.typeName = MkTypeName(specs, decl);
7737 e.cast.exp = thisExp;
7738 e.byReference = true;
7742 e.destType = destType;
7743 destType.refCount++;
7748 void ApplyLocation(Expression exp, Location loc)
7754 if(exp.op.exp1) ApplyLocation(exp.op.exp1, loc);
7755 if(exp.op.exp2) ApplyLocation(exp.op.exp2, loc);
7761 for(e = exp.list->first; e; e = e.next)
7762 ApplyLocation(e, loc);
7769 for(e = exp.index.index->first; e; e = e.next)
7770 ApplyLocation(e, loc);
7773 ApplyLocation(exp.index.exp, loc);
7776 if(exp.call.arguments)
7779 for(arg = exp.call.arguments->first; arg; arg = arg.next)
7780 ApplyLocation(arg, loc);
7783 ApplyLocation(exp.call.exp, loc);
7788 ApplyLocation(exp.member.exp, loc);
7792 ApplyLocation(exp.cast.exp, loc);
7798 for(e = exp.cond.exp->first; e; e = e.next)
7799 ApplyLocation(e, loc);
7802 ApplyLocation(exp.cond.cond, loc);
7803 if(exp.cond.elseExp)
7804 ApplyLocation(exp.cond.elseExp, loc);
7808 ApplyLocation(exp.vaArg.exp, loc);
7815 void ProcessExpressionType(Expression exp)
7817 bool unresolved = false;
7818 Location oldyylloc = yylloc;
7819 bool notByReference = false;
7821 char debugExpString[4096];
7822 debugExpString[0] = '\0';
7823 PrintExpression(exp, debugExpString);
7825 if(!exp || exp.expType)
7828 //eSystem_Logf("%s\n", expString);
7830 // Testing this here
7836 Identifier id = exp.identifier;
7837 if(!id || !topContext) return;
7839 // DOING THIS LATER NOW...
7840 if(id._class && id._class.name)
7842 id.classSym = id._class.symbol; // FindClass(id._class.name);
7843 /* TODO: Name Space Fix ups
7845 id.nameSpace = eSystem_FindNameSpace(privateModule, id._class.name);
7849 /* WHY WAS THIS COMMENTED OUT? if(!strcmp(id.string, "__thisModule"))
7851 exp.expType = ProcessTypeString("Module", true);
7855 if(!strcmp(id.string, "__runtimePlatform"))
7857 exp.expType = ProcessTypeString("ecere::com::Platform", true);
7860 else if(strstr(id.string, "__ecereClass") == id.string)
7862 exp.expType = ProcessTypeString("ecere::com::Class", true);
7865 else if(id._class && (id.classSym || (id._class.name && !strcmp(id._class.name, "property"))))
7867 // Added this here as well
7868 ReplaceClassMembers(exp, thisClass);
7869 if(exp.type != identifierExp)
7871 ProcessExpressionType(exp);
7875 if(id.classSym && ResolveIdWithClass(exp, id.classSym.registered, false))
7880 Symbol symbol = FindSymbol(id.string, curContext, topContext /*exp.destType ? topContext : globalContext*/, false, id._class && id._class.name == null);
7881 // Enums should be resolved here (Special pass in opExp to fix identifiers not seen as enum on the first pass)
7882 if(!symbol/* && exp.destType*/)
7884 if(exp.destType && CheckExpressionType(exp, exp.destType, false, false))
7890 ReplaceClassMembers(exp, thisClass ? thisClass : currentClass);
7891 if(exp.type != identifierExp)
7893 ProcessExpressionType(exp);
7897 // Static methods called from inside the _class
7898 else if(currentClass && !id._class)
7900 if(ResolveIdWithClass(exp, currentClass, true))
7903 symbol = FindSymbol(id.string, topContext.parent, globalContext, false, id._class && id._class.name == null);
7907 // If we manage to resolve this symbol
7910 Type type = symbol.type;
7911 Class _class = (type && type.kind == classType && type._class) ? type._class.registered : null;
7913 if(_class && !strcmp(id.string, "this") && !type.classObjectType)
7915 Context context = SetupTemplatesContext(_class);
7916 type = ReplaceThisClassType(_class);
7917 FinishTemplatesContext(context);
7918 if(type) type.refCount = 0; // We'll be incrementing it right below...
7921 FreeSpecifier(id._class);
7924 id.string = CopyString(symbol.string);
7931 // Commented this out, it was making non-constant enum parameters seen as constant
7932 // enums should have been resolved by ResolveIdWithClass, changed to constantExp and marked as constant
7933 if(type && (type.kind == enumType /*|| (_class && _class.type == enumClass)*/))
7934 // Add missing cases here... enum Classes...
7935 exp.isConstant = true;
7937 // TOCHECK: Why was !strcmp(id.string, "this") commented out?
7938 if(symbol.isParam || !strcmp(id.string, "this"))
7940 if(_class && _class.type == structClass && !type.declaredWithStruct)
7941 exp.byReference = true;
7943 //TESTING COMMENTING THIS OUT IN FAVOR OF ApplyAnyObjectLogic
7944 /*if(type && _class && (type.classObjectType == typedObject || type.classObjectType == anyObject) &&
7945 ((_class.type == unitClass || _class.type == enumClass || _class.type == bitClass) ||
7946 (type.byReference && (_class.type == normalClass || _class.type == noHeadClass))))
7948 Identifier id = exp.identifier;
7949 exp.type = bracketsExp;
7950 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(id)));
7954 if(symbol.isIterator)
7956 if(symbol.isIterator == 3)
7958 exp.type = bracketsExp;
7959 exp.list = MkListOne(MkExpOp(null, '*', MkExpIdentifier(exp.identifier)));
7960 ((Expression)exp.list->first).op.exp2.expType = exp.expType;
7962 ProcessExpressionType(exp);
7964 else if(symbol.isIterator != 4)
7966 exp.type = memberExp;
7967 exp.member.exp = MkExpIdentifier(exp.identifier);
7968 exp.member.exp.expType = exp.expType;
7969 /*if(symbol.isIterator == 6)
7970 exp.member.member = MkIdentifier("key");
7972 exp.member.member = MkIdentifier("data");
7974 ProcessExpressionType(exp);
7981 DefinedExpression definedExp = null;
7982 if(thisNameSpace && !(id._class && !id._class.name))
7985 strcpy(name, thisNameSpace);
7987 strcat(name, id.string);
7988 definedExp = eSystem_FindDefine(privateModule, name);
7991 definedExp = eSystem_FindDefine(privateModule, id.string);
7995 for(c = 0; c<definedExpStackPos; c++)
7996 if(definedExpStack[c] == definedExp)
7998 if(c == definedExpStackPos && c < sizeof(definedExpStack) / sizeof(void *))
8000 Location backupYylloc = yylloc;
8001 File backInput = fileInput;
8002 definedExpStack[definedExpStackPos++] = definedExp;
8004 fileInput = TempFile { };
8005 fileInput.Write(definedExp.value, 1, strlen(definedExp.value));
8006 fileInput.Seek(0, start);
8009 parsedExpression = null;
8011 expression_yyparse();
8014 fileInput = backInput;
8016 yylloc = backupYylloc;
8018 if(parsedExpression)
8021 exp.type = bracketsExp;
8022 exp.list = MkListOne(parsedExpression);
8023 ApplyLocation(parsedExpression, yylloc);
8024 ProcessExpressionType(exp);
8025 definedExpStackPos--;
8028 definedExpStackPos--;
8034 Compiler_Error($"Recursion in defined expression %s\n", id.string);
8040 GlobalData data = null;
8041 if(thisNameSpace && !(id._class && !id._class.name))
8044 strcpy(name, thisNameSpace);
8046 strcat(name, id.string);
8047 data = FindGlobalData(name);
8050 data = FindGlobalData(id.string);
8053 DeclareGlobalData(data);
8054 exp.expType = data.dataType;
8055 if(data.dataType) data.dataType.refCount++;
8058 id.string = CopyString(data.fullName);
8059 FreeSpecifier(id._class);
8066 GlobalFunction function = null;
8067 if(thisNameSpace && !(id._class && !id._class.name))
8070 strcpy(name, thisNameSpace);
8072 strcat(name, id.string);
8073 function = eSystem_FindFunction(privateModule, name);
8076 function = eSystem_FindFunction(privateModule, id.string);
8081 id.string = CopyString(function.name);
8084 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
8085 strcpy(name, "__ecereFunction_");
8086 FullClassNameCat(name, id.string, false); // Why is this using FullClassNameCat ?
8087 if(DeclareFunction(function, name))
8090 id.string = CopyString(name);
8092 exp.expType = function.dataType;
8093 if(function.dataType) function.dataType.refCount++;
8095 FreeSpecifier(id._class);
8112 if(!exp.instance._class)
8114 if(exp.destType && exp.destType.kind == classType && exp.destType._class)
8116 exp.instance._class = MkSpecifierName(exp.destType._class.string);
8120 //classSym = FindClass(exp.instance._class.fullName);
8121 //_class = classSym ? classSym.registered : null;
8123 ProcessInstantiationType(exp.instance);
8125 exp.isConstant = exp.instance.isConstant;
8128 if(_class.type == unitClass && _class.base.type != systemClass)
8131 Type destType = exp.destType;
8133 exp.destType = MkClassType(_class.base.fullName);
8134 exp.expType = MkClassType(_class.fullName);
8135 CheckExpressionType(exp, exp.destType, true);
8137 exp.destType = destType;
8139 exp.expType = MkClassType(_class.fullName);
8142 if(exp.instance._class)
8144 exp.expType = MkClassType(exp.instance._class.name);
8145 /*if(exp.expType._class && exp.expType._class.registered &&
8146 (exp.expType._class.registered.type == normalClass || exp.expType._class.registered.type == noHeadClass))
8147 exp.expType.byReference = true;*/
8155 char * constant = exp.constant;
8163 if(constant[0] == '\'')
8165 if((int)((byte *)constant)[1] > 127)
8168 unichar ch = UTF8GetChar(constant + 1, &nb);
8169 if(nb < 2) ch = constant[1];
8171 exp.constant = PrintUInt(ch);
8172 // type.kind = (ch > 0xFFFF) ? intType : shortType;
8173 type.kind = classType; //(ch > 0xFFFF) ? intType : shortType;
8174 type._class = FindClass("unichar");
8176 type.isSigned = false;
8180 type.kind = charType;
8181 type.isSigned = true;
8186 char * dot = strchr(constant, '.');
8187 bool isHex = (constant[0] == '0' && (constant[1] == 'x' || constant[1] == 'X'));
8191 exponent = strchr(constant, 'p');
8192 if(!exponent) exponent = strchr(constant, 'P');
8196 exponent = strchr(constant, 'e');
8197 if(!exponent) exponent = strchr(constant, 'E');
8202 if(strchr(constant, 'f') || strchr(constant, 'F'))
8203 type.kind = floatType;
8205 type.kind = doubleType;
8206 type.isSigned = true;
8210 bool isSigned = constant[0] == '-';
8212 int64 i64 = strtoll(constant, &endP, 0);
8213 uint64 ui64 = strtoull(constant, &endP, 0);
8214 bool is64Bit = endP && (!strcmp(endP, "LL") || !strcmp(endP, "ll"));
8227 if(ui64 <= MAXINT64 && (constant[0] != '0' || !constant[1]))
8231 else if(constant[0] != '0' || !constant[1])
8234 type.kind = is64Bit ? int64Type : intType;
8235 type.isSigned = isSigned;
8238 exp.isConstant = true;
8239 if(exp.destType && exp.destType.kind == doubleType)
8240 type.kind = doubleType;
8241 else if(exp.destType && exp.destType.kind == floatType)
8242 type.kind = floatType;
8243 else if(exp.destType && exp.destType.kind == int64Type)
8244 type.kind = int64Type;
8250 exp.isConstant = true; // Why wasn't this constant?
8258 kind = exp.wideString ? shortType : charType;
8260 isSigned = exp.wideString ? false : true;
8267 ProcessExpressionType(exp._new.size);
8272 type = ProcessType(exp._new.typeName.qualifiers, exp._new.typeName.declarator);
8274 DeclareType(exp.expType.type, false, false);
8278 ProcessExpressionType(exp._renew.size);
8279 ProcessExpressionType(exp._renew.exp);
8284 type = ProcessType(exp._renew.typeName.qualifiers, exp._renew.typeName.declarator);
8286 DeclareType(exp.expType.type, false, false);
8290 bool assign = false, boolResult = false, boolOps = false;
8291 Type type1 = null, type2 = null;
8292 bool useDestType = false, useSideType = false;
8293 Location oldyylloc = yylloc;
8294 bool useSideUnit = false;
8295 Class destClass = (exp.destType && exp.destType.kind == classType && exp.destType._class) ? exp.destType._class.registered : null;
8297 // Dummy type to prevent ProcessExpression of operands to say unresolved identifiers yet
8306 // Assignment Operators
8320 // boolean Operators
8322 // Expect boolean operators
8324 //boolResult = true;
8328 // Expect boolean operands
8339 // Gives boolean result
8371 // For & operator, useDestType nicely ensures the result will fit in a bool (TODO: Fix for generic enum)
8377 /*// Implement speed etc.
8383 if(exp.op.op == '&')
8385 // Added this here earlier for Iterator address as key
8386 if(!exp.op.exp1 && exp.op.exp2 && exp.op.exp2.type == identifierExp && exp.op.exp2.identifier)
8388 Identifier id = exp.op.exp2.identifier;
8389 Symbol symbol = FindSymbol(id.string, curContext, topContext, false, id._class && id._class.name == null);
8390 if(symbol && symbol.isIterator == 2)
8392 exp.type = memberExp;
8393 exp.member.exp = exp.op.exp2;
8394 exp.member.member = MkIdentifier("key");
8396 exp.op.exp2.expType = symbol.type;
8397 symbol.type.refCount++;
8398 ProcessExpressionType(exp);
8402 // exp.op.exp2.usage.usageRef = true;
8406 //dummy.kind = TypeDummy;
8409 // Added this check here to use the dest type only for units derived from the base unit
8410 // So that untyped units will use the side unit as opposed to the untyped destination unit
8411 // This fixes (#771) sin(Degrees { 5 } + 5) to be equivalent to sin(Degrees { 10 }), since sin expects a generic Angle
8412 if(exp.op.exp2 && useSideUnit && useDestType && destClass && destClass.type == unitClass && destClass.base.type != unitClass)
8413 useDestType = false;
8415 if(destClass && useDestType &&
8416 ((destClass.type == unitClass && useSideUnit) || destClass.type == enumClass || destClass.type == bitClass))
8418 //(exp.destType._class.registered.type == unitClass || exp.destType._class.registered.type == enumClass) && useDestType)
8420 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8421 exp.op.exp1.destType = exp.destType;
8422 exp.op.exp1.opDestType = true;
8424 exp.destType.refCount++;
8428 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8429 exp.op.exp1.destType = dummy;
8433 // TESTING THIS HERE...
8434 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count++;
8435 ProcessExpressionType(exp.op.exp1);
8436 if(exp.op.exp1.destType && exp.op.op != '=') exp.op.exp1.destType.count--;
8438 exp.op.exp1.opDestType = false;
8440 // Fix for unit and ++ / --
8441 if(!exp.op.exp2 && (exp.op.op == INC_OP || exp.op.op == DEC_OP) && exp.op.exp1.expType && exp.op.exp1.expType.kind == classType &&
8442 exp.op.exp1.expType._class && exp.op.exp1.expType._class.registered && exp.op.exp1.expType._class.registered.type == unitClass)
8444 exp.op.exp2 = MkExpConstant("1");
8445 exp.op.op = exp.op.op == INC_OP ? ADD_ASSIGN : SUB_ASSIGN;
8449 if(exp.op.exp1.destType == dummy)
8452 exp.op.exp1.destType = null;
8454 type1 = exp.op.exp1.expType;
8459 char expString[10240];
8460 expString[0] = '\0';
8461 if(exp.op.exp2.type == instanceExp && !exp.op.exp2.instance._class)
8465 exp.op.exp2.destType = exp.op.exp1.expType;
8466 if(exp.op.exp1.expType)
8467 exp.op.exp1.expType.refCount++;
8471 exp.op.exp2.destType = exp.destType;
8472 if(!exp.op.exp1 || exp.op.op != '&')
8473 exp.op.exp2.opDestType = true;
8475 exp.destType.refCount++;
8478 if(type1) type1.refCount++;
8479 exp.expType = type1;
8484 PrintExpression(exp.op.exp2, expString);
8486 if(type1 && type1.kind == pointerType)
8488 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 ||
8489 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN)
8490 Compiler_Error($"operator %s illegal on pointer\n", exp.op.op);
8491 else if(exp.op.op == '=')
8493 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8494 exp.op.exp2.destType = type1;
8501 // Don't convert to the type for those... (e.g.: Degrees a; a /= 2;)
8502 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/* ||
8503 exp.op.op == AND_ASSIGN || exp.op.op == OR_ASSIGN*/);
8506 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8507 exp.op.exp2.destType = type1;
8512 if(type1) type1.refCount++;
8513 exp.expType = type1;
8515 else if(destClass &&
8516 ((destClass.type == unitClass && useDestType && useSideUnit) ||
8517 (destClass.type == enumClass && useDestType)))
8519 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8520 exp.op.exp2.destType = exp.destType;
8521 if(exp.op.op != '&')
8522 exp.op.exp2.opDestType = true;
8524 exp.destType.refCount++;
8528 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8529 exp.op.exp2.destType = dummy;
8533 // TESTING THIS HERE... (DANGEROUS)
8534 if(type1 && boolResult && useSideType && type1.kind == classType && type1._class && type1._class.registered &&
8535 (type1._class.registered.type == bitClass || type1._class.registered.type == enumClass))
8537 FreeType(exp.op.exp2.destType);
8538 exp.op.exp2.destType = type1;
8541 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count++;
8542 // Cannot lose the cast on a sizeof
8543 if(exp.op.op == SIZEOF)
8545 Expression e = exp.op.exp2;
8546 while((e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp) && e.list)
8548 if(e.type == bracketsExp || e.type == extensionExpressionExp || e.type == extensionCompoundExp)
8550 if(e.type == extensionCompoundExp)
8551 e = ((Statement)e.compound.compound.statements->last).expressions->last;
8556 if(e.type == castExp && e.cast.exp)
8557 e.cast.exp.needCast = true;
8559 ProcessExpressionType(exp.op.exp2);
8560 exp.op.exp2.opDestType = false;
8561 if(exp.op.exp2.destType && exp.op.op != '=') exp.op.exp2.destType.count--;
8563 if(assign && type1 && type1.kind == pointerType && exp.op.exp2.expType)
8565 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)
8567 if(exp.op.op != '=' && type1.type.kind == voidType)
8568 Compiler_Error($"void *: unknown size\n");
8570 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||
8571 (type1.type.kind == voidType && exp.op.exp2.expType.kind == classType && exp.op.exp2.expType._class.registered &&
8572 (exp.op.exp2.expType._class.registered.type == normalClass ||
8573 exp.op.exp2.expType._class.registered.type == structClass ||
8574 exp.op.exp2.expType._class.registered.type == noHeadClass)))
8576 if(exp.op.op == ADD_ASSIGN)
8577 Compiler_Error($"cannot add two pointers\n");
8579 else if((exp.op.exp2.expType.kind == classType && type1.kind == pointerType && type1.type.kind == classType &&
8580 type1.type._class == exp.op.exp2.expType._class && exp.op.exp2.expType._class.registered && exp.op.exp2.expType._class.registered.type == structClass))
8582 if(exp.op.op == ADD_ASSIGN)
8583 Compiler_Error($"cannot add two pointers\n");
8587 char type1String[1024];
8588 char type2String[1024];
8589 type1String[0] = '\0';
8590 type2String[0] = '\0';
8592 PrintType(exp.op.exp2.expType, type1String, false, true);
8593 PrintType(type1, type2String, false, true);
8594 ChangeCh(expString, '\n', ' ');
8595 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1String, type2String);
8599 if(exp.op.exp2.destType == dummy)
8602 exp.op.exp2.destType = null;
8605 if(exp.op.op == '-' && !exp.op.exp1 && exp.op.exp2.expType && !exp.op.exp2.expType.isSigned)
8609 CopyTypeInto(type2, exp.op.exp2.expType);
8610 type2.isSigned = true;
8612 else if(exp.op.op == '~' && !exp.op.exp1 && exp.op.exp2.expType && (!exp.op.exp2.expType.isSigned || exp.op.exp2.expType.kind != intType))
8614 type2 = { kind = intType };
8616 type2.isSigned = true;
8620 type2 = exp.op.exp2.expType;
8621 if(type2) type2.refCount++;
8625 dummy.kind = voidType;
8627 if(exp.op.op == SIZEOF)
8634 exp.isConstant = true;
8636 // Get type of dereferenced pointer
8637 else if(exp.op.op == '*' && !exp.op.exp1)
8639 exp.expType = Dereference(type2);
8640 if(type2 && type2.kind == classType)
8641 notByReference = true;
8643 else if(exp.op.op == '&' && !exp.op.exp1)
8644 exp.expType = Reference(type2);
8651 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8652 exp.op.exp1.destType = MkClassType("bool");
8653 exp.op.exp1.destType.truth = true;
8654 if(!exp.op.exp1.expType)
8655 ProcessExpressionType(exp.op.exp1);
8657 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8658 FreeType(exp.op.exp1.expType);
8659 exp.op.exp1.expType = MkClassType("bool");
8660 exp.op.exp1.expType.truth = true;
8664 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8665 exp.op.exp2.destType = MkClassType("bool");
8666 exp.op.exp2.destType.truth = true;
8667 if(!exp.op.exp2.expType)
8668 ProcessExpressionType(exp.op.exp2);
8670 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8671 FreeType(exp.op.exp2.expType);
8672 exp.op.exp2.expType = MkClassType("bool");
8673 exp.op.exp2.expType.truth = true;
8676 else if(exp.op.exp1 && exp.op.exp2 &&
8679 ((!type1 || type1.kind != classType || type1._class.registered.type != unitClass) &&
8680 (!type2 || type2.kind != classType || type2._class.registered.type != unitClass)))*/) ||
8681 ((!type1 || type1.kind != classType || !strcmp(type1._class.string, "String")) &&
8682 (!type2 || type2.kind != classType || !strcmp(type2._class.string, "String")))))
8684 if(type1 && type2 &&
8685 // If either both are class or both are not class
8686 ((type1.kind == classType && type1._class && strcmp(type1._class.string, "String")) == (type2.kind == classType && type2._class && strcmp(type2._class.string, "String"))))
8688 // Added this check for enum subtraction to result in an int type:
8689 if(exp.op.op == '-' &&
8690 ((type1.kind == classType && type1._class.registered && type1._class.registered.type == enumClass) ||
8691 (type2.kind == classType && type2._class.registered && type2._class.registered.type == enumClass)) )
8694 if(!type1._class.registered.dataType)
8695 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8696 if(!type2._class.registered.dataType)
8697 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8699 intType = ProcessTypeString(
8700 (type1._class.registered.dataType.kind == int64Type || type2._class.registered.dataType.kind == int64Type) ? "int64" : "int", false);
8702 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8703 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8704 exp.op.exp1.destType = intType;
8705 exp.op.exp2.destType = intType;
8710 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8711 exp.op.exp2.destType = type1;
8713 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8714 exp.op.exp1.destType = type2;
8718 // Warning here for adding Radians + Degrees with no destination type
8719 if(!boolResult && type1.kind == classType && (!exp.destType || exp.destType.kind != classType) &&
8720 type1._class.registered && type1._class.registered.type == unitClass &&
8721 type2._class.registered && type2._class.registered.type == unitClass &&
8722 type1._class.registered != type2._class.registered)
8723 Compiler_Warning($"operating on %s and %s with an untyped result, assuming %s\n",
8724 type1._class.string, type2._class.string, type1._class.string);
8726 if(type1.kind == pointerType && type1.type.kind == templateType && type2.kind != pointerType)
8728 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8731 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8733 exp.op.exp1 = MkExpBrackets(MkListOne(MkExpCast(
8734 MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)),
8737 ProcessExpressionType(exp.op.exp1);
8739 if(type2.kind != pointerType)
8741 ProcessExpressionType(classExp);
8743 exp.op.exp2 = MkExpBrackets(MkListOne(MkExpOp(exp.op.exp2, '*', MkExpMember(classExp, MkIdentifier("typeSize")) )));
8745 if(!exp.op.exp2.expType)
8749 type2 = exp.op.exp2.expType = ProcessTypeString("int", false);
8753 ProcessExpressionType(exp.op.exp2);
8758 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)))
8760 if(type1.kind != classType && type1.type.kind == voidType)
8761 Compiler_Error($"void *: unknown size\n");
8762 exp.expType = type1;
8763 if(type1) type1.refCount++;
8765 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)))
8767 if(type2.kind != classType && type2.type.kind == voidType)
8768 Compiler_Error($"void *: unknown size\n");
8769 exp.expType = type2;
8770 if(type2) type2.refCount++;
8772 else if((type1.kind == pointerType && type2.kind != pointerType && type2.kind != arrayType && type2.kind != functionType && type2.kind != methodType && type2.kind != classType && type2.kind != subClassType) ||
8773 (type2.kind == pointerType && type1.kind != pointerType && type1.kind != arrayType && type1.kind != functionType && type1.kind != methodType && type1.kind != classType && type1.kind != subClassType))
8775 Compiler_Warning($"different levels of indirection\n");
8779 bool success = false;
8780 if(type1.kind == pointerType && type2.kind == pointerType)
8782 if(exp.op.op == '+')
8783 Compiler_Error($"cannot add two pointers\n");
8784 else if(exp.op.op == '-')
8786 // Pointer Subtraction gives integer
8787 if(MatchTypes(type1.type, type2.type, null, null, null, false, false, false, false, false))
8796 if(type1.type.kind == templateType)
8798 Expression argExp = GetTemplateArgExp(type1.type.templateParameter, thisClass, true);
8801 Expression classExp = MkExpMember(argExp, MkIdentifier("dataTypeClass"));
8803 ProcessExpressionType(classExp);
8805 exp.type = bracketsExp;
8806 exp.list = MkListOne(MkExpOp(
8807 MkExpBrackets(MkListOne(MkExpOp(
8808 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp1)))
8810 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpBrackets(MkListOne(exp.op.exp2)))))), '/',
8811 MkExpMember(classExp, MkIdentifier("typeSize"))));
8813 ProcessExpressionType(((Expression)exp.list->first).op.exp2);
8822 if(!success && exp.op.exp1.type == constantExp)
8824 // If first expression is constant, try to match that first
8825 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8827 if(exp.expType) FreeType(exp.expType);
8828 exp.expType = exp.op.exp1.destType;
8829 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8832 else if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8834 if(exp.expType) FreeType(exp.expType);
8835 exp.expType = exp.op.exp2.destType;
8836 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8842 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
8844 if(exp.expType) FreeType(exp.expType);
8845 exp.expType = exp.op.exp2.destType;
8846 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
8849 else if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
8851 if(exp.expType) FreeType(exp.expType);
8852 exp.expType = exp.op.exp1.destType;
8853 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
8859 char expString1[10240];
8860 char expString2[10240];
8863 expString1[0] = '\0';
8864 expString2[0] = '\0';
8869 PrintExpression(exp.op.exp1, expString1);
8870 ChangeCh(expString1, '\n', ' ');
8871 PrintExpression(exp.op.exp2, expString2);
8872 ChangeCh(expString2, '\n', ' ');
8873 PrintType(exp.op.exp1.expType, type1, false, true);
8874 PrintType(exp.op.exp2.expType, type2, false, true);
8877 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1, expString2, type2);
8881 // ADDED THESE TWO FROM OUTSIDE useSideType CHECK
8882 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type2 && type1 && type2.kind == classType && type1.kind != classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
8884 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8885 // Convert e.g. / 4 into / 4.0
8886 exp.op.exp1.destType = type2._class.registered.dataType;
8887 if(type2._class.registered.dataType)
8888 type2._class.registered.dataType.refCount++;
8889 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8890 exp.expType = type2;
8891 if(type2) type2.refCount++;
8893 else if(!boolResult && (!useSideUnit /*|| exp.destType*/) && type1 && type2 && type1.kind == classType && type2.kind != classType && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
8895 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8896 // Convert e.g. / 4 into / 4.0
8897 exp.op.exp2.destType = type1._class.registered.dataType;
8898 if(type1._class.registered.dataType)
8899 type1._class.registered.dataType.refCount++;
8900 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8901 exp.expType = type1;
8902 if(type1) type1.refCount++;
8908 if(!boolResult && useSideUnit && type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
8910 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
8912 if(!type1._class.registered.dataType)
8913 type1._class.registered.dataType = ProcessTypeString(type1._class.registered.dataTypeString, false);
8914 exp.op.exp2.destType = type1._class.registered.dataType;
8915 exp.op.exp2.destType.refCount++;
8917 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
8920 type2 = exp.op.exp2.destType;
8921 if(type2) type2.refCount++;
8923 exp.expType = type2;
8927 if(!boolResult && useSideUnit && type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
8929 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
8931 if(!type2._class.registered.dataType)
8932 type2._class.registered.dataType = ProcessTypeString(type2._class.registered.dataTypeString, false);
8933 exp.op.exp1.destType = type2._class.registered.dataType;
8934 exp.op.exp1.destType.refCount++;
8936 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
8937 type1 = exp.op.exp1.destType;
8938 exp.expType = type1;
8942 // TESTING THIS NEW CODE
8943 if(!boolResult || exp.op.op == '>' || exp.op.op == '<' || exp.op.op == GE_OP || exp.op.op == LE_OP)
8945 bool op1IsEnum = type1 && type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass;
8946 bool op2IsEnum = type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass;
8947 if(exp.op.op == '*' || exp.op.op == '/' || exp.op.op == '-' || exp.op.op == '|' || exp.op.op == '^')
8949 // Convert the enum to an int instead for these operators
8950 if(op1IsEnum && exp.op.exp2.expType)
8952 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8954 if(exp.expType) FreeType(exp.expType);
8955 exp.expType = exp.op.exp2.expType;
8956 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8960 else if(op2IsEnum && exp.op.exp1.expType)
8962 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8964 if(exp.expType) FreeType(exp.expType);
8965 exp.expType = exp.op.exp1.expType;
8966 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8973 if(op1IsEnum && exp.op.exp2.expType)
8975 if(CheckExpressionType(exp.op.exp1, exp.op.exp2.expType, false, false))
8977 if(exp.expType) FreeType(exp.expType);
8978 exp.expType = exp.op.exp1.expType;
8979 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
8983 else if(op2IsEnum && exp.op.exp1.expType)
8985 if(CheckExpressionType(exp.op.exp2, exp.op.exp1.expType, false, false))
8987 if(exp.expType) FreeType(exp.expType);
8988 exp.expType = exp.op.exp2.expType;
8989 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
8998 // 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
8999 if(type2 && type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == unitClass &&
9000 (type1.kind != classType || !type1._class || !type1._class.registered || type1._class.registered.type != unitClass))
9002 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9003 exp.op.exp1.destType = type2;
9006 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9008 if(exp.expType) FreeType(exp.expType);
9009 exp.expType = exp.op.exp1.destType;
9010 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9015 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9016 exp.op.exp2.destType = type1;
9020 // Maybe this was meant to be an enum...
9021 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9023 Type oldType = exp.op.exp2.expType;
9024 exp.op.exp2.expType = null;
9025 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false))
9028 exp.op.exp2.expType = oldType;
9033 // TESTING THIS HERE... LATEST ADDITION
9034 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9036 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9037 exp.op.exp2.destType = type2._class.registered.dataType;
9038 if(type2._class.registered.dataType)
9039 type2._class.registered.dataType.refCount++;
9040 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false);
9042 //exp.expType = type2._class.registered.dataType; //type2;
9043 //if(type2) type2.refCount++;
9046 // TESTING THIS HERE... LATEST ADDITION
9047 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9049 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9050 exp.op.exp1.destType = type1._class.registered.dataType;
9051 if(type1._class.registered.dataType)
9052 type1._class.registered.dataType.refCount++;
9053 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false);
9054 exp.expType = type1._class.registered.dataType; //type1;
9055 if(type1) type1.refCount++;
9059 if(CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false))
9061 if(exp.expType) FreeType(exp.expType);
9062 exp.expType = exp.op.exp2.destType;
9063 if(exp.op.exp2.destType) exp.op.exp2.destType.refCount++;
9065 else if(type1 && type2)
9067 char expString1[10240];
9068 char expString2[10240];
9069 char type1String[1024];
9070 char type2String[1024];
9071 expString1[0] = '\0';
9072 expString2[0] = '\0';
9073 type1String[0] = '\0';
9074 type2String[0] = '\0';
9077 PrintExpression(exp.op.exp1, expString1);
9078 ChangeCh(expString1, '\n', ' ');
9079 PrintExpression(exp.op.exp2, expString2);
9080 ChangeCh(expString2, '\n', ' ');
9081 PrintType(exp.op.exp1.expType, type1String, false, true);
9082 PrintType(exp.op.exp2.expType, type2String, false, true);
9085 Compiler_Warning($"incompatible expressions %s (%s) and %s (%s)\n", expString1, type1String, expString2, type2String);
9087 if(type1.kind == classType && type1._class && type1._class.registered && type1._class.registered.type == enumClass)
9089 exp.expType = exp.op.exp1.expType;
9090 if(exp.op.exp1.expType) exp.op.exp1.expType.refCount++;
9092 else if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9094 exp.expType = exp.op.exp2.expType;
9095 if(exp.op.exp2.expType) exp.op.exp2.expType.refCount++;
9103 // Maybe this was meant to be an enum...
9104 if(type2.kind == classType && type2._class && type2._class.registered && type2._class.registered.type == enumClass)
9106 Type oldType = exp.op.exp1.expType;
9107 exp.op.exp1.expType = null;
9108 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9111 exp.op.exp1.expType = oldType;
9114 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9115 exp.op.exp1.destType = type2;
9118 // TESTING THIS HERE... LATEST ADDITION
9119 if(type1 && type1.kind == classType && type1._class.registered && type1._class.registered.type == unitClass && type2 && type2.kind != classType)
9121 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9122 exp.op.exp1.destType = type1._class.registered.dataType;
9123 if(type1._class.registered.dataType)
9124 type1._class.registered.dataType.refCount++;
9127 // TESTING THIS HERE... LATEST ADDITION
9128 if(type2 && type2.kind == classType && type2._class.registered && type2._class.registered.type == unitClass && type1 && type1.kind != classType)
9130 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9131 exp.op.exp2.destType = type2._class.registered.dataType;
9132 if(type2._class.registered.dataType)
9133 type2._class.registered.dataType.refCount++;
9137 if(CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false))
9139 if(exp.expType) FreeType(exp.expType);
9140 exp.expType = exp.op.exp1.destType;
9141 if(exp.op.exp1.destType) exp.op.exp1.destType.refCount++;
9145 else if(type2 && (!type1 || (type2.kind == classType && type1.kind != classType)))
9147 if(type1 && type2._class && type2._class.registered && type2._class.registered.type == unitClass)
9149 if(exp.op.exp1.destType) FreeType(exp.op.exp1.destType);
9150 // Convert e.g. / 4 into / 4.0
9151 exp.op.exp1.destType = type2._class.registered.dataType;
9152 if(type2._class.registered.dataType)
9153 type2._class.registered.dataType.refCount++;
9154 CheckExpressionType(exp.op.exp1, exp.op.exp1.destType, false, false);
9156 if(exp.op.op == '!')
9158 exp.expType = MkClassType("bool");
9159 exp.expType.truth = true;
9163 exp.expType = type2;
9164 if(type2) type2.refCount++;
9167 else if(type1 && (!type2 || (type1.kind == classType && type2.kind != classType)))
9169 if(type2 && type1._class && type1._class.registered && type1._class.registered.type == unitClass)
9171 if(exp.op.exp2.destType) FreeType(exp.op.exp2.destType);
9172 // Convert e.g. / 4 into / 4.0
9173 exp.op.exp2.destType = type1._class.registered.dataType;
9174 if(type1._class.registered.dataType)
9175 type1._class.registered.dataType.refCount++;
9176 CheckExpressionType(exp.op.exp2, exp.op.exp2.destType, false, false);
9178 exp.expType = type1;
9179 if(type1) type1.refCount++;
9184 if(exp.op.exp1 && !exp.op.exp1.expType)
9186 char expString[10000];
9187 expString[0] = '\0';
9190 PrintExpression(exp.op.exp1, expString);
9191 ChangeCh(expString, '\n', ' ');
9194 Compiler_Error($"couldn't determine type of %s\n", expString);
9196 if(exp.op.exp2 && !exp.op.exp2.expType)
9198 char expString[10240];
9199 expString[0] = '\0';
9202 PrintExpression(exp.op.exp2, expString);
9203 ChangeCh(expString, '\n', ' ');
9206 Compiler_Error($"couldn't determine type of %s\n", expString);
9211 FreeType(exp.expType);
9212 exp.expType = MkClassType("bool");
9213 exp.expType.truth = true;
9216 if(exp.op.op != SIZEOF)
9217 exp.isConstant = (!exp.op.exp1 || exp.op.exp1.isConstant) &&
9218 (!exp.op.exp2 || exp.op.exp2.isConstant);
9220 if(exp.op.op == SIZEOF && exp.op.exp2.expType)
9222 DeclareType(exp.op.exp2.expType, false, false);
9225 if(exp.op.op == DELETE && exp.op.exp2 && exp.op.exp2.expType && exp.op.exp2.expType.specConst)
9226 Compiler_Warning($"deleting const qualified object\n");
9236 case extensionExpressionExp:
9239 exp.isConstant = true;
9240 for(e = exp.list->first; e; e = e.next)
9245 FreeType(e.destType);
9246 e.opDestType = exp.opDestType;
9247 e.destType = exp.destType;
9248 if(e.destType) { exp.destType.refCount++; e.destType.count++; inced = true; }
9250 ProcessExpressionType(e);
9252 exp.destType.count--;
9253 if(!exp.expType && !e.next)
9255 exp.expType = e.expType;
9256 if(e.expType) e.expType.refCount++;
9259 exp.isConstant = false;
9262 // In case a cast became a member...
9263 e = exp.list->first;
9264 if(!e.next && e.type == memberExp)
9266 // Preserve prev, next
9267 Expression next = exp.next, prev = exp.prev;
9270 FreeType(exp.expType);
9271 FreeType(exp.destType);
9281 ProcessExpressionType(exp);
9288 exp.isConstant = true;
9290 ProcessExpressionType(exp.index.exp);
9291 if(!exp.index.exp.isConstant)
9292 exp.isConstant = false;
9294 if(exp.index.exp.expType)
9296 Type source = exp.index.exp.expType;
9297 if(source.kind == classType && source._class && source._class.registered)
9299 Class _class = source._class.registered;
9300 Class c = _class.templateClass ? _class.templateClass : _class;
9301 if(_class != containerClass && eClass_IsDerived(c, containerClass) && _class.templateArgs)
9303 exp.expType = ProcessTypeString(_class.templateArgs[2].dataTypeString, false);
9305 if(exp.index.index && exp.index.index->last)
9307 Type type = ProcessTypeString(_class.templateArgs[1].dataTypeString, false);
9309 if(type.kind == classType) type.constant = true;
9310 else if(type.kind == pointerType)
9313 while(t.kind == pointerType) t = t.type;
9317 ((Expression)exp.index.index->last).destType = type;
9323 for(e = exp.index.index->first; e; e = e.next)
9325 if(!e.next && exp.index.exp.expType && exp.index.exp.expType.kind == arrayType && exp.index.exp.expType.enumClass)
9327 if(e.destType) FreeType(e.destType);
9328 e.destType = MkClassType(exp.index.exp.expType.enumClass.string);
9330 ProcessExpressionType(e);
9333 // Check if this type is int
9336 exp.isConstant = false;
9340 exp.expType = Dereference(exp.index.exp.expType);
9342 DeclareType(exp.expType, false, false);
9349 Type methodType = null;
9355 PrintExpression(exp.call.exp, name);
9356 if(exp.call.exp.expType && !exp.call.exp.expType.returnType)
9358 //exp.call.exp.expType = null;
9359 PrintExpression(exp.call.exp, name);
9362 if(exp.call.exp.type == identifierExp)
9364 Expression idExp = exp.call.exp;
9365 Identifier id = idExp.identifier;
9366 if(!strcmp(id.string, "__builtin_frame_address"))
9368 exp.expType = ProcessTypeString("void *", true);
9369 if(exp.call.arguments && exp.call.arguments->first)
9370 ProcessExpressionType(exp.call.arguments->first);
9373 else if(!strcmp(id.string, "__ENDIAN_PAD"))
9375 exp.expType = ProcessTypeString("int", true);
9376 if(exp.call.arguments && exp.call.arguments->first)
9377 ProcessExpressionType(exp.call.arguments->first);
9380 else if(!strcmp(id.string, "Max") ||
9381 !strcmp(id.string, "Min") ||
9382 !strcmp(id.string, "Sgn") ||
9383 !strcmp(id.string, "Abs"))
9385 Expression a = null;
9386 Expression b = null;
9387 Expression tempExp1 = null, tempExp2 = null;
9388 if((!strcmp(id.string, "Max") ||
9389 !strcmp(id.string, "Min")) && exp.call.arguments->count == 2)
9391 a = exp.call.arguments->first;
9392 b = exp.call.arguments->last;
9396 else if(exp.call.arguments->count == 1)
9398 a = exp.call.arguments->first;
9404 exp.call.arguments->Clear();
9405 idExp.identifier = null;
9407 FreeExpContents(exp);
9409 ProcessExpressionType(a);
9411 ProcessExpressionType(b);
9413 exp.type = bracketsExp;
9414 exp.list = MkList();
9416 if(a.expType && (!b || b.expType))
9418 if((!a.isConstant && a.type != identifierExp) || (b && !b.isConstant && b.type != identifierExp))
9420 // Use the simpleStruct name/ids for now...
9423 OldList * specs = MkList();
9424 OldList * decls = MkList();
9426 char temp1[1024], temp2[1024];
9428 GetTypeSpecs(a.expType, specs);
9430 if(a && !a.isConstant && a.type != identifierExp)
9432 sprintf(temp1, "__simpleStruct%d", curContext.simpleID++);
9433 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp1)), null));
9434 tempExp1 = QMkExpId(temp1);
9435 tempExp1.expType = a.expType;
9437 a.expType.refCount++;
9438 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp1), '=', a));
9440 if(b && !b.isConstant && b.type != identifierExp)
9442 sprintf(temp2, "__simpleStruct%d", curContext.simpleID++);
9443 ListAdd(decls, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(temp2)), null));
9444 tempExp2 = QMkExpId(temp2);
9445 tempExp2.expType = b.expType;
9447 b.expType.refCount++;
9448 ListAdd(exp.list, MkExpOp(CopyExpression(tempExp2), '=', b));
9451 decl = MkDeclaration(specs, decls);
9452 if(!curCompound.compound.declarations)
9453 curCompound.compound.declarations = MkList();
9454 curCompound.compound.declarations->Insert(null, decl);
9459 if(!strcmp(id.string, "Max") || !strcmp(id.string, "Min"))
9461 int op = (!strcmp(id.string, "Max")) ? '>' : '<';
9463 MkExpCondition(MkExpBrackets(MkListOne(
9464 MkExpOp(CopyExpression(tempExp1), op, CopyExpression(tempExp2)))),
9465 MkListOne(CopyExpression(tempExp1)), CopyExpression(tempExp2)));
9466 exp.expType = a.expType;
9468 a.expType.refCount++;
9470 else if(!strcmp(id.string, "Abs"))
9473 MkExpCondition(MkExpBrackets(MkListOne(
9474 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9475 MkListOne(MkExpOp(null, '-', CopyExpression(tempExp1))), CopyExpression(tempExp1)));
9476 exp.expType = a.expType;
9478 a.expType.refCount++;
9480 else if(!strcmp(id.string, "Sgn"))
9482 // ((!(a))?(0):(((a)<0)?(-1):(1)))
9484 MkExpCondition(MkExpBrackets(MkListOne(
9485 MkExpOp(null, '!', CopyExpression(tempExp1)))), MkListOne(MkExpConstant("0")),
9486 MkExpBrackets(MkListOne(MkExpCondition(MkExpBrackets(MkListOne(
9487 MkExpOp(CopyExpression(tempExp1), '<', MkExpConstant("0")))),
9488 MkListOne(MkExpConstant("-1")), MkExpConstant("1"))))));
9489 exp.expType = ProcessTypeString("int", false);
9492 FreeExpression(tempExp1);
9493 if(tempExp2) FreeExpression(tempExp2);
9507 if(!exp.call.exp.destType)
9509 exp.call.exp.destType = dummy;
9512 ProcessExpressionType(exp.call.exp);
9513 if(exp.call.exp.destType == dummy)
9516 exp.call.exp.destType = null;
9521 // Check argument types against parameter types
9522 functionType = exp.call.exp.expType;
9524 if(functionType && functionType.kind == TypeKind::methodType)
9526 methodType = functionType;
9527 functionType = methodType.method.dataType;
9529 //if(functionType.returnType && functionType.returnType.kind == thisClassType)
9530 // TOCHECK: Instead of doing this here could this be done per param?
9531 if(exp.call.exp.expType.usedClass)
9533 char typeString[1024];
9534 typeString[0] = '\0';
9536 Symbol back = functionType.thisClass;
9537 // Do not output class specifier here (thisclass was added to this)
9538 functionType.thisClass = null;
9539 PrintType(functionType, typeString, true, true);
9540 functionType.thisClass = back;
9542 if(strstr(typeString, "thisclass"))
9544 OldList * specs = MkList();
9547 Context context = SetupTemplatesContext(exp.call.exp.expType.usedClass);
9549 decl = SpecDeclFromString(typeString, specs, null);
9551 // SET THIS TO FALSE WHEN PROCESSING THISCLASS OUTSIDE THE CLASS
9552 if(thisClass != (exp.call.exp.expType.usedClass.templateClass ? exp.call.exp.expType.usedClass.templateClass :
9553 exp.call.exp.expType.usedClass))
9554 thisClassParams = false;
9556 ReplaceThisClassSpecifiers(specs, exp.call.exp.expType.usedClass);
9558 Class backupThisClass = thisClass;
9559 thisClass = exp.call.exp.expType.usedClass;
9560 ProcessDeclarator(decl);
9561 thisClass = backupThisClass;
9564 thisClassParams = true;
9566 functionType = ProcessType(specs, decl);
9567 functionType.refCount = 0;
9568 FinishTemplatesContext(context);
9570 // Mark parameters that were 'thisclass'
9573 for(p = functionType.params.first, op = methodType.method.dataType.params.first; p && op; p = p.next, op = op.next)
9574 p.wasThisClass = op.kind == thisClassType;
9578 FreeList(specs, FreeSpecifier);
9579 FreeDeclarator(decl);
9583 if(functionType && functionType.kind == pointerType && functionType.type && functionType.type.kind == TypeKind::functionType)
9585 Type type = functionType.type;
9586 if(!functionType.refCount)
9588 functionType.type = null;
9589 FreeType(functionType);
9591 //methodType = functionType;
9592 functionType = type;
9594 if(functionType && functionType.kind != TypeKind::functionType)
9596 Compiler_Error($"called object %s is not a function\n", name);
9598 else if(functionType)
9600 bool emptyParams = false, noParams = false;
9601 Expression e = exp.call.arguments ? exp.call.arguments->first : null;
9602 Type type = functionType.params.first;
9603 Expression memberExp = (exp.call.exp.type == ExpressionType::memberExp) ? exp.call.exp : null;
9605 Location oldyylloc = yylloc;
9607 if(!type) emptyParams = true;
9610 if(functionType.extraParam && e && functionType.thisClass)
9612 e.destType = MkClassType(functionType.thisClass.string);
9616 // WHY WAS THIS COMMENTED OUT ? Broke DisplaySystem::FontExtent(this ? displaySystem : null, font, text, len, width, height);
9617 // Fixed #141 by adding '&& !functionType.extraParam'
9618 if(!functionType.staticMethod && !functionType.extraParam)
9620 if(memberExp && memberExp.member.exp && memberExp.member.exp.expType && memberExp.member.exp.expType.kind == subClassType &&
9621 memberExp.member.exp.expType._class)
9623 type = MkClassType(memberExp.member.exp.expType._class.string);
9628 type = functionType.params.first;
9633 else if(!memberExp && (functionType.thisClass || (methodType && methodType.methodClass)))
9635 type = MkClassType(functionType.thisClass ? functionType.thisClass.string : (methodType ? methodType.methodClass.fullName : null));
9636 type.byReference = functionType.byReference;
9637 type.typedByReference = functionType.typedByReference;
9640 // Allow manually passing a class for typed object
9641 if(e.next && type.kind == classType && (functionType && functionType.thisClass) && functionType.classObjectType == typedObject)
9645 type = functionType.params.first;
9653 if(type && type.kind == voidType)
9656 if(!type.refCount) FreeType(type);
9660 for( ; e; e = e.next)
9662 if(!type && !emptyParams)
9665 if(methodType && methodType.methodClass)
9666 Compiler_Error($"too many arguments for method %s::%s (%d given, expected %d)\n",
9667 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments->count,
9668 noParams ? 0 : functionType.params.count);
9670 Compiler_Error($"too many arguments for function %s (%d given, expected %d)\n",
9671 name /*exp.call.exp.identifier.string*/, exp.call.arguments->count,
9672 noParams ? 0 : functionType.params.count);
9676 if(methodType && type && type.kind == templateType && type.templateParameter.type == TemplateParameterType::type)
9678 Type templatedType = null;
9679 Class _class = methodType.usedClass;
9680 ClassTemplateParameter curParam = null;
9682 if(_class && _class.templateArgs /*&& _class.templateClass*/)
9685 for(sClass = _class; sClass; sClass = sClass.base)
9687 if(sClass.templateClass) sClass = sClass.templateClass;
9689 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
9691 if(curParam.type == TemplateParameterType::type && !strcmp(type.templateParameter.identifier.string, curParam.name))
9694 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
9696 if(nextClass.templateClass) nextClass = nextClass.templateClass;
9697 id += nextClass.templateParams.count;
9706 if(curParam && _class.templateArgs[id].dataTypeString)
9708 bool constant = type.constant;
9709 ClassTemplateArgument arg = _class.templateArgs[id];
9711 Context context = SetupTemplatesContext(_class);
9714 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
9715 templatedType = ProcessTypeString(arg.dataTypeString, false);
9716 FinishTemplatesContext(context);
9719 if(templatedType.kind == classType && constant) templatedType.constant = true;
9720 else if(templatedType.kind == pointerType)
9722 Type t = templatedType.type;
9723 while(t.kind == pointerType) t = t.type;
9724 if(constant) t.constant = constant;
9727 e.destType = templatedType;
9730 templatedType.passAsTemplate = true;
9731 // templatedType.refCount++;
9737 if(type) type.refCount++;
9742 if(type && type.kind == ellipsisType && type.prev && type.prev.kind == classType && type.prev.classObjectType)
9744 e.destType = type.prev;
9745 e.destType.refCount++;
9750 if(type) type.refCount++;
9753 // Don't reach the end for the ellipsis
9754 if(type && type.kind != ellipsisType)
9756 Type next = type.next;
9757 if(!type.refCount) FreeType(type);
9762 if(type && type.kind != ellipsisType)
9764 if(methodType && methodType.methodClass)
9765 Compiler_Warning($"not enough arguments for method %s::%s (%d given, expected %d)\n",
9766 methodType.methodClass.fullName, methodType.method.name, exp.call.arguments ? exp.call.arguments->count : 0,
9767 functionType.params.count + extra);
9769 Compiler_Warning($"not enough arguments for function %s (%d given, expected %d)\n",
9770 name /*exp.call.exp.identifier.string*/, exp.call.arguments ? exp.call.arguments->count : 0,
9771 functionType.params.count + extra);
9774 if(type && !type.refCount) FreeType(type);
9781 kind = TypeKind::functionType;
9784 if(exp.call.exp.type == identifierExp)
9786 char * string = exp.call.exp.identifier.string;
9790 Location oldyylloc = yylloc;
9792 yylloc = exp.call.exp.identifier.loc;
9793 if(strstr(string, "__builtin_") == string)
9797 functionType.returnType = exp.destType;
9798 exp.destType.refCount++;
9802 Compiler_Warning($"%s undefined; assuming extern returning int\n", string);
9803 symbol = Symbol { string = CopyString(string), type = ProcessTypeString("int()", true) };
9804 globalContext.symbols.Add((BTNode)symbol);
9805 if(strstr(symbol.string, "::"))
9806 globalContext.hasNameSpace = true;
9811 else if(exp.call.exp.type == memberExp)
9813 /*Compiler_Warning($"%s undefined; assuming returning int\n",
9814 exp.call.exp.member.member.string);*/
9817 Compiler_Warning($"callable object undefined; extern assuming returning int\n");
9819 if(!functionType.returnType)
9821 functionType.returnType = Type
9828 if(functionType && functionType.kind == TypeKind::functionType)
9830 exp.expType = functionType.returnType;
9832 if(functionType.returnType)
9833 functionType.returnType.refCount++;
9835 if(!functionType.refCount)
9836 FreeType(functionType);
9839 if(exp.call.arguments)
9841 for(e = exp.call.arguments->first; e; e = e.next)
9842 ProcessExpressionType(e);
9849 Location oldyylloc = yylloc;
9851 Expression checkExp = exp.member.exp;
9854 if(checkExp.type == castExp)
9855 checkExp = checkExp.cast.exp;
9856 else if(checkExp.type == bracketsExp)
9857 checkExp = checkExp.list ? checkExp.list->first : null;
9862 thisPtr = (checkExp && checkExp.type == identifierExp && !strcmp(checkExp.identifier.string, "this"));
9863 exp.thisPtr = thisPtr;
9865 // DOING THIS LATER NOW...
9866 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
9868 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
9869 /* TODO: Name Space Fix ups
9870 if(!exp.member.member.classSym)
9871 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.fullName);
9875 ProcessExpressionType(exp.member.exp);
9876 if(exp.member.exp.expType && exp.member.exp.expType.kind == classType && exp.member.exp.expType._class &&
9877 exp.member.exp.expType._class.registered && exp.member.exp.expType._class.registered.type == normalClass)
9879 exp.isConstant = false;
9882 exp.isConstant = exp.member.exp.isConstant;
9883 type = exp.member.exp.expType;
9887 if(type && (type.kind == templateType))
9889 Class _class = thisClass ? thisClass : currentClass;
9890 ClassTemplateParameter param = null;
9893 for(param = _class.templateParams.first; param; param = param.next)
9895 if(param.type == identifier && exp.member.member && exp.member.member.string && !strcmp(param.name, exp.member.member.string))
9899 if(param && param.defaultArg.member)
9901 Expression argExp = GetTemplateArgExpByName(param.name, thisClass, TemplateParameterType::identifier);
9904 Expression expMember = exp.member.exp;
9906 OldList * specs = MkList();
9907 char thisClassTypeString[1024];
9909 FreeIdentifier(exp.member.member);
9911 ProcessExpressionType(argExp);
9914 char * colon = strstr(param.defaultArg.memberString, "::");
9917 memcpy(thisClassTypeString, param.defaultArg.memberString, colon - param.defaultArg.memberString);
9918 thisClassTypeString[colon - param.defaultArg.memberString] = '\0';
9921 strcpy(thisClassTypeString, _class.fullName);
9924 decl = SpecDeclFromString(param.defaultArg.member.dataTypeString, specs, null);
9926 exp.expType = ProcessType(specs, decl);
9927 if(exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.templateClass)
9929 Class expClass = exp.expType._class.registered;
9930 Class cClass = null;
9934 char templateString[1024];
9935 ClassTemplateParameter param;
9936 sprintf(templateString, "%s<", expClass.templateClass.fullName);
9937 for(cClass = expClass; cClass; cClass = cClass.base)
9940 for(param = cClass.templateParams.first; param; param = param.next)
9944 ClassTemplateArgument arg;
9945 for(sClass = cClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
9946 arg = expClass.templateArgs[id];
9948 for(sClass = _class /*expClass*/; sClass; sClass = sClass.base)
9950 ClassTemplateParameter cParam;
9951 //int p = numParams - sClass.templateParams.count;
9954 for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
9956 for(cParam = sClass.templateParams.first; cParam; cParam = cParam.next, p++)
9958 if(cParam.type == TemplateParameterType::type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
9960 if(_class.templateArgs && arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
9962 arg.dataTypeString = _class.templateArgs[p].dataTypeString;
9963 arg.dataTypeClass = _class.templateArgs[p].dataTypeClass;
9975 strcat(argument, arg.name.string);
9976 strcat(argument, " = ");
9982 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
9983 char expString[1024];
9984 OldList * specs = MkList();
9985 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
9987 char * string = PrintHexUInt64(arg.expression.ui64);
9988 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
9991 ProcessExpressionType(exp);
9992 ComputeExpression(exp);
9993 expString[0] = '\0';
9994 PrintExpression(exp, expString);
9995 strcat(argument, expString);
9997 FreeExpression(exp);
10002 strcat(argument, arg.member.name);
10005 case TemplateParameterType::type:
10007 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10009 if(!strcmp(arg.dataTypeString, "thisclass"))
10010 strcat(argument, thisClassTypeString);
10012 strcat(argument, arg.dataTypeString);
10019 if(paramCount) strcat(templateString, ", ");
10020 if(lastParam != p - 1)
10022 strcat(templateString, param.name);
10023 strcat(templateString, " = ");
10025 strcat(templateString, argument);
10034 int len = strlen(templateString);
10035 if(templateString[len-1] == '>') templateString[len++] = ' ';
10036 templateString[len++] = '>';
10037 templateString[len++] = '\0';
10040 Context context = SetupTemplatesContext(_class);
10041 FreeType(exp.expType);
10042 exp.expType = ProcessTypeString(templateString, false);
10043 FinishTemplatesContext(context);
10047 // *([expType] *)(((byte *)[exp.member.exp]) + [argExp].member.offset)
10048 exp.type = bracketsExp;
10049 exp.list = MkListOne(MkExpOp(null, '*',
10052 exp.op.exp1 = null;
10054 MkExpCast(MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl)), MkExpBrackets(MkListOne(MkExpOp(
10055 MkExpBrackets(MkListOne(
10056 MkExpCast(MkTypeName(MkListOne(MkSpecifierName("byte")), MkDeclaratorPointer(MkPointer(null, null), null)), expMember))),
10058 MkExpOp(MkExpMember(MkExpMember(argExp, MkIdentifier("member")), MkIdentifier("offset")),
10060 MkExpMember(MkExpMember(MkExpMember(CopyExpression(argExp), MkIdentifier("member")), MkIdentifier("_class")), MkIdentifier("offset")))))))
10065 else if(type.templateParameter && type.templateParameter.type == TemplateParameterType::type &&
10066 (type.templateParameter.dataType || type.templateParameter.dataTypeString))
10068 type = ProcessTemplateParameterType(type.templateParameter);
10071 // TODO: *** This seems to be where we should add method support for all basic types ***
10072 if(type && (type.kind == templateType));
10073 else if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType ||
10074 type.kind == int64Type || type.kind == shortType || type.kind == longType || type.kind == charType || type.kind == _BoolType ||
10075 type.kind == intPtrType || type.kind == intSizeType || type.kind == floatType || type.kind == doubleType ||
10076 (type.kind == pointerType && type.type.kind == charType)))
10078 Identifier id = exp.member.member;
10079 TypeKind typeKind = type.kind;
10080 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10081 if(typeKind == subClassType && exp.member.exp.type == classExp)
10083 _class = eSystem_FindClass(privateModule, "ecere::com::Class");
10084 typeKind = classType;
10089 if(typeKind == intType || typeKind == enumType)
10090 _class = eSystem_FindClass(privateModule, "int");
10093 if(type.kind == classType && type._class && type._class.registered)
10095 _class = type._class.registered;
10097 else if((type.kind == arrayType || type.kind == pointerType) && type.type && type.type.kind == charType)
10099 _class = FindClass("char *").registered;
10101 else if(type.kind == pointerType)
10103 _class = eSystem_FindClass(privateModule, "uintptr");
10104 FreeType(exp.expType);
10105 exp.expType = ProcessTypeString("uintptr", false);
10106 exp.byReference = true;
10110 char string[1024] = "";
10112 PrintTypeNoConst(type, string, false, true);
10113 classSym = FindClass(string);
10114 if(classSym) _class = classSym.registered;
10122 (exp.member.exp.type == identifierExp &&
10123 !strcmp(exp.member.exp.identifier.string, "this"));*/
10124 Property prop = null;
10125 Method method = null;
10126 DataMember member = null;
10127 Property revConvert = null;
10128 ClassProperty classProp = null;
10130 if(id && id._class && id._class.name && !strcmp(id._class.name, "property"))
10131 exp.member.memberType = propertyMember;
10133 if(id && id._class && type._class && !eClass_IsDerived(type._class.registered, _class))
10134 Compiler_Error($"invalid class specifier %s for object of class %s\n", _class.fullName, type._class.string);
10136 if(typeKind != subClassType)
10138 // Prioritize data members over properties for "this"
10139 if((exp.member.memberType == unresolvedMember && thisPtr) || exp.member.memberType == dataMember)
10141 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10142 if(member && member._class != (_class.templateClass ? _class.templateClass : _class) && exp.member.memberType != dataMember)
10144 prop = eClass_FindProperty(_class, id.string, privateModule);
10148 if(!member && !prop)
10149 prop = eClass_FindProperty(_class, id.string, privateModule);
10150 if((member && member._class == (_class.templateClass ? _class.templateClass : _class)) ||
10151 (prop && prop._class == (_class.templateClass ? _class.templateClass : _class)))
10152 exp.member.thisPtr = true;
10154 // Prioritize properties over data members otherwise
10157 bool useMemberForNonConst = false;
10158 // First look for Public Members (Unless class specifier is provided, which skips public priority)
10161 prop = eClass_FindProperty(_class, id.string, null);
10163 useMemberForNonConst = prop && exp.destType &&
10164 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10165 !strncmp(prop.dataTypeString, "const ", 6);
10167 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10168 member = eClass_FindDataMember(_class, id.string, null, null, null);
10171 if((!prop || useMemberForNonConst) && !member)
10173 method = useMemberForNonConst ? null : eClass_FindMethod(_class, id.string, null);
10176 prop = eClass_FindProperty(_class, id.string, privateModule);
10178 useMemberForNonConst |= prop && exp.destType &&
10179 ( (exp.destType.kind == classType && !exp.destType.constant) || ((exp.destType.kind == pointerType || exp.destType.kind == arrayType) && exp.destType.type && !exp.destType.type.constant) ) &&
10180 !strncmp(prop.dataTypeString, "const ", 6);
10182 if(useMemberForNonConst || !id._class || !id._class.name || strcmp(id._class.name, "property"))
10183 member = eClass_FindDataMember(_class, id.string, privateModule, null, null);
10189 if(useMemberForNonConst || (member._class != prop._class && !id._class && eClass_IsDerived(member._class, prop._class)))
10196 if(!prop && !member && !method) // NOTE: Recently added the !method here, causes private methods to unprioritized
10197 method = eClass_FindMethod(_class, id.string, privateModule);
10198 if(!prop && !member && !method)
10200 if(typeKind == subClassType)
10202 classProp = eClass_FindClassProperty(type._class.registered, exp.member.member.string);
10205 exp.member.memberType = classPropertyMember;
10206 exp.expType = ProcessTypeString(classProp.dataTypeString, false);
10210 // Assume this is a class_data member
10211 char structName[1024];
10212 Identifier id = exp.member.member;
10213 Expression classExp = exp.member.exp;
10216 FreeType(classExp.expType);
10217 classExp.expType = ProcessTypeString("ecere::com::Class", false);
10219 strcpy(structName, "__ecereClassData_");
10220 FullClassNameCat(structName, type._class.string, false);
10221 exp.type = pointerExp;
10222 exp.member.member = id;
10224 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10225 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10226 MkExpBrackets(MkListOne(MkExpOp(
10227 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10228 MkExpMember(classExp, MkIdentifier("data"))), '+',
10229 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(type._class.string)), null), MkIdentifier("offsetClass")))))
10234 ProcessExpressionType(exp);
10240 // Check for reverse conversion
10241 // (Convert in an instantiation later, so that we can use
10242 // deep properties system)
10243 Symbol classSym = FindClass(id.string);
10246 Class convertClass = classSym.registered;
10248 revConvert = eClass_FindProperty(convertClass, _class.fullName, privateModule);
10253 //if(!exp.member.exp.destType)
10254 if(exp.member.exp.destType)
10255 FreeType(exp.member.exp.destType);
10257 if(method && !method._class.symbol)
10258 method._class.symbol = FindClass(method._class.fullName);
10259 if(prop && !prop._class.symbol)
10260 prop._class.symbol = FindClass(prop._class.fullName);
10262 exp.member.exp.destType = Type
10266 _class = prop ? prop._class.symbol : method ? method._class.symbol : _class.symbol;
10267 // wasThisClass = type ? type.wasThisClass : false;
10273 exp.member.memberType = propertyMember;
10275 ProcessPropertyType(prop);
10276 exp.expType = prop.dataType;
10277 if(!strcmp(_class.base.fullName, "eda::Row") && !exp.expType.constant && !exp.destType)
10280 CopyTypeInto(type, exp.expType);
10282 type.constant = true;
10283 exp.expType = type;
10285 else if(prop.dataType)
10286 prop.dataType.refCount++;
10290 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10292 FreeExpContents(exp);
10293 exp.type = identifierExp;
10294 exp.identifier = MkIdentifier("class");
10295 ProcessExpressionType(exp);
10299 exp.member.memberType = dataMember;
10300 DeclareStruct(_class.fullName, false);
10301 if(!member.dataType)
10303 Context context = SetupTemplatesContext(_class);
10304 member.dataType = ProcessTypeString(member.dataTypeString, false);
10305 FinishTemplatesContext(context);
10307 exp.expType = member.dataType;
10308 if(member.dataType) member.dataType.refCount++;
10310 else if(revConvert)
10312 exp.member.memberType = reverseConversionMember;
10313 exp.expType = MkClassType(revConvert._class.fullName);
10321 exp.type = identifierExp;
10322 exp.identifier = exp.member.member;
10325 exp.member.memberType = methodMember;
10327 if(!method.dataType)
10328 ProcessMethodType(method);
10336 // Tricky spot here... To use instance versus class virtual table
10337 // Put it back to what it was... What did we break?
10339 // Had to put it back for overriding Main of Thread global instance
10341 //exp.expType.methodClass = _class;
10342 exp.expType.methodClass = (id && id._class) ? _class : null;
10344 // Need the actual class used for templated classes
10345 exp.expType.usedClass = _class;
10347 else if(!classProp)
10349 if(exp.member.exp.expType.classObjectType == typedObject && !strcmp(exp.member.member.string, "_class"))
10351 FreeExpContents(exp);
10352 exp.type = identifierExp;
10353 exp.identifier = MkIdentifier("class");
10354 FreeType(exp.expType);
10355 exp.expType = MkClassType("ecere::com::Class");
10358 yylloc = exp.member.member.loc;
10359 Compiler_Error($"couldn't find member %s in class %s\n", id.string, _class.fullName);
10361 eClass_AddDataMember(_class, id.string, "int", 0, 0, publicAccess);
10364 if(_class && /*(_class.templateClass || _class.templateArgs) && */exp.expType)
10368 tClass = type._class && type._class.registered ? type._class.registered : _class;
10369 while(tClass && !tClass.templateClass) tClass = tClass.base;
10371 if(tClass && exp.expType.kind == templateType && exp.expType.templateParameter.type == TemplateParameterType::type)
10374 ClassTemplateParameter curParam = null;
10377 for(sClass = tClass; sClass; sClass = sClass.base)
10380 if(sClass.templateClass) sClass = sClass.templateClass;
10381 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10383 if(curParam.type == TemplateParameterType::type && !strcmp(exp.expType.templateParameter.identifier.string, curParam.name))
10385 for(sClass = sClass.base; sClass; sClass = sClass.base)
10386 id += sClass.templateParams.count;
10391 if(curParam) break;
10394 if(curParam && tClass.templateArgs[id].dataTypeString)
10396 ClassTemplateArgument arg = tClass.templateArgs[id];
10397 Context context = SetupTemplatesContext(tClass);
10398 bool constant = exp.expType.constant;
10399 /*if(!arg.dataType)
10400 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10401 FreeType(exp.expType);
10403 exp.expType = ProcessTypeString(arg.dataTypeString, false);
10404 if(exp.expType.kind == classType && constant) exp.expType.constant = true;
10405 else if(exp.expType.kind == pointerType)
10407 Type t = exp.expType.type;
10408 while(t.kind == pointerType) t = t.type;
10409 if(constant) t.constant = constant;
10413 if(exp.expType.kind == thisClassType)
10415 FreeType(exp.expType);
10416 exp.expType = ReplaceThisClassType(_class);
10419 if(tClass.templateClass && (exp.expType.kind != templateType || (!exp.expType.templateParameter || (!exp.expType.templateParameter.dataTypeString && !exp.expType.templateParameter.dataType))))
10420 exp.expType.passAsTemplate = true;
10421 //exp.expType.refCount++;
10424 exp.destType = ProcessTypeString(arg.dataTypeString, false);
10425 if(exp.destType.kind == classType && constant) exp.destType.constant = true;
10426 else if(exp.destType.kind == pointerType)
10428 Type t = exp.destType.type;
10429 while(t.kind == pointerType) t = t.type;
10430 if(constant) t.constant = constant;
10433 //exp.destType.refCount++;
10435 if(exp.destType.kind == thisClassType)
10437 FreeType(exp.destType);
10438 exp.destType = ReplaceThisClassType(_class);
10442 FinishTemplatesContext(context);
10445 // TODO: MORE GENERIC SUPPORT FOR DEEPER TYPES
10446 else if(tClass && exp.expType.kind == pointerType && exp.expType.type && exp.expType.type.kind == templateType && exp.expType.type.templateParameter.type == TemplateParameterType::type)
10449 ClassTemplateParameter curParam = null;
10452 for(sClass = tClass; sClass; sClass = sClass.base)
10455 if(sClass.templateClass) sClass = sClass.templateClass;
10456 for(curParam = sClass.templateParams.first; curParam; curParam = curParam.next)
10458 if(curParam.type == TemplateParameterType::type &&
10459 !strcmp(exp.expType.type.templateParameter.identifier.string, curParam.name))
10461 for(sClass = sClass.base; sClass; sClass = sClass.base)
10462 id += sClass.templateParams.count;
10467 if(curParam) break;
10472 ClassTemplateArgument arg = tClass.templateArgs[id];
10473 Context context = SetupTemplatesContext(tClass);
10475 /*if(!arg.dataType)
10476 arg.dataType = ProcessTypeString(arg.dataTypeString, false);*/
10478 basicType = ProcessTypeString(arg.dataTypeString, false);
10481 if(basicType.kind == thisClassType)
10483 FreeType(basicType);
10484 basicType = ReplaceThisClassType(_class);
10487 /* DO WE REALLY WANT THIS HERE? IT SEEMS TO BE ONLY USED WITH Array::array which was causing bug 135
10488 if(tClass.templateClass)
10489 basicType.passAsTemplate = true;
10492 FreeType(exp.expType);
10494 exp.expType = Type { refCount = 1, kind = pointerType, type = basicType };
10495 //exp.expType.refCount++;
10498 exp.destType = exp.expType;
10499 exp.destType.refCount++;
10503 Expression newExp { };
10504 OldList * specs = MkList();
10506 decl = SpecDeclFromString(arg.dataTypeString, specs, null);
10508 if(exp.destType) exp.destType.refCount++;
10509 if(exp.expType) exp.expType.refCount++;
10510 exp.type = castExp;
10511 exp.cast.typeName = MkTypeName(specs, MkDeclaratorPointer(MkPointer(null, null), decl));
10512 exp.cast.exp = newExp;
10513 //FreeType(exp.expType);
10514 //exp.expType = null;
10515 //ProcessExpressionType(sourceExp);
10518 FinishTemplatesContext(context);
10521 else if(tClass && exp.expType.kind == classType && exp.expType._class && strchr(exp.expType._class.string, '<'))
10523 Class expClass = exp.expType._class.registered;
10526 Class cClass = null;
10528 int paramCount = 0;
10529 int lastParam = -1;
10530 char templateString[1024];
10531 ClassTemplateParameter param;
10532 sprintf(templateString, "%s<", expClass.templateClass.fullName);
10533 while(cClass != expClass)
10536 for(sClass = expClass; sClass && sClass.base != cClass; sClass = sClass.base);
10539 for(param = cClass.templateParams.first; param; param = param.next)
10541 Class cClassCur = null;
10543 ClassTemplateParameter paramCur = null;
10544 ClassTemplateArgument arg;
10545 while(cClassCur != tClass && !paramCur)
10548 for(sClassCur = tClass; sClassCur && sClassCur.base != cClassCur; sClassCur = sClassCur.base);
10549 cClassCur = sClassCur;
10551 for(paramCur = cClassCur.templateParams.first; paramCur; paramCur = paramCur.next)
10553 if(!strcmp(paramCur.name, param.name))
10561 if(paramCur && paramCur.type == TemplateParameterType::type)
10562 arg = tClass.templateArgs[cp];
10564 arg = expClass.templateArgs[p];
10567 char argument[256];
10568 argument[0] = '\0';
10571 strcat(argument, arg.name.string);
10572 strcat(argument, " = ");
10578 // THIS WHOLE THING IS A WILD GUESS... FIX IT UP
10579 char expString[1024];
10580 OldList * specs = MkList();
10581 Declarator decl = SpecDeclFromString(param.dataTypeString, specs, null);
10583 char * string = PrintHexUInt64(arg.expression.ui64);
10584 exp = MkExpCast(MkTypeName(specs, decl), MkExpConstant(string));
10587 ProcessExpressionType(exp);
10588 ComputeExpression(exp);
10589 expString[0] = '\0';
10590 PrintExpression(exp, expString);
10591 strcat(argument, expString);
10593 FreeExpression(exp);
10598 strcat(argument, arg.member.name);
10601 case TemplateParameterType::type:
10603 if(arg.dataTypeString && (!param.defaultArg.dataTypeString || strcmp(arg.dataTypeString, param.defaultArg.dataTypeString)))
10604 strcat(argument, arg.dataTypeString);
10610 if(paramCount) strcat(templateString, ", ");
10611 if(lastParam != p - 1)
10613 strcat(templateString, param.name);
10614 strcat(templateString, " = ");
10616 strcat(templateString, argument);
10625 int len = strlen(templateString);
10626 if(templateString[len-1] == '>') templateString[len++] = ' ';
10627 templateString[len++] = '>';
10628 templateString[len++] = '\0';
10631 FreeType(exp.expType);
10633 Context context = SetupTemplatesContext(tClass);
10634 exp.expType = ProcessTypeString(templateString, false);
10635 FinishTemplatesContext(context);
10642 Compiler_Error($"undefined class %s\n", (id && (!id._class || id._class.name))? (id.classSym ? id.classSym.string : (type._class ? type._class.string : null)) : "(null)");
10644 else if(type && (type.kind == structType || type.kind == unionType))
10646 Type memberType = exp.member.member ? FindMember(type, exp.member.member.string) : null;
10649 exp.expType = memberType;
10651 memberType.refCount++;
10656 char expString[10240];
10657 expString[0] = '\0';
10658 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
10659 Compiler_Error($"member operator on non-structure type expression %s\n", expString);
10662 if(exp.expType && exp.expType.kind == thisClassType && (!exp.destType || exp.destType.kind != thisClassType))
10664 if(type && (type.kind == classType || type.kind == subClassType || type.kind == intType || type.kind == enumType))
10666 Identifier id = exp.member.member;
10667 Class _class = (id && (!id._class || id._class.name))? ( id.classSym ? id.classSym.registered : (type._class ? type._class.registered : null)) : null;
10670 FreeType(exp.expType);
10671 exp.expType = ReplaceThisClassType(_class);
10675 yylloc = oldyylloc;
10678 // Convert x->y into (*x).y
10681 Type destType = exp.destType;
10683 // DOING THIS LATER NOW...
10684 if(exp.member.member && exp.member.member._class && exp.member.member._class.name)
10686 exp.member.member.classSym = exp.member.member._class.symbol; // FindClass(exp.member.member._class.name);
10687 /* TODO: Name Space Fix ups
10688 if(!exp.member.member.classSym)
10689 exp.member.member.nameSpace = eSystem_FindNameSpace(privateModule, exp.member.member._class.name);
10693 exp.member.exp = MkExpBrackets(MkListOne(MkExpOp(null, '*', exp.member.exp)));
10694 exp.type = memberExp;
10697 ProcessExpressionType(exp);
10704 //ComputeExpression(exp);
10706 Symbol classSym = exp._class.symbol; // FindClass(exp._class.name);
10707 if(classSym && classSym.registered)
10709 if(classSym.registered.type == noHeadClass)
10713 DeclareStruct(classSym.string, false);
10714 FreeSpecifier(exp._class);
10715 exp.type = typeSizeExp;
10716 FullClassNameCat(name, classSym.string, false);
10717 exp.typeName = MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(name), null)), null);
10721 if(classSym.registered.fixed)
10723 FreeSpecifier(exp._class);
10724 exp.constant = PrintUInt(classSym.registered.templateClass ? classSym.registered.templateClass.structSize : classSym.registered.structSize);
10725 exp.type = constantExp;
10729 char className[1024];
10730 strcpy(className, "__ecereClass_");
10731 FullClassNameCat(className, classSym.string, true);
10732 //MangleClassName(className);
10734 DeclareClass(classSym, className);
10736 FreeExpContents(exp);
10737 exp.type = pointerExp;
10738 exp.member.exp = MkExpIdentifier(MkIdentifier(className));
10739 exp.member.member = MkIdentifier("structSize");
10747 kind = intSizeType;
10749 // exp.isConstant = true;
10754 Type type = ProcessType(exp.typeName.qualifiers, exp.typeName.declarator);
10759 kind = intSizeType;
10761 exp.isConstant = true;
10763 DeclareType(type, false, false);
10769 Type type = ProcessType(exp.cast.typeName.qualifiers, exp.cast.typeName.declarator);
10771 FreeType(exp.cast.exp.destType);
10772 exp.cast.exp.destType = type;
10774 type.casted = true;
10775 ProcessExpressionType(exp.cast.exp);
10776 type.casted = false;
10778 exp.expType = type;
10781 // if(!NeedCast(exp.cast.exp.expType, exp.cast.exp.destType))
10782 if(!exp.cast.exp.needCast && !NeedCast(exp.cast.exp.expType, type))
10784 void * prev = exp.prev, * next = exp.next;
10785 Type expType = exp.cast.exp.destType;
10786 Expression castExp = exp.cast.exp;
10787 Type destType = exp.destType;
10789 if(expType) expType.refCount++;
10791 //FreeType(exp.destType);
10792 FreeType(exp.expType);
10793 FreeTypeName(exp.cast.typeName);
10796 FreeType(exp.expType);
10797 FreeType(exp.destType);
10799 exp.expType = expType;
10800 exp.destType = destType;
10810 exp.isConstant = exp.cast.exp.isConstant;
10815 case extensionInitializerExp:
10817 Type type = ProcessType(exp.initializer.typeName.qualifiers, exp.initializer.typeName.declarator);
10818 // We have yet to support this... ( { } initializers are currently processed inside ProcessDeclaration()'s initDeclaration case statement
10819 // ProcessInitializer(exp.initializer.initializer, type);
10820 exp.expType = type;
10825 Type type = ProcessType(exp.vaArg.typeName.qualifiers, exp.vaArg.typeName.declarator);
10826 ProcessExpressionType(exp.vaArg.exp);
10827 exp.expType = type;
10833 exp.isConstant = true;
10835 FreeType(exp.cond.cond.destType);
10836 exp.cond.cond.destType = MkClassType("bool");
10837 exp.cond.cond.destType.truth = true;
10838 ProcessExpressionType(exp.cond.cond);
10839 if(!exp.cond.cond.isConstant)
10840 exp.isConstant = false;
10841 for(e = exp.cond.exp->first; e; e = e.next)
10845 FreeType(e.destType);
10846 e.destType = exp.destType;
10847 if(e.destType) e.destType.refCount++;
10849 ProcessExpressionType(e);
10852 exp.expType = e.expType;
10853 if(e.expType) e.expType.refCount++;
10856 exp.isConstant = false;
10859 FreeType(exp.cond.elseExp.destType);
10860 // Added this check if we failed to find an expType
10861 // exp.cond.elseExp.destType = exp.expType ? exp.expType : exp.destType;
10864 exp.cond.elseExp.destType = exp.destType ? exp.destType : exp.expType;
10866 if(exp.cond.elseExp.destType)
10867 exp.cond.elseExp.destType.refCount++;
10868 ProcessExpressionType(exp.cond.elseExp);
10870 // FIXED THIS: Was done before calling process on elseExp
10871 if(!exp.cond.elseExp.isConstant)
10872 exp.isConstant = false;
10875 case extensionCompoundExp:
10877 if(exp.compound && exp.compound.compound.statements && exp.compound.compound.statements->last)
10879 Statement last = exp.compound.compound.statements->last;
10880 if(last.type == expressionStmt && last.expressions && last.expressions->last)
10882 ((Expression)last.expressions->last).destType = exp.destType;
10884 exp.destType.refCount++;
10886 ProcessStatement(exp.compound);
10887 exp.expType = (last.expressions && last.expressions->last) ? ((Expression)last.expressions->last).expType : null;
10889 exp.expType.refCount++;
10895 Specifier spec = exp._classExp.specifiers->first;
10896 if(spec && spec.type == nameSpecifier)
10898 exp.expType = MkClassType(spec.name);
10899 exp.expType.kind = subClassType;
10900 exp.byReference = true;
10904 exp.expType = MkClassType("ecere::com::Class");
10905 exp.byReference = true;
10911 Class _class = thisClass ? thisClass : currentClass;
10914 Identifier id = exp.classData.id;
10915 char structName[1024];
10916 Expression classExp;
10917 strcpy(structName, "__ecereClassData_");
10918 FullClassNameCat(structName, _class.fullName, false);
10919 exp.type = pointerExp;
10920 exp.member.member = id;
10921 if(curCompound && FindSymbol("this", curContext, curCompound.compound.context, false, false))
10922 classExp = MkExpMember(MkExpIdentifier(MkIdentifier("this")), MkIdentifier("_class"));
10924 classExp = MkExpIdentifier(MkIdentifier("class"));
10926 exp.member.exp = MkExpBrackets(MkListOne(MkExpCast(
10927 MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)),
10928 MkExpBrackets(MkListOne(MkExpOp(
10929 MkExpCast(MkTypeName(MkListOne(MkSpecifier(CHAR)), MkDeclaratorPointer(MkPointer(null,null), null)),
10930 MkExpMember(classExp, MkIdentifier("data"))), '+',
10931 MkExpMember(MkExpClass(MkListOne(MkSpecifierName(_class.fullName)), null), MkIdentifier("offsetClass")))))
10934 ProcessExpressionType(exp);
10942 const char * typeString = null;
10943 char typeStringBuf[1024];
10944 if(exp.destType && exp.destType.kind == classType && exp.destType._class && exp.destType._class.registered &&
10945 exp.destType._class.registered != containerClass && eClass_IsDerived(exp.destType._class.registered, containerClass))
10947 Class templateClass = exp.destType._class.registered;
10948 typeString = templateClass.templateArgs[2].dataTypeString;
10952 // Guess type from expressions in the array
10954 for(e = exp.list->first; e; e = e.next)
10956 ProcessExpressionType(e);
10959 if(!type) { type = e.expType; type.refCount++; }
10962 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
10963 if(!MatchTypeExpression(e, type, null, false, true))
10969 e = exp.list->first;
10970 ProcessExpressionType(e);
10973 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false))
10974 if(!MatchTypeExpression(e, type, null, false, true))
10976 FreeType(e.expType);
10987 FreeType(e.expType);
10994 typeStringBuf[0] = '\0';
10995 PrintTypeNoConst(type, typeStringBuf, false, true);
10996 typeString = typeStringBuf;
11004 (Container)& (struct BuiltInContainer)
11006 ._vTbl = class(BuiltInContainer)._vTbl,
11007 ._class = class(BuiltInContainer),
11009 .data = (int[]){ 1, 7, 3, 4, 5 },
11011 .type = class(int),
11014 char templateString[1024];
11015 OldList * initializers = MkList();
11016 OldList * structInitializers = MkList();
11017 OldList * specs = MkList();
11019 Declarator decl = SpecDeclFromString(typeString, specs, null);
11020 sprintf(templateString, "Container<%s>", typeString);
11025 type = ProcessTypeString(typeString, false);
11026 while((e = exp.list->first))
11028 exp.list->Remove(e);
11031 ProcessExpressionType(e);
11032 ListAdd(initializers, MkInitializerAssignment(e));
11038 DeclareStruct("ecere::com::BuiltInContainer", false);
11040 ListAdd(structInitializers, /*MkIdentifier("_vTbl")*/ MkInitializerAssignment(MkExpMember(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null), MkIdentifier("_vTbl"))));
11041 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11042 ListAdd(structInitializers, /*MkIdentifier("_class")*/ MkInitializerAssignment(MkExpClass(MkListOne(MkSpecifierName("BuiltInContainer")), null)));
11043 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11044 ListAdd(structInitializers, /*MkIdentifier("_refCount")*/MkInitializerAssignment(MkExpConstant("0")));
11045 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11046 ListAdd(structInitializers, /*MkIdentifier("data")*/ MkInitializerAssignment(MkExpExtensionInitializer(
11047 MkTypeName(specs, MkDeclaratorArray(decl, null)),
11048 MkInitializerList(initializers))));
11049 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11050 ListAdd(structInitializers, /*MkIdentifier("count")*/ MkInitializerAssignment({ type = constantExp, constant = PrintString(initializers->count) }));
11051 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11052 ListAdd(structInitializers, /*MkIdentifier("type")*/ MkInitializerAssignment(MkExpClass(CopyList(specs, CopySpecifier), CopyDeclarator(decl))));
11053 ProcessExpressionType(((Initializer)structInitializers->last).exp);
11054 exp.expType = ProcessTypeString(templateString, false);
11055 exp.type = bracketsExp;
11056 exp.list = MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName(templateString)), null),
11058 expExt = MkExpExtensionInitializer(MkTypeName(MkListOne(MkSpecifierName("BuiltInContainer")), null),
11059 MkInitializerList(structInitializers)))));
11060 ProcessExpressionType(expExt);
11064 exp.expType = ProcessTypeString("Container", false);
11065 Compiler_Error($"Couldn't determine type of array elements\n");
11071 if(exp.expType && exp.expType.kind == thisClassType && thisClass && (!exp.destType || exp.destType.kind != thisClassType))
11073 FreeType(exp.expType);
11074 exp.expType = ReplaceThisClassType(thisClass);
11077 // Resolve structures here
11078 if(exp.expType && (exp.expType.kind == structType || exp.expType.kind == unionType || exp.expType.kind == enumType) && !exp.expType.members.first && exp.expType.enumName)
11080 Symbol symbol = FindSymbol(exp.expType.enumName, curContext, globalContext, true, false);
11081 // TODO: Fix members reference...
11084 if(exp.expType.kind != enumType)
11087 String enumName = CopyString(exp.expType.enumName);
11089 // Fixed a memory leak on self-referencing C structs typedefs
11090 // by instantiating a new type rather than simply copying members
11091 // into exp.expType
11092 FreeType(exp.expType);
11093 exp.expType = Type { };
11094 exp.expType.kind = symbol.type.kind;
11095 exp.expType.refCount++;
11096 exp.expType.enumName = enumName;
11098 exp.expType.members = symbol.type.members;
11099 for(member = symbol.type.members.first; member; member = member.next)
11104 NamedLink64 member;
11105 for(member = symbol.type.members.first; member; member = member.next)
11107 NamedLink64 value { name = CopyString(member.name) };
11108 exp.expType.members.Add(value);
11115 if(exp.destType && (/*exp.destType.kind == voidType || */exp.destType.kind == dummyType) );
11116 else if(exp.destType && !exp.destType.keepCast)
11118 if(!exp.needTemplateCast && exp.expType && (exp.expType.kind == templateType || exp.expType.passAsTemplate)) // && exp.destType && !exp.destType.passAsTemplate)
11119 exp.needTemplateCast = 1;
11121 if(exp.destType.kind == voidType);
11122 else if(!CheckExpressionType(exp, exp.destType, false, !exp.destType.casted))
11124 if(!exp.destType.count || unresolved)
11129 if(exp.destType.kind != ellipsisType)
11135 char expString[10240];
11136 expString[0] = '\0';
11138 PrintType(exp.destType, type2, false, true);
11140 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11142 Compiler_Error($"unresolved identifier %s; expected %s\n", expString, type2);
11143 else if(exp.type != dummyExp)
11144 Compiler_Error($"couldn't determine type of %s; expected %s\n", expString, type2);
11149 char expString[10240] ;
11150 expString[0] = '\0';
11151 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11154 Compiler_Error($"unresolved identifier %s\n", expString);
11155 else if(exp.type != dummyExp)
11156 Compiler_Error($"couldn't determine type of %s\n", expString);
11167 PrintType(exp.expType, type1, false, true);
11168 PrintType(exp.destType, type2, false, true);
11171 //CheckExpressionType(exp, exp.destType, false);
11173 if(exp.destType.truth && exp.destType._class && exp.destType._class.registered && !strcmp(exp.destType._class.registered.name, "bool") &&
11174 exp.expType.kind != voidType && exp.expType.kind != structType && exp.expType.kind != unionType &&
11175 (exp.expType.kind != classType || exp.expType.classObjectType || (exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type != structClass)));
11178 char expString[10240];
11179 expString[0] = '\0';
11180 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11183 CheckExpressionType(exp, exp.destType, false, true);
11185 // Flex & Bison generate code that triggers this, so we ignore it for a quiet sdk build:
11186 if(!sourceFile || (!strstr(sourceFile, "src\\lexer.ec") && !strstr(sourceFile, "src/lexer.ec") &&
11187 !strstr(sourceFile, "src\\grammar.ec") && !strstr(sourceFile, "src/grammar.ec") &&
11188 !strstr(sourceFile, "src\\type.ec") && !strstr(sourceFile, "src/type.ec") &&
11189 !strstr(sourceFile, "src\\expression.ec") && !strstr(sourceFile, "src/expression.ec")))
11190 Compiler_Warning($"incompatible expression %s (%s); expected %s\n", expString, type1, type2);
11192 // TO CHECK: FORCING HERE TO HELP DEBUGGER
11193 FreeType(exp.expType);
11194 exp.destType.refCount++;
11195 exp.expType = exp.destType;
11200 // Cast function pointers to void * as eC already checked compatibility
11201 else if(exp.destType && exp.destType.kind == pointerType && exp.destType.type && exp.destType.type.kind == functionType &&
11202 exp.expType && (exp.expType.kind == functionType || exp.expType.kind == methodType))
11204 Expression nbExp = GetNonBracketsExp(exp);
11205 if(nbExp.type != castExp || !IsVoidPtrCast(nbExp.cast.typeName))
11207 Expression e = MoveExpContents(exp);
11208 exp.cast.exp = MkExpBrackets(MkListOne(e));
11209 exp.type = castExp;
11210 exp.cast.exp.destType = exp.destType;
11211 if(exp.destType) exp.destType.refCount++;
11212 exp.cast.typeName = MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null));
11216 else if(unresolved)
11218 if(exp.identifier._class && exp.identifier._class.name)
11219 Compiler_Error($"unresolved identifier %s::%s\n", exp.identifier._class.name, exp.identifier.string);
11220 else if(exp.identifier.string && exp.identifier.string[0])
11221 Compiler_Error($"unresolved identifier %s\n", exp.identifier.string);
11223 else if(!exp.expType && exp.type != dummyExp)
11225 char expString[10240];
11226 expString[0] = '\0';
11227 if(inCompiler) { PrintExpression(exp, expString); ChangeCh(expString, '\n', ' '); }
11228 Compiler_Error($"couldn't determine type of %s\n", expString);
11231 // Let's try to support any_object & typed_object here:
11233 ApplyAnyObjectLogic(exp);
11235 // Mark nohead classes as by reference, unless we're casting them to an integral type
11236 if(!notByReference && exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered &&
11237 exp.expType._class.registered.type == noHeadClass && (!exp.destType ||
11238 (exp.destType.kind != intType && exp.destType.kind != int64Type && exp.destType.kind != intPtrType && exp.destType.kind != intSizeType &&
11239 exp.destType.kind != longType && exp.destType.kind != shortType && exp.destType.kind != charType && exp.destType.kind != _BoolType)))
11241 exp.byReference = true;
11243 yylloc = oldyylloc;
11246 static void FindNextDataMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
11248 // THIS CODE WILL FIND NEXT MEMBER...
11251 *curMember = (*curMember).next;
11253 if(subMemberStackPos && *subMemberStackPos > 0 && subMemberStack[*subMemberStackPos-1].type == unionMember)
11255 *curMember = subMemberStack[--(*subMemberStackPos)];
11256 *curMember = (*curMember).next;
11259 // SKIP ALL PROPERTIES HERE...
11260 while((*curMember) && (*curMember).isProperty)
11261 *curMember = (*curMember).next;
11263 if(subMemberStackPos)
11265 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11267 subMemberStack[(*subMemberStackPos)++] = *curMember;
11269 *curMember = (*curMember).members.first;
11270 while(*curMember && (*curMember).isProperty)
11271 *curMember = (*curMember).next;
11279 if(subMemberStackPos && *subMemberStackPos)
11281 *curMember = subMemberStack[--(*subMemberStackPos)];
11282 *curMember = (*curMember).next;
11286 Class lastCurClass = *curClass;
11288 if(*curClass == _class) break; // REACHED THE END
11290 for(*curClass = _class; (*curClass).base != lastCurClass && (*curClass).base.type != systemClass; *curClass = (*curClass).base);
11291 *curMember = (*curClass).membersAndProperties.first;
11294 while((*curMember) && (*curMember).isProperty)
11295 *curMember = (*curMember).next;
11296 if(subMemberStackPos)
11298 while((*curMember) && !(*curMember).isProperty && !(*curMember).name && ((*curMember).type == structMember || (*curMember).type == unionMember))
11300 subMemberStack[(*subMemberStackPos)++] = *curMember;
11302 *curMember = (*curMember).members.first;
11303 while(*curMember && (*curMember).isProperty)
11304 *curMember = (*curMember).next;
11312 static void ProcessInitializer(Initializer init, Type type)
11316 case expInitializer:
11317 if(!init.exp || init.exp.type != instanceExp || !init.exp.instance || init.exp.instance._class || !type || type.kind == classType)
11319 // TESTING THIS FOR SHUTTING = 0 WARNING
11320 if(init.exp && !init.exp.destType)
11322 FreeType(init.exp.destType);
11323 init.exp.destType = type;
11324 if(type) type.refCount++;
11328 ProcessExpressionType(init.exp);
11329 init.isConstant = init.exp.isConstant;
11335 Expression exp = init.exp;
11336 Instantiation inst = exp.instance;
11337 MembersInit members;
11339 init.type = listInitializer;
11340 init.list = MkList();
11344 for(members = inst.members->first; members; members = members.next)
11346 if(members.type == dataMembersInit)
11349 for(member = members.dataMembers->first; member; member = member.next)
11351 ListAdd(init.list, member.initializer);
11352 member.initializer = null;
11355 // Discard all MembersInitMethod
11358 FreeExpression(exp);
11360 case listInitializer:
11363 Type initializerType = null;
11364 Class curClass = null;
11365 DataMember curMember = null;
11366 DataMember subMemberStack[256];
11367 int subMemberStackPos = 0;
11369 if(type && type.kind == arrayType)
11370 initializerType = Dereference(type);
11371 else if(type && (type.kind == structType || type.kind == unionType))
11372 initializerType = type.members.first;
11374 for(i = init.list->first; i; i = i.next)
11376 if(type && type.kind == classType && type._class && type._class.registered)
11378 // 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)
11379 FindNextDataMember(type._class.registered, &curClass, &curMember, subMemberStack, &subMemberStackPos);
11380 // TODO: Generate error on initializing a private data member this way from another module...
11383 if(!curMember.dataType)
11384 curMember.dataType = ProcessTypeString(curMember.dataTypeString, false);
11385 initializerType = curMember.dataType;
11388 ProcessInitializer(i, initializerType);
11389 if(initializerType && type && (type.kind == structType || type.kind == unionType))
11390 initializerType = initializerType.next;
11392 init.isConstant = false;
11395 if(type && type.kind == arrayType)
11396 FreeType(initializerType);
11398 if(type && type.kind != arrayType && type.kind != structType && type.kind != unionType && (type.kind != classType || !type._class.registered || type._class.registered.type != structClass))
11400 Compiler_Error($"Assigning list initializer to non list\n");
11407 static void ProcessSpecifier(Specifier spec, bool declareStruct)
11411 case baseSpecifier:
11413 if(spec.specifier == THISCLASS)
11417 spec.type = nameSpecifier;
11418 spec.name = ReplaceThisClass(thisClass);
11419 spec.symbol = FindClass(spec.name);
11420 ProcessSpecifier(spec, declareStruct);
11425 case nameSpecifier:
11427 Symbol symbol = FindType(curContext, spec.name);
11429 DeclareType(symbol.type, true, true);
11430 else if((symbol = spec.symbol /*FindClass(spec.name)*/) && symbol.registered && symbol.registered.type == structClass && declareStruct)
11431 DeclareStruct(spec.name, false);
11434 case enumSpecifier:
11439 for(e = spec.list->first; e; e = e.next)
11442 ProcessExpressionType(e.exp);
11447 case structSpecifier:
11448 case unionSpecifier:
11450 if(spec.definitions)
11453 Symbol symbol = spec.id ? FindClass(spec.id.string) : null;
11455 ProcessClass(spec.definitions, symbol);
11458 for(def = spec.definitions->first; def; def = def.next)
11460 //if(def.type == declarationClassDef && def.decl && def.decl.type == DeclarationStruct)
11461 ProcessDeclaration(def.decl);
11468 case classSpecifier:
11470 Symbol classSym = FindClass(spec.name);
11471 if(classSym && classSym.registered && classSym.registered.type == structClass)
11472 DeclareStruct(spec.name, false);
11480 static void ProcessDeclarator(Declarator decl)
11484 case identifierDeclarator:
11485 if(decl.identifier.classSym /* TODO: Name Space Fix ups || decl.identifier.nameSpace*/)
11487 FreeSpecifier(decl.identifier._class);
11488 decl.identifier._class = null;
11491 case arrayDeclarator:
11493 ProcessExpressionType(decl.array.exp);
11494 case structDeclarator:
11495 case bracketsDeclarator:
11496 case functionDeclarator:
11497 case pointerDeclarator:
11498 case extendedDeclarator:
11499 case extendedDeclaratorEnd:
11500 if(decl.declarator)
11501 ProcessDeclarator(decl.declarator);
11502 if(decl.type == functionDeclarator)
11504 Identifier id = GetDeclId(decl);
11505 if(id && id._class)
11509 qualifiers = MkListOne(id._class);
11512 if(!decl.function.parameters)
11513 decl.function.parameters = MkList();
11514 decl.function.parameters->Insert(null, param);
11517 if(decl.function.parameters)
11521 for(param = decl.function.parameters->first; param; param = param.next)
11523 if(param.qualifiers && param.qualifiers->first)
11525 Specifier spec = param.qualifiers->first;
11526 if(spec && spec.specifier == TYPED_OBJECT)
11528 Declarator d = param.declarator;
11531 qualifiers = MkListOne(MkSpecifier(VOID));
11532 declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11534 if(d.type != pointerDeclarator)
11535 newParam.qualifiers->Insert(null, MkSpecifier(CONST));
11537 FreeList(param.qualifiers, FreeSpecifier);
11539 param.qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
11540 param.declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
11542 decl.function.parameters->Insert(param, newParam);
11545 else if(spec && spec.specifier == ANY_OBJECT)
11547 Declarator d = param.declarator;
11549 FreeList(param.qualifiers, FreeSpecifier);
11551 param.qualifiers = MkListOne(MkSpecifier(VOID));
11552 if(d.type != pointerDeclarator)
11553 param.qualifiers->Insert(null, MkSpecifier(CONST));
11554 param.declarator = MkDeclaratorPointer(MkPointer(null,null), d);
11556 else if(spec.specifier == THISCLASS)
11560 spec.type = nameSpecifier;
11561 spec.name = ReplaceThisClass(thisClass);
11562 spec.symbol = FindClass(spec.name);
11563 ProcessSpecifier(spec, false);
11568 if(param.declarator)
11569 ProcessDeclarator(param.declarator);
11577 static void ProcessDeclaration(Declaration decl)
11582 case initDeclaration:
11584 bool declareStruct = false;
11586 lineNum = decl.pos.line;
11587 column = decl.pos.col;
11590 if(decl.declarators)
11594 for(d = decl.declarators->first; d; d = d.next)
11596 Type type, subType;
11597 ProcessDeclarator(d.declarator);
11599 type = ProcessType(decl.specifiers, d.declarator);
11603 ProcessInitializer(d.initializer, type);
11605 // Change "ColorRGB a = ColorRGB { 1,2,3 } => ColorRGB a { 1,2,3 }
11607 if(decl.declarators->count == 1 && d.initializer.type == expInitializer &&
11608 d.initializer.exp.type == instanceExp)
11610 if(type.kind == classType && type._class ==
11611 d.initializer.exp.expType._class)
11613 Instantiation inst = d.initializer.exp.instance;
11614 inst.exp = MkExpIdentifier(CopyIdentifier(GetDeclId(d.declarator)));
11616 d.initializer.exp.instance = null;
11617 if(decl.specifiers)
11618 FreeList(decl.specifiers, FreeSpecifier);
11619 FreeList(decl.declarators, FreeInitDeclarator);
11623 decl.type = instDeclaration;
11628 for(subType = type; subType;)
11630 if(subType.kind == classType)
11632 declareStruct = true;
11635 else if(subType.kind == pointerType)
11637 else if(subType.kind == arrayType)
11638 subType = subType.arrayType;
11648 if(decl.specifiers)
11651 for(s = decl.specifiers->first; s; s = s.next)
11653 ProcessSpecifier(s, declareStruct);
11658 case instDeclaration:
11660 ProcessInstantiationType(decl.inst);
11663 case structDeclaration:
11667 bool declareStruct = false;
11669 if(decl.declarators)
11671 for(d = decl.declarators->first; d; d = d.next)
11673 Type type = ProcessType(decl.specifiers, d.declarator);
11675 ProcessDeclarator(d);
11676 for(subType = type; subType;)
11678 if(subType.kind == classType)
11680 declareStruct = true;
11683 else if(subType.kind == pointerType)
11685 else if(subType.kind == arrayType)
11686 subType = subType.arrayType;
11693 if(decl.specifiers)
11695 for(spec = decl.specifiers->first; spec; spec = spec.next)
11696 ProcessSpecifier(spec, declareStruct);
11703 static FunctionDefinition curFunction;
11705 static void CreateFireWatcher(Property prop, Expression object, Statement stmt)
11707 char propName[1024], propNameM[1024];
11708 char getName[1024], setName[1024];
11711 DeclareProperty(prop, setName, getName);
11713 // eInstance_FireWatchers(object, prop);
11714 strcpy(propName, "__ecereProp_");
11715 FullClassNameCat(propName, prop._class.fullName, false);
11716 strcat(propName, "_");
11717 // strcat(propName, prop.name);
11718 FullClassNameCat(propName, prop.name, true);
11719 //MangleClassName(propName);
11721 strcpy(propNameM, "__ecerePropM_");
11722 FullClassNameCat(propNameM, prop._class.fullName, false);
11723 strcat(propNameM, "_");
11724 // strcat(propNameM, prop.name);
11725 FullClassNameCat(propNameM, prop.name, true);
11726 //MangleClassName(propNameM);
11728 if(prop.isWatchable)
11731 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11732 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11733 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11736 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11737 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11738 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireWatchers")), args));
11744 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11745 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
11746 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11749 ListAdd(args, object ? CopyExpression(object) : MkExpIdentifier(MkIdentifier("this")));
11750 ListAdd(args, MkExpIdentifier(MkIdentifier(propNameM)));
11751 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_FireSelfWatchers")), args));
11754 if(curFunction.propSet && !strcmp(curFunction.propSet.string, prop.name) &&
11755 (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
11756 curFunction.propSet.fireWatchersDone = true;
11759 static void ProcessStatement(Statement stmt)
11763 lineNum = stmt.pos.line;
11764 column = stmt.pos.col;
11769 ProcessStatement(stmt.labeled.stmt);
11772 // This expression should be constant...
11773 if(stmt.caseStmt.exp)
11775 FreeType(stmt.caseStmt.exp.destType);
11776 stmt.caseStmt.exp.destType = curSwitchType;
11777 if(curSwitchType) curSwitchType.refCount++;
11778 ProcessExpressionType(stmt.caseStmt.exp);
11779 ComputeExpression(stmt.caseStmt.exp);
11781 if(stmt.caseStmt.stmt)
11782 ProcessStatement(stmt.caseStmt.stmt);
11786 if(stmt.compound.context)
11791 Statement prevCompound = curCompound;
11792 Context prevContext = curContext;
11794 if(!stmt.compound.isSwitch)
11795 curCompound = stmt;
11796 curContext = stmt.compound.context;
11798 if(stmt.compound.declarations)
11800 for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
11801 ProcessDeclaration(decl);
11803 if(stmt.compound.statements)
11805 for(s = stmt.compound.statements->first; s; s = s.next)
11806 ProcessStatement(s);
11809 curContext = prevContext;
11810 curCompound = prevCompound;
11814 case expressionStmt:
11817 if(stmt.expressions)
11819 for(exp = stmt.expressions->first; exp; exp = exp.next)
11820 ProcessExpressionType(exp);
11828 FreeType(((Expression)stmt.ifStmt.exp->last).destType);
11829 ((Expression)stmt.ifStmt.exp->last).destType = MkClassType("bool");
11830 ((Expression)stmt.ifStmt.exp->last).destType.truth = true;
11831 for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
11833 ProcessExpressionType(exp);
11835 if(stmt.ifStmt.stmt)
11836 ProcessStatement(stmt.ifStmt.stmt);
11837 if(stmt.ifStmt.elseStmt)
11838 ProcessStatement(stmt.ifStmt.elseStmt);
11843 Type oldSwitchType = curSwitchType;
11844 if(stmt.switchStmt.exp)
11847 for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
11857 e.exp.destType = destType;
11860 ProcessExpressionType(exp);
11863 curSwitchType = exp.expType;
11866 ProcessStatement(stmt.switchStmt.stmt);
11867 curSwitchType = oldSwitchType;
11872 if(stmt.whileStmt.exp)
11876 FreeType(((Expression)stmt.whileStmt.exp->last).destType);
11877 ((Expression)stmt.whileStmt.exp->last).destType = MkClassType("bool");
11878 ((Expression)stmt.whileStmt.exp->last).destType.truth = true;
11879 for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
11881 ProcessExpressionType(exp);
11884 if(stmt.whileStmt.stmt)
11885 ProcessStatement(stmt.whileStmt.stmt);
11890 if(stmt.doWhile.exp)
11894 if(stmt.doWhile.exp->last)
11896 FreeType(((Expression)stmt.doWhile.exp->last).destType);
11897 ((Expression)stmt.doWhile.exp->last).destType = MkClassType("bool");
11898 ((Expression)stmt.doWhile.exp->last).destType.truth = true;
11900 for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
11902 ProcessExpressionType(exp);
11905 if(stmt.doWhile.stmt)
11906 ProcessStatement(stmt.doWhile.stmt);
11912 if(stmt.forStmt.init)
11913 ProcessStatement(stmt.forStmt.init);
11915 if(stmt.forStmt.check && stmt.forStmt.check.expressions)
11917 FreeType(((Expression)stmt.forStmt.check.expressions->last).destType);
11918 ((Expression)stmt.forStmt.check.expressions->last).destType = MkClassType("bool");
11919 ((Expression)stmt.forStmt.check.expressions->last).destType.truth = true;
11922 if(stmt.forStmt.check)
11923 ProcessStatement(stmt.forStmt.check);
11924 if(stmt.forStmt.increment)
11926 for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
11927 ProcessExpressionType(exp);
11930 if(stmt.forStmt.stmt)
11931 ProcessStatement(stmt.forStmt.stmt);
11936 Identifier id = stmt.forEachStmt.id;
11937 OldList * exp = stmt.forEachStmt.exp;
11938 OldList * filter = stmt.forEachStmt.filter;
11939 Statement block = stmt.forEachStmt.stmt;
11940 char iteratorType[1024];
11943 bool isBuiltin = exp && exp->last &&
11944 (((Expression)exp->last).type == ExpressionType::arrayExp ||
11945 (((Expression)exp->last).type == castExp && ((Expression)exp->last).cast.exp.type == ExpressionType::arrayExp));
11946 Expression arrayExp;
11947 const char * typeString = null;
11948 int builtinCount = 0;
11950 for(e = exp ? exp->first : null; e; e = e.next)
11954 FreeType(e.destType);
11955 e.destType = ProcessTypeString("Container", false);
11957 if(!isBuiltin || e.next)
11958 ProcessExpressionType(e);
11961 source = (exp && exp->last) ? ((Expression)exp->last).expType : null;
11962 if(isBuiltin || (source && source.kind == classType && source._class && source._class.registered && source._class.registered != containerClass &&
11963 eClass_IsDerived(source._class.registered, containerClass)))
11965 Class _class = source ? source._class.registered : null;
11967 Expression expIt = null;
11968 bool isMap = false, isArray = false, isLinkList = false, isList = false, isCustomAVLTree = false; //, isAVLTree = false;
11969 Class arrayClass = eSystem_FindClass(privateModule, "Array");
11970 Class linkListClass = eSystem_FindClass(privateModule, "LinkList");
11971 Class customAVLTreeClass = eSystem_FindClass(privateModule, "CustomAVLTree");
11972 stmt.type = compoundStmt;
11974 stmt.compound.context = Context { };
11975 stmt.compound.context.parent = curContext;
11976 curContext = stmt.compound.context;
11978 if(source && eClass_IsDerived(source._class.registered, customAVLTreeClass))
11980 Class mapClass = eSystem_FindClass(privateModule, "Map");
11981 //Class avlTreeClass = eSystem_FindClass(privateModule, "AVLTree");
11982 isCustomAVLTree = true;
11983 /*if(eClass_IsDerived(source._class.registered, avlTreeClass))
11985 else */if(eClass_IsDerived(source._class.registered, mapClass))
11988 else if(source && eClass_IsDerived(source._class.registered, arrayClass)) isArray = true;
11989 else if(source && eClass_IsDerived(source._class.registered, linkListClass))
11991 Class listClass = eSystem_FindClass(privateModule, "List");
11993 isList = eClass_IsDerived(source._class.registered, listClass);
11999 OldList * specs = MkList();
12000 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12001 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12002 stmt.compound.declarations = MkListOne(
12003 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12004 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12005 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalArray")),
12006 MkInitializerAssignment(MkExpBrackets(exp))))));
12011 char typeStringBuf[1024];
12013 // TODO: Merge this code?
12014 arrayExp = (((Expression)exp->last).type == ExpressionType::arrayExp) ? (Expression)exp->last : ((Expression)exp->last).cast.exp;
12015 if(((Expression)exp->last).type == castExp)
12017 TypeName typeName = ((Expression)exp->last).cast.typeName;
12019 arrayExp.destType = ProcessType(typeName.qualifiers, typeName.declarator);
12022 if(arrayExp.destType && arrayExp.destType.kind == classType && arrayExp.destType._class && arrayExp.destType._class.registered &&
12023 arrayExp.destType._class.registered != containerClass && eClass_IsDerived(arrayExp.destType._class.registered, containerClass) &&
12024 arrayExp.destType._class.registered.templateArgs)
12026 Class templateClass = arrayExp.destType._class.registered;
12027 typeString = templateClass.templateArgs[2].dataTypeString;
12029 else if(arrayExp.list)
12031 // Guess type from expressions in the array
12033 for(e = arrayExp.list->first; e; e = e.next)
12035 ProcessExpressionType(e);
12038 if(!type) { type = e.expType; type.refCount++; }
12041 // if(!MatchType(e.expType, type, null, null, null, false, false, false))
12042 if(!MatchTypeExpression(e, type, null, false, true))
12048 e = arrayExp.list->first;
12049 ProcessExpressionType(e);
12052 //if(!MatchTypes(e.expType, type, null, null, null, false, false, false, false))
12053 if(!MatchTypeExpression(e, type, null, false, true))
12055 FreeType(e.expType);
12066 FreeType(e.expType);
12073 typeStringBuf[0] = '\0';
12074 PrintType(type, typeStringBuf, false, true);
12075 typeString = typeStringBuf;
12081 OldList * initializers = MkList();
12083 OldList * specs = MkList();
12088 builtinCount = arrayExp.list->count;
12089 type = ProcessTypeString(typeString, false);
12090 while((e = arrayExp.list->first))
12092 arrayExp.list->Remove(e);
12095 ProcessExpressionType(e);
12096 ListAdd(initializers, MkInitializerAssignment(e));
12099 delete arrayExp.list;
12101 decl = SpecDeclFromString(typeString, specs, MkDeclaratorIdentifier(id));
12102 stmt.compound.declarations = MkListOne(MkDeclaration(CopyList(specs, CopySpecifier),
12103 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), /*CopyDeclarator(*/decl/*)*/), null))));
12105 ListAdd(stmt.compound.declarations, MkDeclaration(specs, MkListOne(MkInitDeclarator(
12107 /*CopyDeclarator(*/decl/*)*/, MkDeclaratorArray(MkDeclaratorIdentifier(MkIdentifier("__internalArray")), null)
12108 ), MkInitializerList(initializers)))));
12109 FreeList(exp, FreeExpression);
12113 arrayExp.expType = ProcessTypeString("Container", false);
12114 Compiler_Error($"Couldn't determine type of array elements\n");
12119 OldList * specs = MkList();
12121 decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs,
12122 MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(id)));
12123 stmt.compound.declarations = MkListOne(
12124 MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12125 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName("BuiltInContainer")),
12126 MkListOne(MkInitDeclarator(MkDeclaratorPointer(MkPointer(null, null), MkDeclaratorIdentifier(MkIdentifier("__internalArray"))),
12127 MkInitializerAssignment(MkExpBrackets(exp))))));
12130 else if(isLinkList && !isList)
12133 OldList * specs = MkList();
12134 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12135 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12136 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12137 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalLinkList")),
12138 MkInitializerAssignment(MkExpBrackets(exp))))));
12140 /*else if(isCustomAVLTree)
12143 OldList * specs = MkList();
12144 decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, MkDeclaratorIdentifier(id));
12145 stmt.compound.declarations = MkListOne(MkDeclaration(specs, MkListOne(MkInitDeclarator(decl, null))));
12146 ListAdd(stmt.compound.declarations, MkDeclaration(MkListOne(MkSpecifierName(source._class.registered.fullName)),
12147 MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__internalTree")),
12148 MkInitializerAssignment(MkExpBrackets(exp))))));
12150 else if(_class.templateArgs)
12153 sprintf(iteratorType, "MapIterator<%s, %s >", _class.templateArgs[5].dataTypeString, _class.templateArgs[6].dataTypeString);
12155 sprintf(iteratorType, "Iterator<%s, %s >", _class.templateArgs[2].dataTypeString, _class.templateArgs[1].dataTypeString);
12157 stmt.compound.declarations = MkListOne(
12158 MkDeclarationInst(MkInstantiationNamed(MkListOne(MkSpecifierName(iteratorType)),
12159 MkExpIdentifier(id), MkListOne(MkMembersInitList(MkListOne(MkMemberInit(isMap ? MkListOne(MkIdentifier("map")) : null,
12160 MkInitializerAssignment(MkExpBrackets(exp)))))))));
12162 symbol = FindSymbol(id.string, curContext, curContext, false, false);
12166 // Reparent sub-contexts in this statement
12170 if(block.compound.context)
12171 block.compound.context.parent = stmt.compound.context;
12174 if(block.ifStmt.stmt && block.ifStmt.stmt.type == compoundStmt && block.ifStmt.stmt.compound.context)
12175 block.ifStmt.stmt.compound.context.parent = stmt.compound.context;
12176 if(block.ifStmt.elseStmt && block.ifStmt.elseStmt.type == compoundStmt && block.ifStmt.elseStmt.compound.context)
12177 block.ifStmt.elseStmt.compound.context.parent = stmt.compound.context;
12180 if(block.switchStmt.stmt && block.switchStmt.stmt.type == compoundStmt && block.switchStmt.stmt.compound.context)
12181 block.switchStmt.stmt.compound.context.parent = stmt.compound.context;
12184 if(block.whileStmt.stmt && block.whileStmt.stmt.type == compoundStmt && block.whileStmt.stmt.compound.context)
12185 block.whileStmt.stmt.compound.context.parent = stmt.compound.context;
12188 if(block.doWhile.stmt && block.doWhile.stmt.type == compoundStmt && block.doWhile.stmt.compound.context)
12189 block.doWhile.stmt.compound.context.parent = stmt.compound.context;
12192 if(block.forStmt.stmt && block.forStmt.stmt.type == compoundStmt && block.forStmt.stmt.compound.context)
12193 block.forStmt.stmt.compound.context.parent = stmt.compound.context;
12196 if(block.forEachStmt.stmt && block.forEachStmt.stmt.type == compoundStmt && block.forEachStmt.stmt.compound.context)
12197 block.forEachStmt.stmt.compound.context.parent = stmt.compound.context;
12199 /* Only handle those with compound blocks for now... (Potential limitation on compound statements within expressions)
12202 case expressionStmt:
12208 case badDeclarationStmt:
12209 case fireWatchersStmt:
12210 case stopWatchingStmt:
12217 block = MkIfStmt(filter, block, null);
12221 stmt.compound.statements = MkListOne(MkForStmt(
12222 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array"))))),
12223 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12224 MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("array")), '+', MkExpMember(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12225 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12227 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12228 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12229 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12234 //OldList * specs = MkList();
12235 // Declarator decl = SpecDeclFromString(typeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12237 sprintf(count, "%d", builtinCount);
12239 stmt.compound.statements = MkListOne(MkForStmt(
12240 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpIdentifier(MkIdentifier("__internalArray"))))),
12241 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12242 MkExpOp(MkExpIdentifier(MkIdentifier("__internalArray")), '+', MkExpConstant(count))))),
12243 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12247 Declarator decl = SpecDeclFromString(_class.templateArgs[2].dataTypeString, specs, MkDeclaratorPointer(MkPointer(null, null), null));
12248 stmt.compound.statements = MkListOne(MkForStmt(
12249 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))))),
12250 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '<',
12251 MkExpOp(MkExpCast(MkTypeName(specs, decl), MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("data"))), '+', MkExpPointer(MkExpIdentifier(MkIdentifier("__internalArray")), MkIdentifier("count")))))),
12252 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), INC_OP, null)),
12255 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12256 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12257 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12259 else if(isLinkList && !isList)
12261 Class typeClass = eSystem_FindClass(_class.module, _class.templateArgs[3].dataTypeString);
12262 Class listItemClass = eSystem_FindClass(_class.module, "ListItem");
12263 if(typeClass && eClass_IsDerived(typeClass, listItemClass) && _class.templateArgs[5].dataTypeString &&
12264 !strcmp(_class.templateArgs[5].dataTypeString, "LT::link"))
12266 stmt.compound.statements = MkListOne(MkForStmt(
12267 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12268 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12269 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12274 OldList * specs = MkList();
12275 Declarator decl = SpecDeclFromString(_class.templateArgs[3].dataTypeString, specs, null);
12276 stmt.compound.statements = MkListOne(MkForStmt(
12277 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("first"))))),
12278 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12279 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpCast(MkTypeName(specs, decl), MkExpCall(
12280 MkExpMember(MkExpIdentifier(MkIdentifier("__internalLinkList")), MkIdentifier("GetNext")),
12281 MkListOne(MkExpCast(MkTypeName(MkListOne(MkSpecifierName("IteratorPointer")), null), MkExpIdentifier(CopyIdentifier(id)))))))),
12284 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12285 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12286 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12288 /*else if(isCustomAVLTree)
12290 stmt.compound.statements = MkListOne(MkForStmt(
12291 MkExpressionStmt(MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpMember(MkExpIdentifier(
12292 MkIdentifier("__internalTree")), MkIdentifier("root")), MkIdentifier("minimum"))))),
12293 MkExpressionStmt(MkListOne(MkExpIdentifier(CopyIdentifier(id)))),
12294 MkListOne(MkExpOp(MkExpIdentifier(CopyIdentifier(id)), '=', MkExpMember(MkExpIdentifier(CopyIdentifier(id)), MkIdentifier("next")))),
12297 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.init);
12298 ProcessStatement(((Statement)stmt.compound.statements->first).forStmt.check);
12299 ProcessExpressionType(((Statement)stmt.compound.statements->first).forStmt.increment->first);
12303 stmt.compound.statements = MkListOne(MkWhileStmt(MkListOne(MkExpCall(MkExpMember(expIt = MkExpIdentifier(CopyIdentifier(id)),
12304 MkIdentifier("Next")), null)), block));
12306 ProcessExpressionType(expIt);
12307 if(stmt.compound.declarations->first)
12308 ProcessDeclaration(stmt.compound.declarations->first);
12311 symbol.isIterator = isMap ? 2 : ((isArray || isBuiltin) ? 3 : (isLinkList ? (isList ? 5 : 4) : (isCustomAVLTree ? 6 : 1)));
12313 ProcessStatement(stmt);
12314 curContext = stmt.compound.context.parent;
12319 Compiler_Error($"Expression is not a container\n");
12332 if(stmt.expressions)
12334 for(exp = stmt.expressions->first; exp; exp = exp.next)
12338 if(curFunction && !curFunction.type)
12339 curFunction.type = ProcessType(
12340 curFunction.specifiers, curFunction.declarator);
12341 FreeType(exp.destType);
12342 exp.destType = (curFunction && curFunction.type && curFunction.type.kind == functionType) ? curFunction.type.returnType : null;
12343 if(exp.destType) exp.destType.refCount++;
12345 ProcessExpressionType(exp);
12350 case badDeclarationStmt:
12352 ProcessDeclaration(stmt.decl);
12358 if(stmt.asmStmt.inputFields)
12360 for(field = stmt.asmStmt.inputFields->first; field; field = field.next)
12361 if(field.expression)
12362 ProcessExpressionType(field.expression);
12364 if(stmt.asmStmt.outputFields)
12366 for(field = stmt.asmStmt.outputFields->first; field; field = field.next)
12367 if(field.expression)
12368 ProcessExpressionType(field.expression);
12370 if(stmt.asmStmt.clobberedFields)
12372 for(field = stmt.asmStmt.clobberedFields->first; field; field = field.next)
12374 if(field.expression)
12375 ProcessExpressionType(field.expression);
12382 PropertyWatch propWatch;
12383 OldList * watches = stmt._watch.watches;
12384 Expression object = stmt._watch.object;
12385 Expression watcher = stmt._watch.watcher;
12387 ProcessExpressionType(watcher);
12389 ProcessExpressionType(object);
12393 if(watcher || thisClass)
12395 External external = curExternal;
12396 Context context = curContext;
12398 stmt.type = expressionStmt;
12399 stmt.expressions = MkList();
12401 curExternal = external.prev;
12403 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12405 ClassFunction func;
12406 char watcherName[1024];
12407 Class watcherClass = watcher ?
12408 ((watcher.expType && watcher.expType.kind == classType && watcher.expType._class) ? watcher.expType._class.registered : null) : thisClass;
12409 External createdExternal;
12411 // Create a declaration above
12412 External externalDecl = MkExternalDeclaration(null);
12413 ast->Insert(curExternal.prev, externalDecl);
12415 sprintf(watcherName,"__ecerePropertyWatcher_%d", propWatcherID++);
12416 if(propWatch.deleteWatch)
12417 strcat(watcherName, "_delete");
12421 for(propID = propWatch.properties->first; propID; propID = propID.next)
12423 strcat(watcherName, "_");
12424 strcat(watcherName, propID.string);
12428 if(object && object.expType && object.expType.kind == classType && object.expType._class && object.expType._class.registered)
12430 // TESTING THIS STUFF... BEWARE OF SYMBOL ID ISSUES
12431 func = MkClassFunction(MkListOne(MkSpecifier(VOID)), null, MkDeclaratorFunction(MkDeclaratorIdentifier(MkIdentifier(watcherName)),
12432 //MkListOne(MkTypeName(MkListOne(MkSpecifier(VOID)), null))), null);
12433 MkListOne(MkTypeName(MkListOne(MkSpecifierName(object.expType._class.string)), MkDeclaratorIdentifier(MkIdentifier("value"))))), null);
12434 ProcessClassFunctionBody(func, propWatch.compound);
12435 propWatch.compound = null;
12437 //afterExternal = afterExternal ? afterExternal : curExternal;
12439 //createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal.prev);
12440 createdExternal = ProcessClassFunction(watcherClass, func, ast, curExternal, true);
12442 createdExternal.symbol.idCode = external.symbol.idCode;
12444 curExternal = createdExternal;
12445 ProcessFunction(createdExternal.function);
12448 // Create a declaration above
12450 Declaration decl = MkDeclaration(CopyList(createdExternal.function.specifiers, CopySpecifier),
12451 MkListOne(MkInitDeclarator(CopyDeclarator(createdExternal.function.declarator), null)));
12452 externalDecl.declaration = decl;
12453 if(decl.symbol && !decl.symbol.pointerExternal)
12454 decl.symbol.pointerExternal = externalDecl;
12457 if(propWatch.deleteWatch)
12459 OldList * args = MkList();
12460 ListAdd(args, CopyExpression(object));
12461 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12462 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
12463 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_WatchDestruction")), args));
12467 Class _class = object.expType._class.registered;
12470 for(propID = propWatch.properties->first; propID; propID = propID.next)
12472 char propName[1024];
12473 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12476 char getName[1024], setName[1024];
12477 OldList * args = MkList();
12479 DeclareProperty(prop, setName, getName);
12481 // eInstance_Watch(stmt.watch.object, prop, stmt.watch.watcher, callback);
12482 strcpy(propName, "__ecereProp_");
12483 FullClassNameCat(propName, prop._class.fullName, false);
12484 strcat(propName, "_");
12485 // strcat(propName, prop.name);
12486 FullClassNameCat(propName, prop.name, true);
12488 ListAdd(args, CopyExpression(object));
12489 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12490 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12491 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(VOID)), MkDeclaratorPointer(MkPointer(null, null), null)), MkExpIdentifier(MkIdentifier(watcherName))));
12493 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_Watch")), args));
12496 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12501 Compiler_Error($"Invalid watched object\n");
12504 curExternal = external;
12505 curContext = context;
12508 FreeExpression(watcher);
12510 FreeExpression(object);
12511 FreeList(watches, FreePropertyWatch);
12514 Compiler_Error($"No observer specified and not inside a _class\n");
12518 for(propWatch = watches->first; propWatch; propWatch = propWatch.next)
12520 ProcessStatement(propWatch.compound);
12526 case fireWatchersStmt:
12528 OldList * watches = stmt._watch.watches;
12529 Expression object = stmt._watch.object;
12531 // DEBUGGER BUG: Why doesn't watches evaluate to null??
12532 // printf("%X\n", watches);
12533 // printf("%X\n", stmt._watch.watches);
12535 ProcessExpressionType(object);
12540 ((object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null) : thisClass;
12546 stmt.type = expressionStmt;
12547 stmt.expressions = MkList();
12549 // Check if we're inside a property set
12550 if(!watches && curFunction.propSet && (!object || (object.type == identifierExp && !strcmp(object.identifier.string, "this"))))
12552 watches = MkListOne(MkIdentifier(curFunction.propSet.string));
12556 //Compiler_Error($"No property specified and not inside a property set\n");
12560 for(propID = watches->first; propID; propID = propID.next)
12562 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12565 CreateFireWatcher(prop, object, stmt);
12568 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12573 // Fire all properties!
12576 for(base = _class; base; base = base.base)
12578 for(prop = base.membersAndProperties.first; prop; prop = prop.next)
12580 if(prop.isProperty && prop.isWatchable)
12582 CreateFireWatcher(prop, object, stmt);
12589 FreeExpression(object);
12590 FreeList(watches, FreeIdentifier);
12593 Compiler_Error($"Invalid object specified and not inside a class\n");
12597 case stopWatchingStmt:
12599 OldList * watches = stmt._watch.watches;
12600 Expression object = stmt._watch.object;
12601 Expression watcher = stmt._watch.watcher;
12604 ProcessExpressionType(object);
12606 ProcessExpressionType(watcher);
12609 _class = (object && object.expType && object.expType.kind == classType && object.expType._class) ? object.expType._class.registered : null;
12611 if(watcher || thisClass)
12617 stmt.type = expressionStmt;
12618 stmt.expressions = MkList();
12623 // eInstance_StopWatching(object, null, watcher);
12625 ListAdd(args, CopyExpression(object));
12626 ListAdd(args, MkExpConstant("0"));
12627 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12628 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12632 for(propID = watches->first; propID; propID = propID.next)
12634 char propName[1024];
12635 Property prop = eClass_FindProperty(_class, propID.string, privateModule);
12638 char getName[1024], setName[1024];
12639 OldList * args = MkList();
12641 DeclareProperty(prop, setName, getName);
12643 // eInstance_StopWatching(object, prop, watcher);
12644 strcpy(propName, "__ecereProp_");
12645 FullClassNameCat(propName, prop._class.fullName, false);
12646 strcat(propName, "_");
12647 // strcat(propName, prop.name);
12648 FullClassNameCat(propName, prop.name, true);
12649 //MangleClassName(propName);
12651 ListAdd(args, CopyExpression(object));
12652 ListAdd(args, MkExpIdentifier(MkIdentifier(propName)));
12653 ListAdd(args, watcher ? CopyExpression(watcher) : MkExpIdentifier(MkIdentifier("this")));
12654 ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("ecere::com::eInstance_StopWatching")), args));
12657 Compiler_Error($"Property %s not found in class %s\n", propID.string, _class.fullName);
12662 FreeExpression(object);
12664 FreeExpression(watcher);
12665 FreeList(watches, FreeIdentifier);
12668 Compiler_Error($"Invalid object specified and not inside a class\n");
12671 Compiler_Error($"No observer specified and not inside a class\n");
12678 static void ProcessFunction(FunctionDefinition function)
12680 Identifier id = GetDeclId(function.declarator);
12681 Symbol symbol = function.declarator ? function.declarator.symbol : null;
12682 Type type = symbol ? symbol.type : null;
12683 Class oldThisClass = thisClass;
12684 Context oldTopContext = topContext;
12686 yylloc = function.loc;
12687 // Process thisClass
12689 if(type && type.thisClass)
12691 Symbol classSym = type.thisClass;
12692 Class _class = type.thisClass.registered;
12693 char className[1024];
12694 char structName[1024];
12695 Declarator funcDecl;
12698 bool typedObject = false;
12700 if(_class && !_class.base)
12702 _class = currentClass;
12703 if(_class && !_class.symbol)
12704 _class.symbol = FindClass(_class.fullName);
12705 classSym = _class ? _class.symbol : null;
12706 typedObject = true;
12709 thisClass = _class;
12711 if(inCompiler && _class)
12713 if(type.kind == functionType)
12715 if(symbol.type.params.count == 1 && ((Type)symbol.type.params.first).kind == voidType)
12717 //TypeName param = symbol.type.params.first;
12718 Type param = symbol.type.params.first;
12719 symbol.type.params.Remove(param);
12720 //FreeTypeName(param);
12723 if(type.classObjectType != classPointer)
12725 symbol.type.params.Insert(null, MkClassType(_class.fullName));
12726 symbol.type.staticMethod = true;
12727 symbol.type.thisClass = null;
12729 // HIGH DANGER: VERIFYING THIS...
12730 symbol.type.extraParam = false;
12734 strcpy(className, "__ecereClass_");
12735 FullClassNameCat(className, _class.fullName, true);
12737 //MangleClassName(className);
12740 FullClassNameCat(structName, _class.fullName, false);
12745 funcDecl = GetFuncDecl(function.declarator);
12748 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12750 TypeName param = funcDecl.function.parameters->first;
12751 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12753 funcDecl.function.parameters->Remove(param);
12754 FreeTypeName(param);
12758 // DANGER: Watch for this... Check if it's a Conversion?
12759 // if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12761 // WAS TRYING THIS FOR CONVERSION PROPERTIES ON NOHEAD CLASSES: if((_class.type == structClass) || function != (FunctionDefinition)symbol.externalSet)
12762 if(!function.propertyNoThis)
12764 TypeName thisParam = null;
12766 if(type.classObjectType != classPointer)
12768 thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12769 if(!funcDecl.function.parameters)
12770 funcDecl.function.parameters = MkList();
12771 funcDecl.function.parameters->Insert(null, thisParam);
12776 if(type.classObjectType != classPointer)
12778 if(type.byReference || _class.type == unitClass || _class.type == systemClass || _class.type == enumClass || _class.type == bitClass)
12779 thisParam.declarator = MkDeclaratorPointer(MkPointer(null,null), thisParam.declarator);
12782 thisParam = TypeName
12784 declarator = MkDeclaratorPointer(MkPointer(null,null), MkDeclaratorIdentifier(MkIdentifier("class")));
12785 qualifiers = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Class"), null));
12787 funcDecl.function.parameters->Insert(null, thisParam);
12792 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12794 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12795 funcDecl = GetFuncDecl(initDecl.declarator);
12798 if(funcDecl.function.parameters && funcDecl.function.parameters->count == 1)
12800 TypeName param = funcDecl.function.parameters->first;
12801 if(param.qualifiers && param.qualifiers->count == 1 && ((Specifier)param.qualifiers->first).specifier == VOID && !param.declarator)
12803 funcDecl.function.parameters->Remove(param);
12804 FreeTypeName(param);
12808 if(type.classObjectType != classPointer)
12810 // DANGER: Watch for this... Check if it's a Conversion?
12811 if((_class.type != bitClass && _class.type != unitClass && _class.type != enumClass) || function != (FunctionDefinition)symbol.externalSet)
12813 TypeName thisParam = QMkClass(_class.fullName, MkDeclaratorIdentifier(MkIdentifier("this")));
12815 if(!funcDecl.function.parameters)
12816 funcDecl.function.parameters = MkList();
12817 funcDecl.function.parameters->Insert(null, thisParam);
12824 // Add this to the context
12827 if(type.classObjectType != classPointer)
12829 thisSymbol = Symbol
12831 string = CopyString("this");
12832 type = classSym ? MkClassType(classSym.string) : null; //_class.fullName);
12834 function.body.compound.context.symbols.Add((BTNode)thisSymbol);
12836 if(typedObject && thisSymbol.type)
12838 thisSymbol.type.classObjectType = ClassObjectType::typedObject;
12839 thisSymbol.type.byReference = type.byReference;
12840 thisSymbol.type.typedByReference = type.byReference;
12842 thisSymbol = Symbol { string = CopyString("class") };
12843 function.body.compound.context.symbols.Add(thisSymbol);
12849 // Pointer to class data
12851 if(inCompiler && _class && (_class.type == normalClass /*|| _class.type == noHeadClass*/) && type.classObjectType != classPointer)
12853 DataMember member = null;
12856 for(base = _class; base && base.type != systemClass; base = base.next)
12858 for(member = base.membersAndProperties.first; member; member = member.next)
12859 if(!member.isProperty)
12865 for(member = _class.membersAndProperties.first; member; member = member.next)
12866 if(!member.isProperty)
12870 char pointerName[1024];
12873 Initializer initializer;
12874 Expression exp, bytePtr;
12876 strcpy(pointerName, "__ecerePointer_");
12877 FullClassNameCat(pointerName, _class.fullName, false);
12879 char className[1024];
12880 strcpy(className, "__ecereClass_");
12881 FullClassNameCat(className, classSym.string, true);
12882 //MangleClassName(className);
12885 DeclareClass(classSym, className);
12889 bytePtr = QBrackets(MkExpCast(QMkType("char", QMkPtrDecl(null)), QMkExpId("this")));
12894 sprintf(string, "%d", _class.offset);
12895 exp = QBrackets(MkExpOp(bytePtr, '+', MkExpConstant(string)));
12899 // ([bytePtr] + [className]->offset)
12900 exp = QBrackets(MkExpOp(bytePtr, '+',
12901 MkExpPointer(QMkExpId(className), MkIdentifier("offset"))));
12904 // (this ? [exp] : 0)
12905 exp = QBrackets(QMkExpCond(QMkExpId("this"), exp, MkExpConstant("0")));
12909 kind = pointerType;
12910 type = Type { refCount = 1, kind = voidType };
12915 yylloc = function.body.loc;
12916 // ([structName] *) [exp]
12917 // initializer = MkInitializerAssignment(MkExpCast(QMkType(structName, QMkPtrDecl(null)), exp));
12918 initializer = MkInitializerAssignment(
12919 MkExpCast(MkTypeName(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null)), MkDeclaratorPointer(MkPointer(null, null), null)), exp));
12921 // [structName] * [pointerName] = [initializer];
12922 // decl = QMkDeclaration(structName, MkInitDeclarator(QMkPtrDecl(pointerName), initializer));
12925 Context prevContext = curContext;
12927 curContext = function.body.compound.context;
12929 decl = MkDeclaration((list = MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier(structName), null))),
12930 MkListOne(MkInitDeclarator(QMkPtrDecl(pointerName), initializer)));
12931 list->Insert(null, MkSpecifierExtended(MkExtDeclAttrib(MkAttrib(ATTRIB, MkListOne(MkAttribute(CopyString("unused"), null))))));
12933 curContext = prevContext;
12937 decl.symbol = null;
12939 if(!function.body.compound.declarations)
12940 function.body.compound.declarations = MkList();
12941 function.body.compound.declarations->Insert(null, decl);
12947 // Loop through the function and replace undeclared identifiers
12948 // which are a member of the class (methods, properties or data)
12949 // by "this.[member]"
12956 FreeSpecifier(id._class);
12959 if(symbol && symbol.pointerExternal && symbol.pointerExternal.type == declarationExternal)
12961 InitDeclarator initDecl = symbol.pointerExternal.declaration.declarators->first;
12962 id = GetDeclId(initDecl.declarator);
12964 FreeSpecifier(id._class);
12969 topContext = function.body.compound.context;
12971 FunctionDefinition oldFunction = curFunction;
12972 curFunction = function;
12974 ProcessStatement(function.body);
12976 // If this is a property set and no firewatchers has been done yet, add one here
12977 if(inCompiler && function.propSet && !function.propSet.fireWatchersDone)
12979 Statement prevCompound = curCompound;
12980 Context prevContext = curContext;
12982 Statement fireWatchers = MkFireWatchersStmt(null, null);
12983 if(!function.body.compound.statements) function.body.compound.statements = MkList();
12984 ListAdd(function.body.compound.statements, fireWatchers);
12986 curCompound = function.body;
12987 curContext = function.body.compound.context;
12989 ProcessStatement(fireWatchers);
12991 curContext = prevContext;
12992 curCompound = prevCompound;
12996 curFunction = oldFunction;
12999 if(function.declarator)
13001 ProcessDeclarator(function.declarator);
13004 topContext = oldTopContext;
13005 thisClass = oldThisClass;
13008 /////////// INSTANTIATIONS / DATA TYPES PASS /////////////////////////////////////////////
13009 static void ProcessClass(OldList definitions, Symbol symbol)
13012 External external = curExternal;
13013 Class regClass = symbol ? symbol.registered : null;
13015 // Process all functions
13016 for(def = definitions.first; def; def = def.next)
13018 if(def.type == functionClassDef)
13020 if(def.function.declarator)
13021 curExternal = def.function.declarator.symbol.pointerExternal;
13023 curExternal = external;
13025 ProcessFunction((FunctionDefinition)def.function);
13027 else if(def.type == declarationClassDef)
13029 if(def.decl.type == instDeclaration)
13031 thisClass = regClass;
13032 ProcessInstantiationType(def.decl.inst);
13038 Class backThisClass = thisClass;
13039 if(regClass) thisClass = regClass;
13040 ProcessDeclaration(def.decl);
13041 thisClass = backThisClass;
13044 else if(def.type == defaultPropertiesClassDef && def.defProperties)
13046 MemberInit defProperty;
13048 // Add this to the context
13049 Symbol thisSymbol = Symbol
13051 string = CopyString("this");
13052 type = regClass ? MkClassType(regClass.fullName) : null;
13054 globalContext.symbols.Add((BTNode)thisSymbol);
13056 for(defProperty = def.defProperties->first; defProperty; defProperty = defProperty.next)
13058 thisClass = regClass;
13059 ProcessMemberInitData(defProperty, regClass, null, null, null, null);
13063 globalContext.symbols.Remove((BTNode)thisSymbol);
13064 FreeSymbol(thisSymbol);
13066 else if(def.type == propertyClassDef && def.propertyDef)
13068 PropertyDef prop = def.propertyDef;
13070 // Add this to the context
13072 Symbol thisSymbol = Symbol { string = CopyString("this"), type = MkClassType(regClass.fullName) };
13073 globalContext.symbols.Add(thisSymbol);
13076 thisClass = regClass;
13083 string = CopyString("this");
13084 type = MkClassType(regClass.fullName);
13086 prop.setStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13089 curExternal = prop.symbol ? prop.symbol.externalSet : null;
13090 ProcessStatement(prop.setStmt);
13098 string = CopyString("this");
13099 type = MkClassType(regClass.fullName);
13101 prop.getStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13104 curExternal = prop.symbol ? prop.symbol.externalGet : null;
13105 ProcessStatement(prop.getStmt);
13113 string = CopyString("this");
13114 type = MkClassType(regClass.fullName);
13116 prop.issetStmt.compound.context.symbols.Add((BTNode)thisSymbol);
13119 curExternal = prop.symbol ? prop.symbol.externalIsSet : null;
13120 ProcessStatement(prop.issetStmt);
13126 globalContext.symbols.Remove(thisSymbol);
13127 FreeSymbol(thisSymbol);
13130 else if(def.type == propertyWatchClassDef && def.propertyWatch)
13132 PropertyWatch propertyWatch = def.propertyWatch;
13134 thisClass = regClass;
13135 if(propertyWatch.compound)
13139 string = CopyString("this");
13140 type = regClass ? MkClassType(regClass.fullName) : null;
13143 propertyWatch.compound.compound.context.symbols.Add((BTNode)thisSymbol);
13145 curExternal = null;
13146 ProcessStatement(propertyWatch.compound);
13153 void DeclareFunctionUtil(const String s)
13155 GlobalFunction function = eSystem_FindFunction(privateModule, s);
13160 if(function.module.importType != staticImport && (!function.dataType || !function.dataType.dllExport))
13161 strcpy(name, "__ecereFunction_");
13162 FullClassNameCat(name, s, false); // Why is this using FullClassNameCat ?
13163 DeclareFunction(function, name);
13167 void ComputeDataTypes()
13171 External after = null;
13173 currentClass = null;
13175 containerClass = eSystem_FindClass(GetPrivateModule(), "Container");
13177 for(external = ast->first; external; external = external.next)
13179 if(external.type == declarationExternal)
13181 Declaration decl = external.declaration;
13184 OldList * decls = decl.declarators;
13187 InitDeclarator initDecl = decls->first;
13190 Declarator declarator = initDecl.declarator;
13191 if(declarator && declarator.type == identifierDeclarator)
13193 Identifier id = declarator.identifier;
13194 if(id && id.string)
13196 if(!strcmp(id.string, "uintptr_t") || !strcmp(id.string, "intptr_t") || !strcmp(id.string, "size_t") || !strcmp(id.string, "ssize_t"))
13198 external.symbol.id = -1001, external.symbol.idCode = -1001;
13210 // Workaround until we have proper toposort for declarations reordering
13211 External e = MkExternalDeclaration(MkDeclaration(MkListOne(MkStructOrUnion(structSpecifier, MkIdentifier("__ecereNameSpace__ecere__com__Instance"), null)), null));
13212 ast->Insert(after, e);
13216 temp.symbol = Symbol { id = -1000, idCode = -1000 };
13217 ast->Insert(after, temp);
13218 curExternal = temp;
13220 DeclareFunctionUtil("eSystem_New");
13221 DeclareFunctionUtil("eSystem_New0");
13222 DeclareFunctionUtil("eSystem_Renew");
13223 DeclareFunctionUtil("eSystem_Renew0");
13224 DeclareFunctionUtil("eSystem_Delete");
13225 DeclareFunctionUtil("eClass_GetProperty");
13226 DeclareFunctionUtil("eClass_SetProperty");
13227 DeclareFunctionUtil("eInstance_FireSelfWatchers");
13228 DeclareFunctionUtil("eInstance_SetMethod");
13229 DeclareFunctionUtil("eInstance_IncRef");
13230 DeclareFunctionUtil("eInstance_StopWatching");
13231 DeclareFunctionUtil("eInstance_Watch");
13232 DeclareFunctionUtil("eInstance_FireWatchers");
13234 DeclareStruct("ecere::com::Class", false);
13235 DeclareStruct("ecere::com::Instance", false);
13236 DeclareStruct("ecere::com::Property", false);
13237 DeclareStruct("ecere::com::DataMember", false);
13238 DeclareStruct("ecere::com::Method", false);
13239 DeclareStruct("ecere::com::SerialBuffer", false);
13240 DeclareStruct("ecere::com::ClassTemplateArgument", false);
13244 for(external = ast->first; external; external = external.next)
13246 afterExternal = curExternal = external;
13247 if(external.type == functionExternal)
13249 currentClass = external.function._class;
13250 ProcessFunction(external.function);
13252 // There shouldn't be any _class member access here anyways...
13253 else if(external.type == declarationExternal)
13255 currentClass = null;
13256 if(external.declaration)
13257 ProcessDeclaration(external.declaration);
13259 else if(external.type == classExternal)
13261 ClassDefinition _class = external._class;
13262 currentClass = external.symbol.registered;
13263 if(_class.definitions)
13265 ProcessClass(_class.definitions, _class.symbol);
13269 // Free class data...
13270 ast->Remove(external);
13274 else if(external.type == nameSpaceExternal)
13276 thisNameSpace = external.id.string;
13279 currentClass = null;
13280 thisNameSpace = null;
13281 curExternal = null;
13283 delete temp.symbol;